MySQLdb oddity

Dave Cole djc at object-craft.com.au
Tue Sep 5 20:29:07 EDT 2000


>>>>> "Ken" == Ken Power <ilaryn at my-deja.com> writes:

Ken> Obviosuly I am doing something wrong. I thought dictionaries
Ken> could be used to populate a SQL query. Note the following:

Ken> Python 1.5.2 (#0, Apr  3 2000, 14:46:48)  [GCC 2.95.2 20000313 (Debian
Ken> GNU/Linux)] on linux2
Ken> Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
Ken> >>> import MySQLdb
Ken> >>> mine = MySQLdb.Connect(db='special_shipments')
Ken> >>> curs = mine.cursor()
Ken> >>> test = {"date_sf_entered": 20000809, "approved_by": "Ken"}
Ken> >>> curs.execute("INSERT INTO sales_summary (date_sf_entered,
Ken> approved_by) VALUES (%(date_sf_entered), %(approved_by));" % test)

Try doing this  (put an 's' after the %())

curs.execute("INSERT INTO sales_summary (date_sf_entered, approved_by) VALUES (%(date_sf_entered)s, %(approved_by)s);" % test)

- Dave



More information about the Python-list mailing list