mariadb-corporation / mariadb-connector-nodejs

MariaDB Connector/Node.js is used to connect applications developed on Node.js to MariaDB and MySQL databases. MariaDB Connector/Node.js is LGPL licensed.
GNU Lesser General Public License v2.1
368 stars 91 forks source link

Providing `null` as a value to a query causes an error #167

Closed Jiralite closed 3 years ago

Jiralite commented 3 years ago

Problem

Hiya, I migrated from another package to this one (this looks great by the way) and found some peculiar behaviour. My query is like this:

<Pool>.query("UPDATE `table` SET `column` = ?;", null);

This would set the column to null. However, it doesn't work and I receive this:

{
  text: "You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '?' at line 1",
  sql: 'UPDATE `table` SET `column` = ?; - parameters:[]',
  fatal: false,
  errno: 1064,
  sqlState: '42000',
  code: 'ER_PARSE_ERROR'
}

The documentation states that values is an array or an object but in the case of one placeholder, it can be given as is. In this case, I gave it as is, and it failed.

It seems to only happen with null. I assume this is a bug but a low priority one? This is fixed if I simply provide an array with null in it. Alas, here is my issue, please enlighten me if this is a bug or not!

Versions

rusher commented 3 years ago

This is clearly a bug. null must here be considered as a value. I've created https://jira.mariadb.org/browse/CONJS-173 for that

Jiralite commented 3 years ago

Thank you for confirming & triaging the issue!

rusher commented 3 years ago

corrected with https://github.com/mariadb-corporation/mariadb-connector-nodejs/commit/016ef46a672346d50a4018fea260ba7144f0ade9. Will be available in 2.5.5 and 3.0.1-RC