Unable to run select statement

97 views
Skip to first unread message

necavi

unread,
Jan 13, 2012, 1:03:36 AM1/13/12
to PyMySQL Users
This is my first time using PyMySQL, and unfortunately whenever I try
to use the tuple argument for cursor.execute I always get:
File "C:\Development\Language installs\Python\lib\pymysql
\cursors.py", line 105, in execute
query = query % escaped_args
TypeError: not all arguments converted during string formatting
but when using the exact same values directly in the query (as a test)
it executes flawlessly.

Any ideas on how I can prevent this?

Pete Hunt

unread,
Jan 13, 2012, 3:42:20 AM1/13/12
to pymysq...@googlegroups.com
Can you send your execute() line?

necavi

unread,
Jan 13, 2012, 3:44:48 AM1/13/12
to PyMySQL Users
cur.execute("SELECT
`user_name`,`user_class`,`user_password`,`user_email` FROM
`irpg_users` WHERE `user_ID` = ?",(1,))
is an example (it also happens with INSERT statements and such)
cur.execute("SELECT
`user_name`,`user_class`,`user_password`,`user_email` FROM
`irpg_users` WHERE `user_ID` = 1")
executes flawlessly.

Pete Hunt

unread,
Jan 13, 2012, 4:23:02 AM1/13/12
to pymysq...@googlegroups.com
PyMySQL uses format-style to be compatible with MySQLdb, rather than
qmark-style like sqlite3.

Try changing ? to %s.

necavi

unread,
Jan 13, 2012, 4:24:14 AM1/13/12
to PyMySQL Users
Ahhh, many thanks! I'm not familiar with MySQLdb, so I didn't think to
try that.
Reply all
Reply to author
Forward
0 new messages