Skip to content

Not able to escape JSON.stringify string containing single quotes (') #2323

@varun2410

Description

@varun2410

While Inserting into the table from DBeaver the query is running fine, but when i am trying to the run the same query from the mysqljs, its throwing the syntax error.

Query
INSERT INTO CHECK1 (testField) VALUES ('{"keywords":["1/4 pounder\'s"]}')

JS Code
mysql.query('INSERT INTO CHECK1 (testField) VALUES (?)', [JSON.stringify(data.params)]);

From what i am able to figure out is the its not able to escape the single quotes ('), and that is what is throwing the error.

Error Thrown
UnhandledPromiseRejectionWarning: Error: ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 's\"]}' at line 1

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions