I have a MariaDB database that has a filed TagName with value ~!@#$%^&*()_+|}{":?><./';[]\=-`
I had set mode SET @@SQL_MODE = CONCAT(@@SQL_MODE, ',NO_BACKSLASH_ESCAPES');
When I try to created DB in MySQL 8.0.13, this query work well and return 1 row
select * from taginfo1 where TagName = '~!@#$%^&*()_+|}{":?><./'';[]\\=-`';
But in 10.3.9-MariaDB, the query
select * from taginfo1 where TagName = '~!@#$%^&*()_+|}{":?><./'';[]\\=-`';
can not return any result.
Is this an MariaDB issue or I missed some configuration?
Best Answer
According to the documentation about sql_mode NO_BACKSLASH_ESCAPES:
Your string has a double backslash in it. In the NO_BACKSLASH_ESCAPES sql_mode this will be interpreted as a double backslash whereas in the default sql_mode it's interpreted as a single backslash.
Below are some tests with MariaDB 10.3.13 using the following table:
Default sql_mode
Note that one backslash has disappeared.
sql_mode with NO_BACKSLASH_ESCAPES
Let's remove one backslash from the
WHERE
clause:Then let's insert a second row while we're in NO_BACKSLASH_ESCAPES mode:
As far as I can tell, this all works as per the documentation. If you really get different results in 10.3.9, then presumably there was a bug that's been fixed.