[DB-SIG] Preparing statement API

Hrvoje Niksic hniksic@iskon.hr
26 Jan 2000 09:10:27 +0100

"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.