0

I want to update a table with the following query. I am getting multiple errors on the following. What is the correct syntax for writing the query below

 cursor.execute("""UPDATE `%s` SET `content`=%s WHERE link=%s""", (feed,cnews,news_url))

The error I get when running the above is

Traceback (most recent call last):
  File "digger_1.py", line 34, in <module>
    cursor.execute("""UPDATE `%s` SET `content`=%s WHERE link=%s""", (feed,cnews,news_url))
  File "/usr/lib/python2.7/dist-packages/MySQLdb/cursors.py", line 174, in execute
    self.errorhandler(self, exc, value)
  File "/usr/lib/python2.7/dist-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler
    raise errorclass, errorvalue
_mysql_exceptions.ProgrammingError: (1146, "Table 'newstracker.'NDTV'' doesn't exist")

The error I picked was the table newstracker.NDTV doesn't exist, which is not right as it does exist, and I believe the error is something else which is wrong with the syntax.

2
  • What does feed contain? Commented Oct 21, 2013 at 15:25
  • Yes, but what is it's value, exactly? What does print repr(feed) show? Commented Oct 21, 2013 at 15:35

1 Answer 1

2

You cannot specify metadata such as database, table, or field names using a parametrized query. You must substitute them using normal string formatting and then use the result string as your parametrized query.

...("""UPDATE `%s` SET `content`=%%s WHERE link=%%s""" % (feed,), ...)
Sign up to request clarification or add additional context in comments.

7 Comments

Anywhere that parametrized queries are explained, including thousands of similar SO questions.
Changed the query to cursor.execute("""UPDATE %s SET content=%%s WHERE link=%%s""" %(feed,),cnews,news_url) The error is ---> TypeError: execute() takes at most 3 arguments (4 given)
Erm, you still need the values to replace to be in a single sequence.
Can you help me with how that syntax would be
Exactly how you had it before, except with a different string and different elements in the sequence.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.