[DB-SIG] Preparing statement API
Tue, 25 Jan 2000 21:17:08 +0100
Eric Brunson wrote:
> How does what Hrvoje is asking for differ from the Handle object in
> the DCOracle module?
> >From the DCOracle docs:
> prepare(sql) --
> Returns a new Handle Object. A handle is a pre-prepared
> notion of a cursor, where some handling of the SQL
> parsing has already been done.
> You use it like this:
> (Assume a DB connection called "dbc")
> inshndl = dbc.prepare( "insert into mytable ( attribute, value ) "
> "values ( :p1, :p2 )" )
> for attr, val in list:
> inshndl.execute( (attr, val) )
> :p1 and :p2 can also be named parameters, but as I use them in that
> example, they are simply positional.
With mxODBC this would look something like this:
cursor = dbc.cursor()
cursor.prepare("insert into mytable (attribute, value ) values (?,?)")
for attr, val in list:
cursor.execute(cursor.command, (attr, val))
Not all that different and without the need to invent new
APIs or objects... seriously, all these gimmicks can be done
using abstraction layers on top of the existing DB API interface.
Python Pages: http://www.lemburg.com/python/