Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

node-mysql query attempts to replace my question marks with parameters against my will

I'm trying to run a simple query with node-mysql like this:

client.query("UPDATE mytable SET emote='wtf?' WHERE id=5");

And I get the error

Error: too few parameters given

Because it found a question mark and expects parameters. How the heck do I tell it to ignore the question mark!? Escaping it with \ doesn't work. Passing ['?'] as a parameter is completely out of the question - what if I don't know the amount of question marks the query contains?

Currently I'm using a workaround that counts the amount of question marks in the query and passes that amount of question marks as parameters. But what if I were to actually need the parameters for what they were meant to do? I shiver at the thought.

So to summarize - How do I tell client.query() to ignore question marks?

like image 396
Hubro Avatar asked Sep 06 '25 09:09

Hubro


1 Answers

Use this:

client.query('UPDATE mytable SET emote=? WHERE id=5', ['wtf?']);

Edit:

Passing ['?'] as a parameter is completely out of the question - what if I don't know the amount of question marks the query contains?

I skipped over this. Why would you not know how many question marks the query contains? Why would you have an unknown query with question marks?

like image 200
Felix Geisendörfer Avatar answered Sep 08 '25 16:09

Felix Geisendörfer