Bug #369 | USE_MB should not be used when escape/unescape string | ||
---|---|---|---|
Submitted: | 5 May 2003 2:31 | Modified: | 29 May 2003 2:40 |
Reporter: | xuefer tinys | Email Updates: | |
Status: | Won't fix | Impact on me: | |
Category: | MySQL Server | Severity: | S1 (Critical) |
Version: | mysql4.0.12 | OS: | not realative |
Assigned to: | Alexander Barkov | CPU Architecture: | Any |
[5 May 2003 2:31]
xuefer tinys
[5 May 2003 2:42]
xuefer tinys
note that the above script run on mysql server with GBK charset php script, run under both win32(binary package php) and linux(source package php, with source package of mysql which enabled GBK support with the server) it was several months ago i found this problem. problem still until i found this bug report system now. and i guess isn't so much servers currently running in GBK charset and it may not be a serious BC breaker, just recompile clients with new server protocol will be ok this problem should exists in other charset that make use of USE_MB hope this fix soon
[29 May 2003 2:40]
Michael Widenius
The escaping must be done differently for different charactersets because for some multi-byte character sets \ or ' may be part of a multi-byte character and should not be escaped. The function mysql_real_escape_string() takes care of escaping the string properly according to the current character set and is the recommended way to escape a string. In MySQL 4.1 we will provide a better mysql_real_escape_string() that should be able to handle all character sets. Other ways to solve this problem in 4.1 are: - You can prefix a string with _N"" to tell the server that it's using latin1, in which case the addslashes() should work correctly. - You can specify the character set used for the strings in your SQL statement. (SET CHARACTER SET) - We plan to provide a sql mode where \ doesn't have to be escaped in strings (Good for compatibility purposes) - You can use prepared statements to insert strings (in which case you don't have to quote anything) For 4.0 the only solution for people using a MB character set is to the quoting multi-byte safe either with mysql_real_escape_string() or with an own function.
[29 May 2003 3:32]
xuefer tinys
i don't see any point that make escaping have to care about charset unless one escape string by hand, he can not see the \ and " in multi-byte char but is there anywhere already discussed this problem? and info about the new SQL mode? thx