DB-API execute params, am I missing something?

Diez B. Roggisch deets at nospam.web.de
Tue May 26 08:46:39 EDT 2009


Gabriel Rossetti wrote:

> Hello everyone, I am trying to use dbapi with mysql and I get this error:
> 
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
>   File "<stdin>", line 2, in getUnitParams
>   File "/var/lib/python-support/python2.5/MySQLdb/cursors.py", line 151,
> in execute
>     query = query % db.literal(args)
> TypeError: int argument required
> 
> with this code :
> 
> import MySQLdb
> 
> def getParams(curs):
>     curs.execute("select * from param where id=%d", 1001)
>     return curs.fetchall()
> 
> cp = MySQLdb.connect(host="localhost",
>                      port=3306,
>                      user="root",
>                      passwd="123",
>                      db="test")
> 
> curs = cp.cursor()
> result = getParams(curs)
> 
> I checked MySQLdb.paramstyle and it uses "format". I also tried passing
> (1001,) instead of just 1001 as the param but this changes nothing. What
> am I doing wrong?

AFAIK you need to use %s, regardless of what type you pass.

Diez



More information about the Python-list mailing list