[DB-SIG] .prepare()

Bill Tutt billtut@microsoft.com
Tue, 16 May 2000 02:25:07 -0700


> From: Greg Stein [mailto:gstein@lyra.org]
> > > example implmentation:
> > > 
> > > # Dictionary mapping query text -> opqaue prepared query 
> reference (sproc
> > > name, underlying db access
> > > # mechanism or something entirely different)
> > > preparedQuery = {}
> > > 
> > > def execute(self, cmd):
> > >         if not preparedQuery.has_key(cmd):
> > >                 preparedQuery[cmd] = conn.prepare(cmd)
> > >         else:
> > >                 conn.execute(preparedQuery[cmd])
> > 
> > Don't know about other databases, but ODBC can only prepare
> > one statement on one cursor. Once you prepare another statement
> > on the cursor, the previous one is lost, so making the currently
> > prepared command available via an attribute looked like the
> > right way for mxODBC.
> 
> Other databases have the same restriction. Bill brain-farted 
> on this one.
> :-)
> 

The above was more of psuedo-code than anything specific that has any chance
of working. It was merly to illustrate the concept.

Some databases may impose some sort of restriction upon what ODBC thinks of
as prepared queries, yes.
However, consider: A stored procedure is a prepared and preparsed query.
Hrm....

So to fill in the details of the above a little more:

preparedQuery = {}

def execute(self, ...):
	if not preparedQuery.has_key(cmd):
		preparedQuery[cmd] = createStoredProcedure(conn, cmd)
	conn.execute("exec %s" % preparedQuery[cmd])

Bill