MySQLdb1 icon indicating copy to clipboard operation
MySQLdb1 copied to clipboard

"bad argument to internal function" with sql_mode="NO_BACKSLASH_ESCAPES" on 5.7 client

Open kennethreitz opened this issue 7 years ago • 1 comments

In 5.7.6+, mysql_real_escape_string() will error if the NO_BACKSLASH_ESCAPES SQL mode is enabled. Instead, mysql_real_escape_string_quote() must be used. See the note at https://dev.mysql.com/doc/refman/5.7/en/mysql-real-escape-string.html for more information:

To reproduce:

# python
Python 2.7.12 (default, Jul  1 2016, 15:12:24) 
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import _mysql
>>> m=_mysql.connect(...)
>>> m.escape_string("foobar")
'foobar'
>>> m.query("SET SESSION sql_mode='NO_BACKSLASH_ESCAPES'")
>>> m.escape_string("foobar")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
SystemError: ../Objects/stringobject.c:3903: bad argument to internal function

kennethreitz avatar Oct 24 '16 14:10 kennethreitz

Resolved upstream. https://github.com/PyMySQL/mysqlclient-python/issues/108

nicktimko avatar Nov 24 '16 15:11 nicktimko