Question Jaime Alvarez · Mar 13, 2018

How to escape double quotes on a SQL Update via ODBC

Hi all,

I am new in Cache. I have to update a record with a long text field, for that,  I am using ODBC but the issue is that it is returning an error when I execute the ODBC  SQL statement because the field contains some commas, colon, double quotes, single quotes, and CR LF characters.

There is a way to escape this chars? I have seen I can save the field when I replace the single quotes with a double single quote (it's -> it''s) but I can not save the information when the field contains double quote chars. What about the other chars?

The statement is something like:

SET description = '240-page + cover perfect bound book. Insides on 29" 22.1 ",  productName = ' "AAA244 - Sometext, sometext.  "  '  WHERE id=25

Any Ideas? Than you in advance.

Comments

Eduard Lebedyuk · Mar 13, 2018

Use parameters instead of building the query manually. Everything would be escaped automatically.

0
Jaime Alvarez  Mar 13, 2018 to Eduard Lebedyuk

Thank you for your prompt response.  But ... do you have an example?

0
Jaime Alvarez  Mar 13, 2018 to Eduard Lebedyuk

It worked! Thank you so much!

0
Jaime Alvarez  Mar 13, 2018 to Jon Willeke

Sorry, It was an example. The single quotes in the program are good. Thanks!

0
Jon Willeke · Mar 13, 2018

The statement in your post is not well formed. The value for the description field starts with a single quote, contains a couple of double quotes, but is not terminated with a single quote.

0