DBAPI Paramstyle

Tim Roberts timr at probo.com
Sat Mar 26 09:54:09 CET 2005


Bob Parnes <rparnes at megalink.net> wrote:
>
>I have a mediocre talent at programming, which is why I chose python.
>For me it was a good choice. I note this so that I hope you understand why
>I say that I don't know what you are driving at. My understanding is that a 
>paramstyle is more efficient than the traditional python approach for repeated 
>use of a query. If so, then I do not see how the choice of a parameter is
>relevant. If it is more efficient only in a specific abstract case, then
>one would have to look for other reasons to use it in a practical application.

In theory, using a paramstyle allows the query to be sent to the SQL
database backend and compiled like a program.  Then, successive uses of the
same query can be done by sending just the parameters, instead of sending
the entire query string to be parsed and compiled again and again.  This is
commonly done with large production databases like SQL Server and Oracle.
For a complicated query, it can be a significant time savings.

However, to the best of my knowledge, none of the Python dbabi
implementations actually do that.  So, the primary benefit of the
paramstyle method is that the database provider inserts whatever quoting is
required; you don't have to remember to put single quotes around the
arguments, and protect single quotes within the arguments by doubling them,
and so on.
-- 
- Tim Roberts, timr at probo.com
  Providenza & Boekelheide, Inc.



More information about the Python-list mailing list