tags:

views:

181

answers:

1

Hi I want to insert all escape characters in a column in MySQL. I can not insert \ always because a long data may have a lot escape characters.

Thanks Sunil Kumar Sahoo

A: 

I am not sure if I am getting this correct but you

  • have a lot of data
  • you want to insert them into database with regular SQL commands
  • most of data requires escaping.

So you have no much options. Since there is no direct binary mode in MySQL you

  • either execute SQL script with escaping
  • you will write parametrized queries and insert data directly with some custom tool you will write.

If choosing first approach have a look at MySQL manual for some escaping string details. Particularly you may escape one backslash \ with double backslashes \\ sequence. Also have a look at NO_BACKSLASH_ESCAPES, which eliminates need for escaping completly.

Michal Sznajder
NO_BACKSLASH_ESCAPES doesn't eliminate the need for escaping, it only makes MySQL compliant with the ANSI SQL string literal syntax, where `"` is the only character to need escaping, and it is escaped by doubling to `""`.
bobince