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
asked Oct 2, 2013 at 17:38

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))
answered Oct 2, 2013 at 17:44
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.

answered Oct 2, 2013 at 17:45

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.