0

I am using Node.JS along with the mysql2 module. It's basically like when I try to update a column with a JSON stingified data, I get the following error:

{ Error: 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 '"1050":1}WHERE
 `user` = ?' at line 1

The stingified JSON data:

{"1050":1}

The query:

var sql = 'UPDATE `users` SET `furniture` = ' + 'concat(furniture,' + JSON.stringify(self.furniture) + ')' + 'WHERE `user` = ?';

self.furniture is related to something else, but I can assure you that self.furniture is returning that JSON data thus I get the mysql syntax error.

sqlMessage: '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 \'"1050":

2 Answers 2

1

Issue is resolved using backticks along with single quotes.

    var sql = 'UPDATE `users` SET `furniture` = ' + `concat(furniture, '${lol}')` + 'WHERE `user` = ?';

    var lol = JSON.stringify(self.furniture)
Sign up to request clarification or add additional context in comments.

Comments

0

Your query line says in part

 ...ingify(self.furniture) + ')' + 'WHERE `us...

It should have an extra space after the close parenthesis.

...ingify(self.furniture) + ') ' + 'WHERE `us...

Here's the thing about MySQL syntax errors: the message shows the erroneous query starting with the first character MySQL does not understand. A good way to troubleshoot this kind of thing is to use console.log() to output the entire query string, then look at it carefully. You will usually find something obvious wrong.

2 Comments

The better thing to do, if possible, would be to use statements.
Not really related to the issue, I can't figure out what is wrong with my queries. I tried it, it still spills out the same error.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.