sami
sami

Reputation: 199

can a mysql select query in C language return a field with the special characters escaped?

1- string = a'b"c\d

2- escaped_string = a\'b\"c\\d

3- make an insert query that inserts escaped_string in some table field.

4- make a select query that returns the inserted value.

The returned value is: a'b"c\d

Is there a way to get the select query to return a\'b\"c\\d ? (I understand that i can escape it again).

Upvotes: 1

Views: 46

Answers (1)

Ctx
Ctx

Reputation: 18420

You can use the QUOTE() function of mysql:

mysql> select data from x;
+---------+
| data    |
+---------+
| a'b"c\d |
+---------+
1 row in set (0.00 sec)


mysql> select quote(data) from x;
+-------------+
| quote(data) |
+-------------+
| 'a\'b"c\\d' |
+-------------+
1 row in set (0.00 sec)

This should exactly do what you are looking for. Note that the " doesn't need to be escaped here, so QUOTE() doesn't escape it, too.

Upvotes: 1

Related Questions