Sqlite3. Substitution of names in query.

Lawrence D'Oliveiro ldo at geek-central.gen.new_zealand
Mon Nov 2 20:45:23 EST 2009


In message <mailman.2489.1257197791.2807.python-list at python.org>, Robert 
Kern wrote:

> On 2009-11-02 14:47 PM, Lawrence D'Oliveiro wrote:
>
>> For instance, I'm not aware of any database API that lets me do this:
>>
>>     sql.cursor.execute \
>>        (
>>              "update numbers set flags = flags | %(setflags)u where
>>              projectid = %(projectid)s" "%(match_listid)s and number =
>>              %(number)s"
>>          %
>>              {
>>                  "projectid" : SQLString(ProjectID),
>>                  "match_listid" :
>>                      ("", " and listid = %s" % SQLString(ListID))[ListID
>>                      != None],
>>                  "number" : SQLString(number),
>>                  "setflags" : flags,
>>              }
>>        )
> 
> When programmatically generating SQL, I like to use SQLAlchemy. This use
> case is handled with .where() on Update expression objects. Personally, I
> find manipulating the SQLAlchemy expression objects clearer, safer, and
> more portable than building the raw SQL through string interpolation.

Doesn't seem to support bulk insertions à la this 
<http://www.codecodex.com/wiki/Useful_MySQL_Routines#Bulk_Insertion>. Or 
even literal lists as per the SQLStringList routine on the same page.




More information about the Python-list mailing list