在参数列表之后获取SyntaxError:missing)

时间:2016-08-13 08:54:34

标签: javascript sql sequelize.js

var records = "";
for(var i = 0; i < activity.length; i++) {
sequelize.query("SELECT * from users WHERE city = '"+city+"'" AND categories LIKE CONCAT('%', activity[i], '%')"", { type: sequelize.QueryTypes.SELECT})
    .then(function(logs){ 
        records += logs;
        matchCount += logs.length;

    }); 
}

console.log("--------------------------Priniting matched users-----------------------");
console.log(records);

//INSERT DATA TO SQL

sequelize.query("INSERT INTO users(name, lastname, email, phone, city, categories, createdAt, updatedAt) VALUES ('"+req.body.first_name+"', '"+req.body.last_name+"', '"+req.body.email+"',  '"+req.body.tel+"', '"+req.body.city+"', , '"+JSON.stringify(activity)+"', 'test', 'test')");

1 个答案:

答案 0 :(得分:0)

错误出现在具有奇怪引号的select语句中。

var records = "";
for (var i = 0; i < activity.length; i++) {
    sequelize.query("SELECT * from users WHERE city = '" + city + "'AND categories LIKE CONCAT('%', activity[i], '%')", {
            type: sequelize.QueryTypes.SELECT
        }).then(
        function(logs) {
            records += logs;
            matchCount += logs.length;
        });
}

console.log("--------------------------Priniting matched users-----------------------");
console.log(records);

//INSERT DATA TO SQL

sequelize.query("INSERT INTO users(name, lastname, email, phone, city, categories, createdAt, updatedAt) VALUES ('" + req.body.first_name + "', '" + req.body.last_name + "', '" + req.body.email + "', '" + req.body.tel + "', '" + req.body.city + "', , '" + JSON.stringify(activity) + "', 'test', 'test')");