MySQLdb1
MySQLdb1 copied to clipboard
"bad argument to internal function" with sql_mode="NO_BACKSLASH_ESCAPES" on 5.7 client
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
Resolved upstream. https://github.com/PyMySQL/mysqlclient-python/issues/108