Prepared statements

12 views
Skip to first unread message

Timothy Madden

unread,
Oct 30, 2009, 6:24:23 AM10/30/09
to pyodbc
The DB API says a cursors should retain the last prepared statement
and if that is subsequently used again the cursor can optimise
behaviour. Is this implemented in pyodbc ?

Is there any use for me to implement a pool of connection/cursor pairs
in my application (one for each thread) to avoid preparing the same
statement many times ?

Could a line about this please be added in the wiki or on the FAQ ?

Thank you,
Timothy Madden

mkleehammer

unread,
Oct 30, 2009, 11:35:26 AM10/30/09
to pyodbc
On Oct 30, 5:24 am, Timothy Madden <terminato...@gmail.com> wrote:
> The DB API says a cursors should retain the last prepared statement
> and if that is subsequently used again the cursor can optimise
> behaviour. Is this implemented in pyodbc ?

This is implemented in pyodbc.

> Is there any use for me to implement a pool of connection/cursor pairs
> in my application (one for each thread) to avoid preparing the same
> statement many times ?

SInce only the last statement is kept, you might see a benefit if you
are switching between them a lot.

If you are concerned about performance, also consider not inserting
parameters with None for NULL. When binding a NULL parameter, pyodbc
has to ask the database for the column type being written into, which
is an extra API call. (These are also cached for the last statement,
so I wouldn't worry about it for executing the same statement over and
over.)

> Could a line about this please be added in the wiki or on the FAQ ?

That is a great idea. Let me see if I can find the right places to do
that.
Reply all
Reply to author
Forward
0 new messages