node.js - Complex SQL query with nodes-mysql -
i have problem running following sql query mysql database nodejs , node-mysql packe added npm.
insert locations (locationid,name,latitude,longitude) select '214777725','bryans road, maryland','38.628055556','-77.081666667' dual not exists (select * locations locationid = '214777725')
i've tried following code:
var arrvalues = [ -12.9747, -38.4767, 213287181, 'salvador, brazil' ]; var arrnames = [ 'latitude', 'longitude', 'locationid', 'name' ]; var locationid = "214777725"; if(imagedata["locationid"] != null) { var query = "insert locations ? "; query = query + " select (?)"; query = query + " dual not exists"; query = query + " (select * locations locationid = ?)"; console.log(query); connection.query(query, [arrnames,arrvalues,locationid], function(err,res) { if(err) { console.log(err); } else { console.log("insert-success: " +id); } }); }
running console writes following error:
{ code: 'er_parse_error', errno: 1064, sqlstate: '42000', index: 0 }
i hope can help.
it looks need use .tostring(); function on arrays.
connection.query(query, [arrnames.tostring(),arrvalues.tostring(),locationid], function(err,res) { ...
Comments
Post a Comment