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.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Parameter named undefined is not set

Xaymar opened this issue · comments

I've been running into the error mentioned in the title with any query, prepared or not, that uses ? placeholders. I could not find any resources that explain what this error means, and the errno also did not match anything on the MariaDB error page. For sanity reasons I created a table that matches the example here:

CREATE TABLE `test`.`mytable`  (
  `id` bigint UNSIGNED NOT NULL AUTO_INCREMENT,
  `someVal` int NULL,
  `otherVal` varchar(255) NULL,
  PRIMARY KEY (`id`)
);

And even the example results in this error. How can I fix this? It does not happen with the MySQL connectors, or other languages (tested in PHP and C++, worked fine).

you probably set option namedPlaceholders. In that case, queries must be like this :

const res = await conn.execute('SELECT * FROM mytable WHERE someVal = :someVal and otherVal = :otherVal', 
	{ someVal: 1, otherVal: 'val1' }
);

in place of:

const res = await conn.execute('SELECT * FROM mytable WHERE someVal = ? and otherVal = ?', [1, 'val1']);

still, in this case, error message must be improved.

Thanks for the help, this actually helped me track down a bug in my own configuration file parser, which incorrectly set known-but-not-used keys to new Object(null) instead of undefined.

Just as an FYI, the wording on this page isn't clear about the use of named placeholders, as it doesn't say you can't use ? anymore.