[DB-SIG] PEP 249

James Henstridge james at jamesh.id.au
Wed Jan 23 05:18:52 CET 2008


On 23/01/2008, Konjkov Vladimir <konjkov.vv at gmail.com> wrote:
> in definition of
> .execute(operation[,parameters])
> .....
> A reference to the operation will be retained by the
> cursor. If the same operation object is passed in again,
> then the cursor can optimize its behavior.

The operation object is the one passed as as the first argument to .execute().


> What meens "the same operation object is passed in again"?
> There's no definition for Class Operation.

It means that if you pass the same object to multiple execute() calls,
the database adapter may optimise things (then again, it might not).

The following is an example based on yours:

   query = "select * from table where a=? and b=?"
   C.execute(query, (1, 2))
   C.execute(query, (3, 4))

So if the adapter uses prepared statements, it can see that the second
execute() call uses the same query so uses the previously prepared
statement.

As an application developer, the thing to take away from this is that
if you are going to execute the same query over an over, consider
using the same string object.

James.


More information about the DB-SIG mailing list