node-mariasql icon indicating copy to clipboard operation
node-mariasql copied to clipboard

queries with timestamp values fail when using multistatements

Open devzer01 opened this issue 9 years ago • 1 comments

have found an issue with the way the library currently handles prepared statements.

'use strict';
var Client = require('mariasql');

var c = new Client();

c.connect({
  host: "localhost",
  user: "root",
  password: "foo",
  db: "foobar",
  multiStatements: true
});

c.query("UPDATE a SET s = :s, d = DATE_FORMAT(DATE_ADD(CURDATE(),INTERVAL 60 DAY), '%Y-%m-%d 23:59:59') WHERE id = :id; CALL sp (:id, null, null, null);", {"s":"A", "id": 123}, function(err, rows) {
  if (err)
    throw err;
  console.dir(rows);
}); 

c.close();

you will notice the prepared statement is incorrectly parsed. the value of :id is added to the end of the string, causing the query to fail.

also was there any reason that you decided to prepare the query in javascript instead of using mysql_prepare? The prepare function appears that there could be edge cases where it fails.

anyways i manage to solve this problem by moving '%Y-%m-%d 23:59:59' to a named placeholder so this can be a workaround for now.

devzer01 avatar Feb 10 '16 06:02 devzer01

The reason the async prepared statements API is not used is because it's a real pain in the ass to work with (there's a lot of layers and associated state split among a dozen or so different functions that need to be dealt with, it's not just a single function call) and is why I never got anywhere with it. If you or anyone else wants to take a swing at it, I am definitely open to a PR to add it in. Once we have something like that, I will gladly get rid of the emulated prepared statements functionality.

mscdex avatar Feb 10 '16 06:02 mscdex