在MySQL查询中禁用转义字符

时间:2022-10-16 22:25:24

Is there a way to disable escape characters in a MySQL query? For example, for the following table:

有没有办法在MySQL查询中禁用转义字符?例如,对于下表:

mysql> select * from test1;+------------------------+-------+| name                   | value |+------------------------+-------+| C:\\media\data\temp\   |     1 || C:\\media\data\temp    |     2 || /unix/media/data/temp  |     3 || /unix/media/data/temp/ |     4 |+------------------------+-------+

I want the following to be a valid query:

我希望以下是一个有效的查询:

mysql> select * from test1 where name='C:\\media\data\temp\';

I know that I can instead use

我知道我可以改用

mysql> select * from test1 where name='C:\\\\media\\data\\temp\\';

But I am building this query using my_snprintf(), so there instead I have to use

但我正在使用my_snprintf()构建此查询,所以我必须使用

C:\\\\\\\\media\\\\data\\\\temp\\\\

...and so on!Is there a way to disable escape characters for a single MySQL query ?

...等等!有没有办法为单个MySQL查询禁用转义字符?

2 个解决方案

#1


9  

You can disable backslash escapes by setting NO_BACKSLASH_ESCAPES in the SQL mode:

您可以通过在SQL模式下设置NO_BACKSLASH_ESCAPES来禁用反斜杠转义:

-- save mode & disable backslashesSET @old_sql_mode=@@sql_mode;SET @@sql_mode=CONCAT_WS(',', @@sql_mode, 'NO_BACKSLASH_ESCAPES');-- run the querySELECT 'C:\\media\data\temp\';-- enable backslashesSET @@sql_mode=@old_sql_mode;

#2


1  

For tabular output in MySQL command line, the “boxing” around columns enables one column value to be distinguished from another. For non-tabular output (such as is produced in batch mode or when the --batch or --silent option is given), special characters are escaped in the output so they can be identified easily. Newline, tab, NUL, and backslash are written as \n, \t, \0, and \. The --raw option disables this character escaping.

对于MySQL命令行中的表格输出,围绕列的“装箱”使得一个列值可以与另一个列区分开来。对于非表格输出(例如以批处理模式或在给出--batch或--silent选项时生成),特殊字符将在输出中转义,以便可以轻松识别它们。换行符,制表符,NUL和反斜杠写为\ n,\ t,\ 0和\。 --raw选项禁用此字符转义。

#1


9  

You can disable backslash escapes by setting NO_BACKSLASH_ESCAPES in the SQL mode:

您可以通过在SQL模式下设置NO_BACKSLASH_ESCAPES来禁用反斜杠转义:

-- save mode & disable backslashesSET @old_sql_mode=@@sql_mode;SET @@sql_mode=CONCAT_WS(',', @@sql_mode, 'NO_BACKSLASH_ESCAPES');-- run the querySELECT 'C:\\media\data\temp\';-- enable backslashesSET @@sql_mode=@old_sql_mode;

#2


1  

For tabular output in MySQL command line, the “boxing” around columns enables one column value to be distinguished from another. For non-tabular output (such as is produced in batch mode or when the --batch or --silent option is given), special characters are escaped in the output so they can be identified easily. Newline, tab, NUL, and backslash are written as \n, \t, \0, and \. The --raw option disables this character escaping.

对于MySQL命令行中的表格输出,围绕列的“装箱”使得一个列值可以与另一个列区分开来。对于非表格输出(例如以批处理模式或在给出--batch或--silent选项时生成),特殊字符将在输出中转义,以便可以轻松识别它们。换行符,制表符,NUL和反斜杠写为\ n,\ t,\ 0和\。 --raw选项禁用此字符转义。