DBI spec and parameter passing

M.-A. Lemburg mal at lemburg.com
Tue Jan 18 06:59:55 EST 2000


Thomas Wouters wrote:
> 
> On Mon, Jan 17, 2000 at 07:24:21PM -0500, Gordon McMillan wrote:
> > Skip wrote:
> > >               """ country = %s""", (city, state, country))
> 
> > but Skip _meant_:
> 
> > c.execute(""" select id from city where city = ? and state = ?
> > and country = ?""", (city, state, country))
> 
> Doesn't that depend on the DB-API module in question ? As I recall, it's
> module-dependant what kind of arguments it accepts, and you can query an
> attribute to find out the specifics of that module.

You probably mean the parameter marker: yes that is module
dependant. The '?' marker is used by all ODBC drivers and
managers and thus also by mxODBC :-)

Note that one should always use binding parameters if
possible: the driver or interface usually knows better how
to encode the data according to the DBs specs and it's
also much easier to write and more portable. Especially
column types such as date, time and BLOBs are represented
differently among databases.

-- 
Marc-Andre Lemburg
______________________________________________________________________
Business:                                      http://www.lemburg.com/
Python Pages:                           http://www.lemburg.com/python/





More information about the Python-list mailing list