If I do a:
curs.execute('SELECT * FROM my_table WHERE id = %s', 5)
Everything works fine. However, if I anticipate that id
will always be an integer, and I do:
curs.execute('SELECT * FROM my_table WHERE id = %d', 5)
(Notice the '%d' intead of '%s'), then I get a TypeError:
File "foo.py", line 15, in ?
curs.execute('SELECT * FROM my_table WHERE id = %d', 1)
File
"/home/matt/com/are/dev/trunk/site/app/MySQLdb/cursors.py",
line 95, in execute
return self._execute(query, args)
File
"/home/matt/com/are/dev/trunk/site/app/MySQLdb/cursors.py",
line 110, in _execute
self.errorhandler(self, TypeError, m)
File
"/home/matt/com/are/dev/trunk/site/app/MySQLdb/connections.py",
line 33, in defaulterrorhandler
raise errorclass, errorvalue
TypeError: int argument required
The same thing happens when using "pyformat"-style
arguments as well (e.g., '%(id)d').
Logged In: YES
user_id=71372
Only use %s. The conversion functions turn whatever your
value is into a properly quoted string.