[DB-SIG] query - prepared statment

M.-A. Lemburg mal at egenix.com
Fri Feb 10 23:15:36 CET 2006

Carsten Haese wrote:
> On Fri, 2006-02-10 at 04:07, python eager wrote:
>> Hi All,
>>   How to use prepared statment. Can u give one example  for insert, 
>> delete and update statments. please.
> The DB-API standard does not define a separate method for preparing a
> statement. Preparing the statement is part of the cursor.execute() and
> executemany() methods. execute() prepares the statement and executes it
> with the given parameters. executemany() should prepare the statement
> once and execute it many times over, once for each set of parameters.
> For DB-API implementations that implement statement caching (informixdb
> and cx_Oracle, for example), the first execute call takes the place of
> preparing a statement. If you subsequently execute the same query string
> on the same cursor with different parameters, the same prepared
> statement is reused.
> Apparently cx_Oracle implements a non-standard prepare() method that
> prepares a query string for later execution by either passing the same
> string or None to execute().

Perhaps we should something like this to the list of standard
DB-API extensions ?!

This is what we have in mxODBC 2.1:


   Prepare a database operation (query or command) statement for later
   execution and set cursor.command. To execute a prepared statement,
   pass cursor.statement to one of the .executeXXX() methods. Return
   values are not defined.


   Provides access to the last prepared or executed SQL command
   available through the cursor. If no such command is available, None
   is returned.

Looks very similar to what cx_Oracle implements.

Marc-Andre Lemburg

Professional Python Services directly from the Source  (#1, Feb 10 2006)
>>> Python/Zope Consulting and Support ...        http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ...             http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ...        http://python.egenix.com/

::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! ::::

More information about the DB-SIG mailing list