Obtener error de sintaxis sql en nodejs
Estoy usando este código:
async function getNotificationFsql(data) { var query = "select * from notifications where id>${data.start} and receiver=${data.recId} limit 10"; var record = await db.sequelize.query(query , function (err,results) { if (err) { console.log('Error while getting data from MYSQL :- ' + err); } else { console.log('Notifications data which we got from MYSQL :- ' + results); } } ); // console.log(record); console.log('Notifications :- ' + record[0]); return record[0]; };
Y obtuve:
código: 'ER_PARSE_ERROR', errno: 1064, sqlState: '42000',
sqlMessage: "Tiene un error en su sintaxis SQL; consulte el manual que corresponde a la versión de su servidor MySQL para conocer la sintaxis correcta para usar cerca de '{data.start} and receiver=${data.recId} limit 10' at line 1 ",
sql: 'seleccione * de notificaciones donde id>${data.start} y receptor=${data.recId} límite 10', parámetros: undefined }, sql: 'seleccione * de notificaciones donde id>${data.start} y receptor=${data.recId} límite 10', parámetros: indefinido
¿Qué estoy haciendo mal?
lo siento, estoy haciendo esto mal
Resuelvo este error haciendo esto:
var query = "select * from notifications where id>"+data.start+" and receiver="+data.recId+" limit 10";