1

I am trying to update the data in a row of MySQL which this line of code is throwing this error.

for k in range(city_count):
    cur.execute("UPDATE hqstock SET citylastprice = '%s' WHERE id = '%s'"%(CITYPRICE[k],   tID[k]))

The error that was returned:

File "C:\Python27\lib\site-packages\MySQLdb\cursors.py", line 201, in execute
    self.errorhandler(self, exc, value)
File "C:\Python27\lib\site-packages\MySQLdb\connections.py", line 36, in defaulterrorhandler
    raise errorclass, errorvalue
InterfaceError: (0, '')

This is my table structure.

+--------------------+------------------+------+-----+---------+-------+
| Field              | Type             | Null | Key | Default | Extra |
+--------------------+------------------+------+-----+---------+-------+
| id                 |int(11) unsigned  | NO   | PRI | NULL    |       |
| barcode            | char(15)         | YES  |     | NULL    |       |
| citycurstock       | smallint(6)      | YES  |     | NULL    |       |
| citylastprice      | demical(4,2)     | YES  |     | NULL    |       |
| city               | varchar(60)      | YES  |     | NULL    |       |
+--------------------+------------------+------+-----+---------+-------+

Anybody knows what is wrong with my query statement? or why doesn't this work?

2
  • possible duplicate of mysqldb interfaceError and InterfaceError (0, '') Commented Oct 25, 2013 at 16:53
  • 3
    Note: don't use string interpolation; use SQL parameters instead: cur.execute("UPDATE hqstock SET citylastprice = %s WHERE id = %s", (CITYPRICE[k], tID[k])); this leaves quoting to the database adapter (safer and more convenient). Commented Oct 25, 2013 at 16:54

1 Answer 1

1

try this :

for k in range(city_count):
    cur.execute("UPDATE hqstock SET citylastprice = '%s' WHERE id = '%s'"% (CITYPRICE[k],   tID[k]))
    cur.commit()
Sign up to request clarification or add additional context in comments.

1 Comment

works like a charm. This helps the second problem i encountered. thank you

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.