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
  • 4,696
  • 5
  • 21
  • 28

1 Answers1

1

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

Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895