[DB-SIG] API suggestion: expose 'quote' method

Greg Ewing greg at cosc.canterbury.ac.nz
Fri Jun 6 13:23:10 EDT 2003

> Point conceded: if one can only do that with full-formed SQL 
> statements, then any utility of being able to 'piecemeal' the SQL 
> together using strings is defeated.

Although it should be feasible to piece together pieces
of SQL and their associated parameter values separately
in Python before handing them to the DB module, maybe
using something like

   class SQLWithParams:

     def __init__(self, sql, params):
       self.sql = sql
       self.params = params

     def __add__(self, other):
       if isinstance(other, SQLWithParams):
         # SQLWithParams + SQLWithParams
         return SQLWithParams(
           self.sql + other.sql, 
           self.params + other.params)
         # SQLWithParams + string
         return SQLWithParams(
           self.sql + sql, 

     def __radd__(self, other):
       # string + SQLWithParams
       return SQLWithParams(other + self.sql, self.params)

Greg Ewing, Computer Science Dept, +--------------------------------------+
University of Canterbury,	   | A citizen of NewZealandCorp, a	  |
Christchurch, New Zealand	   | wholly-owned subsidiary of USA Inc.  |
greg at cosc.canterbury.ac.nz	   +--------------------------------------+

More information about the DB-SIG mailing list