q = """SELECT * FROM foo WHERE a IN %s""" tup = (11,2) c.execute(q, (tup,))
This, of course, works great. The tuple "tup" is
escaped correctly for the IN clause. However, if you
change tup to a single item list:
tup = (11,)
The query will fail with invalid syntax:
Traceback (most recent call last):
File "/home/kylev/tmp/foo.py", line 12, in ?
line 137, in execute
self.errorhandler(self, exc, value)
line 33, in defaulterrorhandler
raise errorclass, errorvalue
_mysql_exceptions.ProgrammingError: (1064, "You have an
error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right
syntax to use near ')' at line 1")
It looks like a single-item array/tuple is converted to
a single value, instead of a parenthesized list with
one member. I.e., the above is converted to "'11'"
instead of "('11')". I think the latter is more
correct and wouldn't cause this error.
Log in to post a comment.