a question about mysqldb

Fredrik Lundh fredrik at pythonware.com
Thu Aug 14 17:41:13 CEST 2008

Evan wrote:

> a simple problem but I do not know why...:(, could anyone help me?
> MySQLdb nominally uses just the %s placeholder style, in my script, i
> got error if you want to use placeholder(%s) for table name:

Placeholders are supposed to be used for *values*, not other parts of 
the SQL statement.  To insert table names, column names and stuff like 
that, use Python-level formatting.

try doing:

    table = "tmp"
    sql = "select tID,tNote from " + table + " where tID=%s"
    param = [1]
    s.dbptr.execute(sql, param)

 > But sql worked but the I got no query result:
 > ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 > >>> >>> str="select tID,tNote from tmp where %s = %s"
 > >>> >>> e=["tID",int(1)]

the string value "tID" doesn't match an integer with the value 1, so 
that's expected.


More information about the Python-list mailing list