If I want to insert a variable value in sqlite3 with python you code the following statement. For example:
import sqlite3
import random
conn = sqlite3.connect('testing.db')
c = conn.cursor()
c.execute("CREATE TABLE IF NOT EXISTS testing(Name TEXT, Telephone TEXT, ID REAL)")
var1 = input("Value:")
var2 = input("Value:")
var3 = random.randint(1,20)
c.execute("INSERT INTO testing VALUES(?, ?, ?)", (var1, var2, var3))
conn.commit()
conn.close()
What if I want to do the same with the UPDATE statement. I tried this and is giving me error:
column = input("Column to update:")
update_user = input("Value to update:")
field_name = input("Where field name equal to:")
value = input("Value")
c.execute("UPDATE testing SET ? = ? WHERE ? = ?", (column, update_user, field_name, value))
conn.commit()
And this is the error that I get:
sqlite3.OperationalError: near "?": syntax error