views:

179

answers:

2

from this post http://stackoverflow.com/questions/2130641/sqlite-python-insert I learned inserting into tables but now I need to use where something like

cursor.execute("insert into table1(id) values (?) where ip=? and address=?",(id,),(ip,),(addr,));

+2  A: 

INSERT does not have a WHERE clause. I think you mean UPDATE.

amphetamachine
oops extremely sorry for this funny question :) lol ..yes ...it's update I'll try update statement
lakshmipathi
yes ..its working now :)
lakshmipathi
Oh, and I forgot to mention: good job on using the auto-escaping OO query framework. Most people don't figure that out, and end up accidentally allowing SQL injection attacks.
amphetamachine
A: 

You can't use a WHERE clause in an INSERT. If you want to specify the values for particular fields to insert, put them in the values clause:

cursor.execute("INSERT INTO table1(id, ip, address) VALUES (?, ?, ?)", (id, ip, addr))
Max Shawabkeh
thanks max.yes it's update statement
lakshmipathi