DBI spec and parameter passing

Gordon McMillan gmcm at hypernet.com
Tue Jan 18 11:39:31 EST 2000


Skip wrote:
> 
>     >> Instead of doing the parameter interpolation yourself, try letting
>     >> your database module do it for you, e.g.:
>     >> 
>     >> c = db.cursor()
>     >> c.execute("""select id from city where"""
>     >> """ city = %s and"""
>     >> """ state = %s and"""
>     >> """ country = %s""", (city, state, country))
> 
>     Gordon> but Skip _meant_:
> 
>     Gordon> c.execute(""" select id from city where city = ? and state = ?
>     Gordon> and country = ?""", (city, state, country))
> 
> I suppose so, in the correct context.  Not being an ODBC person I didn't
> know what was required in the context of the original question, so all I
> could do was cut/paste from my MySQLdb code, which wants the %s thingies...

Sorry. DBI is flexible about this, but the only dynamic 
parameter marker mentioned in the SQL 92 (aka SQL II) spec 
is "?". Or to put it another way, since ODBC is part of SQL II, 
the ODBC way *is* the standard way ;-).

- Gordon




More information about the Python-list mailing list