Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python sqlite3 UPDATE set from variables

I made next Query to update a row in my DB.

def saveData(title, LL, LR, RL, RR, distanceBack):
    c.execute("UPDATE settings SET (?,?,?,?,?,?) WHERE name=?",(title, LL, LR, RL, RR, distanceBack, title))
    conn.commit()

I always get next error: sqlite3.OperationalError: near "(": syntax error I know something isn't correct with the question marks. I can't find out what the exact solution is. Can somebody explain me what the problem is?

like image 343
TMJ Avatar asked Nov 03 '25 18:11

TMJ


1 Answers

You could use this SQL syntax:

UPDATE table_name
SET column1 = value1, column2 = value2...., columnN = valueN
WHERE [condition];

for example, if you have a table called Category and you want to edit the category name you can use:

c.execute("UPDATE CATEGORY SET NAME=? WHERE ID=?", (name,category_id))

WHERE:

Category is a table that contains only two items: (ID, NAME) with ID PRIMARY KEY.

like image 106
melix Avatar answered Nov 05 '25 06:11

melix



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!