我试图创建一个允许我使用Node和SQLite3搜索和排序列表的函数。我不太确定我做错了什么,但当我包含sort参数时,代码停止工作,我得到&#34;错误:SQLITE_ERROR:接近&#34;?&#34;:语法错误&#34;。< / p>
这是代码。
exports.search = function(name, sort, sortAscDesc, cb) {
var sqlQuery = "SELECT * FROM Crimestat";
if (name != undefined) {
name = "%" + name + "%";
sqlQuery += " WHERE municipacility LIKE ?";
}
if (sort != undefined) {
if (sortAscDesc != undefined) {
sqlQuery += " ORDER BY ? ?";
} else {
sqlQuery += " ORDER BY ASC";
}
}
console.log("sql query " + sqlQuery)
db.all(sqlQuery, name, sort, sortAscDesc, function(err, row) {
if (row == undefined) {
console.log("error " + err)
cb(false);
} else {
cb(row);
}
});
提前谢谢