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.

3
  • 1
    What's the value of amount variable? Commented Mar 6, 2015 at 7:22
  • 1
    Related stackoverflow.com/questions/1274432/…. You cannot parameterize a table name. Commented Mar 6, 2015 at 7:22
  • Oh the quantity was the amount Commented Mar 6, 2015 at 7:36

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

2 Comments

So something like this? (Table = 'table1' c.execute('UPDATE '+Table+' SET Quantity = Quantity + ? WHERE Date = ?', (amount, date)))
Yes, or using the %s or {} string formatting operators.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.