考虑到以下因素:
let sql: any = 'SELECT * FROM test_people ORDER BY :column :direction LIMIT :limit, :offset';
let binds: any = { column: 'name', direction: 'desc', limit: '1', offset: '10' };
let result = await mysql.query(sql, binds);
无论出于什么原因,它抛出mysql语法错误,如果我替换绑定并将其硬编码而不使用绑定,那么查询实际上会工作并获取结果。不知道这里出了什么问题。救命啊!:)
顺便说一句,我也试过用问号版本,得到同样的语法错误。
错误输出:
...
code: 'ER_PARSE_ERROR',
errno: 1064,
'You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near \':column :direction LIMIT :limit, :offset\' at line 1',
...