jeudi 5 mars 2015

Python SQLite best way to use variables in query

Why do i get this error?



sqlite3.OperationalError: near "?": syntax error


when i run this:



c.execute('UPDATE ? SET Quantity = Quantity + ? WHERE Date = ?', (table, amount, date))


But not when i run this?



c.execute('UPDATE table1 SET Quantity = Quantity + ? WHERE Date = ?', (amount, date))


Variable value is:



table = 'table1'
amount = 20
Date = '12/5/2014'


I'm trying to dynamically create tables, but just doesn't work out.


Aucun commentaire:

Enregistrer un commentaire