Advertisement

03.18.2005 at 03:50PM PST, ID: 21356742
[x]
Attachment Details

SQL update

Asked by astar666 in Python Scripting Language

Tags: update, sql, python

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,itemid,))

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,type,itemid)
  695         elif action =="update":
  696                 values["main"]=updateitem(cursor,form)
  697         else:
  698                 values["main"]=badpass(cursor)
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.Cursor 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,itemid,))
  401         timestamp=DateTime.now()
  402         cursor.execute("""INSERT timestamp(source, timestamp) VALUES(%s,%s)""",(ip,timestamp))
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@spamcop.net', itemid = '0'

 /usr/lib/python2.2/site-packages/MySQLdb/cursors.py in execute(self=<MySQLdb.cursors.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@spamcop.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@spamcop.net', '0')

 /usr/lib/python2.2/site-packages/MySQLdb/cursors.py in _query(self=<MySQLdb.cursors.Cursor instance>, q=r"UPDATE items SET zip = ''98466'',title = ''power...tor\r\n\r\nastar@spamcop.net'' 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.net'' WHERE itemid = '0'"

 /usr/lib/python2.2/site-packages/MySQLdb/cursors.py in __do_query(self=<MySQLdb.cursors.Cursor instance>, q=r"UPDATE items SET zip = ''98466'',title = ''power...tor\r\n\r\nastar@spamcop.net'' 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.net'' 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.ProgrammingError instance>>
      __init__ = <bound method ProgrammingError.__init__ of <_mysql_exceptions.ProgrammingError instance>>
      __module__ = '_mysql_exceptions'
      __str__ = <bound method ProgrammingError.__str__ of <_mysql_exceptions.ProgrammingError 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
[+][-]03.19.2005 at 09:40AM PST, ID: 13582649

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.19.2005 at 11:58AM PST, ID: 13583103

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.19.2005 at 03:52PM PST, ID: 13583951

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.28.2005 at 10:07PM PST, ID: 13649923

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Python Scripting Language
Tags: update, sql, python
Sign Up Now!
Solution Provided By: mish33
Participating Experts: 2
Solution Grade: A
 
 
 
Loading Advertisement...
20080716-EE-VQP-32