Sqlite3. Substitution of names in query.

Lawrence D'Oliveiro ldo at geek-central.gen.new_zealand
Mon Nov 2 15:47:08 EST 2009


In message <mailman.2416.1257062070.2807.python-list at python.org>, Dennis Lee Bieber wrote:

> On Sun, 01 Nov 2009 19:08 +1300, Lawrence D'Oliveiro
> <ldo at geek-central.gen.new_zealand> declaimed the following in
> gmane.comp.python.general:
> 
>> On the grounds that Python has more general and powerful string
>> parameter- substitution mechanisms than anything built into any database
>> API.
> 
> Really? In the case of MySQLdb, the DB-API /uses/ Pythons string
> interpolation ...

Only a limited subset thereof. 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,
            }
      )




More information about the Python-list mailing list