Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在sails.js中使用SQL IN运算符复制查询_Sails.js_Waterline_Sails Postgresql - Fatal编程技术网

如何在sails.js中使用SQL IN运算符复制查询

如何在sails.js中使用SQL IN运算符复制查询,sails.js,waterline,sails-postgresql,Sails.js,Waterline,Sails Postgresql,我正在连接到PostgreSQL并在控制器中使用以下方法,但当它应该返回一些值时,它似乎找不到任何东西: Machine.query('Select * from Machine where Machine.demo_id in (' + ids_demo + ') and Machine.serial_number in (' + serials + ')', [] , function(err, machine) { if(machine === undefined) return

我正在连接到PostgreSQL并在控制器中使用以下方法,但当它应该返回一些值时,它似乎找不到任何东西:

Machine.query('Select * from Machine where Machine.demo_id in (' + ids_demo + ') and Machine.serial_number in (' + serials + ')', [] , function(err, machine) {
    if(machine === undefined) return res.notFound();
    if (err) return next(err);
    res.json(machine);
});
ids\u demo和serials是值的数组。例如:ids_demo=[1,2,3,4,5,8]

有更好的方法吗?
谢谢

查询格式不正确
var query='Select*from Machine where Machine.demo_id in('+ids_demo+')和Machine.serial_number in('+serials+')
console.log(query)
。如果从请求中获取
ids_demo
序列
的输入,则这是SQL注入的开放方式。@Sanghras。您可以指定吗?关于SQL注入否,它是直接来自后端的东西,所以我猜不太可能有SQL注入。无论如何,我不确定如何避免SQL注入,还有其他方法吗?使用此包创建查询,然后将其传递给
Machine.query