Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parameter named undefined is not set #238

Closed
Xaymar opened this issue Mar 27, 2023 · 2 comments
Closed

Parameter named undefined is not set #238

Xaymar opened this issue Mar 27, 2023 · 2 comments

Comments

@Xaymar
Copy link

Xaymar commented Mar 27, 2023

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).

@rusher
Copy link
Collaborator

rusher commented Mar 27, 2023

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.

rusher added a commit that referenced this issue Mar 27, 2023
…ion and executing standard question mark command #238
@Xaymar
Copy link
Author

Xaymar commented Mar 28, 2023

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.

@Xaymar Xaymar closed this as completed Mar 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants