[DB-SIG] Preparing statement API

M.-A. Lemburg mal@lemburg.com
Wed, 26 Jan 2000 10:22:05 +0100


Hrvoje Niksic wrote:
> 
> "M.-A. Lemburg" <mal@lemburg.com> writes:
> 
> > >     statement = cur.prepare("INSERT INTO foo (user, name) VALUES (?, ?)")
> [...]
> > The problem with this approach is that you'd have to store the
> > perpared information somewhere.  This is usually done by the cursor
> > which is not under Python's control.
> 
> You'd store it (or a pointer to it) in the statement object, returned
> by cursor.prepare().  Given that prepare() is a cursor method, the
> cursor can be made aware of each such object.
> 
> > cursor.prepare(operation)
> >          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.
> >
> > cursor.command
> >          Provides access to the current prepared SQL command available
> >          through the cursor. This is set by .prepare(), all catalog
> >        methods, .execute() and .executemany().
> 
> This is very close to what I proposed, except that my cursor.prepare()
> returns the statement (which you provide through cursor.command).
> This allows one to prepare more than one statement using one cursor.

Maybe this is just an ODBC thing, but you cannot prepare more
than one statement on a cursor (in ODBC the notion of cursors
is captured by the HSTMT or statement handle). For ODBC, your
.prepare() function would have to return a new cursor.

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