Hi,
I am trying to execute query like:
set @result:=0;
update mytable
set status = case
when status != 'ended' then if(@result:=1,'ended', status)
else status end
where id = 49;
select @result;
I have to use the raw query here, but seems that I cannon call
db.driver.execQuery with the above query?
I received syntax error.
Now i am just using something like:
db.driver.execQuery('set @result:=0; ', function(err) {
if (err) {
return cb(err);
}
db.driver.execQuery('update mytable \
set status = case \
when status != \'ended\' then if(@result:=1,\'ended\', status) \
else status end \
where id = ' + id, function(err) {
if (err) {
callback(err, null);
} else {
db.driver.execQuery('select @result;', function(err, result) {
callback(null, result);
});
}
});
});
You could try setting the multipleStatements options in the connection string.
See here: https://github.com/felixge/node-mysql
Another option is use a library like async and execute in series.
Hi, I am trying to execute query like: set @result:=0;
update mytable
set status = case
when status != 'ended' then if(@result:=1,'ended', status)
else status end
where id = 49;
select @result;
I have to use the raw query here, but seems that I cannon call db.driver.execQuery with the above query? I received syntax error.
Now i am just using something like: db.driver.execQuery('set @result:=0; ', function(err) { if (err) { return cb(err); }
but its pretty ugly..
any help appreciated!