0

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.

RasmusGP
  • 3,656
  • 5
  • 20
  • 27

1 Answers1

1

You can't use placeholders for table names. You have to use normal Python string formatting or concatenation.

Daniel Roseman
  • 567,968
  • 59
  • 825
  • 842