Is there a way to disable escape characters in a MySQL query? For example, for the following table:
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
C:\\\\\\\\media\\\\data\\\\temp\\\\
...and so on! Is there a way to disable escape characters for a single MySQL query ?
You can remove special characters from a database field using REPLACE() function. The special characters are double quotes (“ “), Number sign (#), dollar sign($), percent (%) etc.
An escape sequence is a set of characters used in string literals that have a special meaning, such as a new line, a new page, or a tab. For example, the escape sequence \n represents a new line character. To ignore an escape sequence in your search, prepend a backslash character to the escape sequence.
Remove characters from string using TRIM() TRIM() function is used to remove any character/ whitespace from the start/ end or both from a string.
SELECT REGEXP_REPLACE(columnName, '[^\\x20-\\x7E]', '') from tableName; Count to do a safety check ... Then update This update is a catch all after the mapping update. Change the limit number to the count value above ...
You can disable backslash escapes by setting NO_BACKSLASH_ESCAPES in the SQL mode:
-- save mode & disable backslashes
SET @old_sql_mode=@@sql_mode;
SET @@sql_mode=CONCAT_WS(',', @@sql_mode, 'NO_BACKSLASH_ESCAPES');
-- run the query
SELECT 'C:\\media\data\temp\';
-- enable backslashes
SET @@sql_mode=@old_sql_mode;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With