[DB-SIG] bound parameters

Carl Karsten carl at personnelware.com
Tue Jan 2 22:32:20 CET 2007


I just read the thread in 
http://www.mail-archive.com/db-sig@python.org/msg00478.html

and am wondering what is currently 'best' for an application developer if we 
want our code to be portable across the various db modules?

Here is what I am currently doing:

import MySQLdb
con = MySQLdb.connect(...)
cur = con.cursor()
ret = cur.execute(
	"insert into logs (host, facility) values (%(host)s, %(facility)s)",
	{'host': 'foo3', 'facility': 'bar3'} )


I am also wondering what the best way is to specify object names:

print "#1", cur.execute("select count(*) as ncount from `logs`" )
print "#2", cur.execute("select count(*) as ncount from `%s`" %('logs') )

print "#3", cur.execute("select count(*) as ncount from %(table)s", 
{'table':'logs'} )  !

# errors because it gets quoted with single quote, not back quote.  bug?

Carl K




More information about the DB-SIG mailing list