I have python 2.2 and MySQLdb. A sql update command generates errors of sql syntax. Please advise.
Here is a fragment of python code:
cursor.execute("""UPDATE items SET zip = '%s',title = '%s',item = '%s' WHERE itemid = %s""",(zip,title,text,item
id,))
Here are the error messages:
--> -->
ProgrammingError Python 2.2.3: /usr/bin/python
Fri Mar 18 18:42:24 2005
A problem occurred in a Python script. Here is the sequence of function calls leading up to the error, in the order they occurred.
/var/www/cgi-bin/donotneed
.py
694 values["main"]=editingitem
(cursor,ty
pe,itemid)
695 elif action =="update":
696 values["main"]=updateitem(
cursor,for
m)
697 else:
698 values["main"]=badpass(cur
sor)
values = {'debug': '', 'head': '', 'menu': ' <table cellspacing="0" cellpadding="5" width="... </td>\r\n </tr>\r\n </tbody>\r\n </table>\r\n', 'subhead': ''}, updateitem = <function updateitem>, cursor = <MySQLdb.cursors.Cursor instance>, form = FieldStorage(None, None, [MiniFieldStorage('zip'...
', 'update'), MiniFieldStorage('state', 'save')])
/var/www/cgi-bin/donotneed
.py in updateitem(cursor=<MySQLdb
.cursors.C
ursor instance>, form=FieldStorage(None, None, [MiniFieldStorage('zip'...
', 'update'), MiniFieldStorage('state', 'save')]))
398 if result is not None:
399 return "Only digits in zip"
400 cursor.execute("""UPDATE items SET zip = '%s',title = '%s',item = '%s' WHERE itemid = %s""",(zip,title,text,item
id,))
401 timestamp=DateTime.now()
402 cursor.execute("""INSERT timestamp(source, timestamp) VALUES(%s,%s)""",(ip,times
tamp))
cursor = <MySQLdb.cursors.Cursor instance>, cursor.execute = <bound method Cursor.execute of <MySQLdb.cursors.Cursor instance>>, zip = '98466', title = 'power brick for concord modem', text = '.8 amp, screw on power connector\r\n\r\nastar@spa
mcop.net',
itemid = '0'
/usr/lib/python2.2/site-pa
ckages/MyS
QLdb/curso
rs.py in execute(self=<MySQLdb.curs
ors.Cursor
instance>, query="UPDATE items SET zip = '%s',title = '%s',item = '%s' WHERE itemid = %s", args=('98466', 'power brick for concord modem', '.8 amp, screw on power connector\r\n\r\nastar@spa
mcop.net',
'0'))
64 else:
65 try:
66 r = self._query(query % self.__conn.literal(args))
67 except TypeError, m:
68 if m.args[0] in ("not enough arguments for format string",
r undefined, self = <MySQLdb.cursors.Cursor instance>, self._query = <bound method Cursor._query of <MySQLdb.cursors.Cursor instance>>, query = "UPDATE items SET zip = '%s',title = '%s',item = '%s' WHERE itemid = %s", self.__conn undefined, args = ('98466', 'power brick for concord modem', '.8 amp, screw on power connector\r\n\r\nastar@spa
mcop.net',
'0')
/usr/lib/python2.2/site-pa
ckages/MyS
QLdb/curso
rs.py in _query(self=<MySQLdb.curso
rs.Cursor instance>, q=r"UPDATE items SET zip = ''98466'',title = ''power...tor\r\n\r\nastar
@spamcop.n
et'' WHERE itemid = '0'")
166
167 def _query(self, q):
168 rowcount = self._BaseCursor__do_query
(q)
169 self._rows = self._result and self._fetch_row(0) or ()
170 self._pos = 0
rowcount undefined, self = <MySQLdb.cursors.Cursor instance>, self._BaseCursor__do_query
= <bound method Cursor.__do_query of <MySQLdb.cursors.Cursor instance>>, q = r"UPDATE items SET zip = ''98466'',title = ''power...tor\r\n\r\nastar
@spamcop.n
et'' WHERE itemid = '0'"
/usr/lib/python2.2/site-pa
ckages/MyS
QLdb/curso
rs.py in __do_query(self=<MySQLdb.c
ursors.Cur
sor instance>, q=r"UPDATE items SET zip = ''98466'',title = ''power...tor\r\n\r\nastar
@spamcop.n
et'' WHERE itemid = '0'")
110 from string import split, atoi
111 db = self._get_db()
112 db.query(q)
113 self._result = self._get_result()
114 self.rowcount = db.affected_rows()
db = <open connection to 'localhost' at 81b2ad0>, db.query = <built-in method query of connection object>, q = r"UPDATE items SET zip = ''98466'',title = ''power...tor\r\n\r\nastar
@spamcop.n
et'' WHERE itemid = '0'"
ProgrammingError: (1064, "You have an error in your SQL syntax near '98466'',title = ''power brick for concord modem'',item = ''.8 amp, screw on powe' at line 1")
__doc__ = 'Exception raised for programming errors, e.g. ta...t, wrong number\n of parameters specified, etc.'
__getitem__ = <bound method ProgrammingError.__getitem
__ of <_mysql_exceptions.Program
mingError instance>>
__init__ = <bound method ProgrammingError.__init__ of <_mysql_exceptions.Program
mingError instance>>
__module__ = '_mysql_exceptions'
__str__ = <bound method ProgrammingError.__str__ of <_mysql_exceptions.Program
mingError instance>>
args = (1064, "You have an error in your SQL syntax near '98466...modem'',item = ''.8 amp, screw on powe' at line 1")
Start Free Trial