Answer the question
In order to leave comments, you need to log in
SQL queries in JS code, escape special characters or not?
Good afternoon!
I automate the testing process with Node.js and Selenium-wd.
Before and after test blocks, queries to the database are performed (creating preconditions or clearing the database).
Requests are stored in variables in string form.
There is a problem with single quotes.
Let me explain with an example:
needForReg = 'INSERT INTO `billing_payment_gateway` (--\
`id`, `name`, `route`, `description`, `is_active`, `is_deleted`--\
) VALUES (--\
1, 'interkassa', 'InterkassaGateway', '', 1, 0);'
needForReg = 'INSERT INTO `billing_payment_gateway` (--\
`id`, `name`, `route`, `description`, `is_active`, `is_deleted`--\
) VALUES (--\
1, \'interkassa\', \'InterkassaGateway\', \'\', 1, 0);'
needForReg = "INSERT INTO `billing_payment_gateway` (--\
`id`, `name`, `route`, `description`, `is_active`, `is_deleted`--\
) VALUES (--\
1, 'interkassa', 'InterkassaGateway', '', 1, 0);"
Answer the question
In order to leave comments, you need to log in
Double quotes differ from single quotes only in the absence of newlines (you cannot escape a newline).
It is quite possible to put queries into separate files with the .sql extension - this is how the IDE will highlight the syntax;
you can read files into memory when the application starts in synchronous mode, and so that there are not many files, you can implement a parser in order to keep several queries in one file
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question