MySQLdb oddity
Ken_Power
ilaryn at my-deja.com
Tue Sep 5 18:11:32 EDT 2000
Obviosuly I am doing something wrong. I thought dictionaries could be
used to populate a SQL query. Note the following:
Python 1.5.2 (#0, Apr 3 2000, 14:46:48) [GCC 2.95.2 20000313 (Debian
GNU/Linux)] on linux2
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> import MySQLdb
>>> mine = MySQLdb.Connect(db='special_shipments')
>>> curs = mine.cursor()
>>> test = {"date_sf_entered": 20000809, "approved_by": "Ken"}
>>> curs.execute("INSERT INTO sales_summary (date_sf_entered,
approved_by) VALUES (%(date_sf_entered), %(approved_by));" % test)
Traceback (innermost last):
File "<stdin>", line 1, in ?
ValueError: unsupported format character ',' (0x2c)
>>> curs.execute("INSERT INTO sales_summary (date_sf_entered,
approved_by) VALUES (%(date_sf_entered)s, %(approved_by)s);" % test)
Traceback (innermost last):
File "<stdin>", line 1, in ?
File "/usr/lib/python1.5/site-packages/MySQLdb.py", line 194, in
execute
return self._query(query)
File "/usr/lib/python1.5/site-packages/MySQLdb.py", line 283, in
_query
rowcount = self._BaseCursor__do_query(q)
File "/usr/lib/python1.5/site-packages/MySQLdb.py", line 238, in
__do_query
db.query(q)
_mysql.OperationalError: (1054, "Unknown column 'Ken' in 'field list'")
What am I missing?
Sent via Deja.com http://www.deja.com/
Before you buy.
More information about the Python-list
mailing list