Skip to content

Instantly share code, notes, and snippets.

@lexdene
Last active December 16, 2015 14:39
Show Gist options
  • Save lexdene/5450648 to your computer and use it in GitHub Desktop.
Save lexdene/5450648 to your computer and use it in GitHub Desktop.
I think this is a bug in MySQLdb .
import MySQLdb
conn = MySQLdb.connect(user='xxx',passwd='xxx',db = 'xxx')
cursor = conn.cursor()
n = cursor.execute(
'select * from xxx where `content` in %(content)s',
{ 'content': ('aa','bb','cc') }
)
print cursor._last_executed
# I hope it print:
# select * from xxx where `content` in ('aa', 'bb', 'cc')
# but actually it print:
# select * from xxx where `content` in ("'aa'", "'bb'", "'cc'")
# and because of this , the query fetch nothing
# Is this a bug of MySQLdb ?
# my system:
# Ubuntu 12.04.2 LTS
# Python 2.7.3
# MySQLdb 1.2.3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment