0

I have a simple piece of code to update a row in sqlite:

def UpdateElement(new_user,new_topic):
    querycurs.execute('''INSERT into First_Data (topic) values(?) WHERE user = (?)''',([new_topic],    [new_user]))

However, this gives me the error:

Traceback (most recent call last):
  File "C:/Python27/Database.py", line 40, in <module>
    UpdateElement("Abhishek Mitra","Particle Physics")
  File "C:/Python27/Database.py", line 36, in UpdateElement
    querycurs.execute('''INSERT into First_Data (topic) values(?) WHERE user = (?)''',([new_topic],[new_user]))
OperationalError: near "WHERE": syntax error

2 Answers 2

3

You should be using an UPDATE statement instead of INSERT:

def UpdateElement(new_user,new_topic):
    querycurs.execute('''UPDATE First_Data 
                         SET topic = ? 
                         WHERE user = ?''', (new_topic, new_user))
Sign up to request clarification or add additional context in comments.

Comments

0

The problem arises from the use of the parentheses and sending in new_user as an array, I believe. Values is an array, user is not.

You want something like:

cur.execute("UPDATE table SET value=? WHERE name=?", (myvalue, myname))

But yes, UPDATE sounds like what you wanted in the first place.

Comments

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.