0

I have to following piece of code:

temp = item.get() #returns a string
c.execute("INSERT OR IGNORE INTO {tn} ({cn}, {dn}, {en}) VALUES (?, 23, 10)".\
format(tn=table_name, cn=field2, dn = field3, en = field4), (temp))

However, the code causes an error:

File "First_GUI.py", line 47, in func_confirm
format(tn=table_name, cn=field2, dn = field3, en = field4), (temp))
sqlite3.ProgrammingError: Incorrect number of bindings supplied. The current 
statement uses 1, and there are 0 supplied.

Do you have any idea how I can fix the syntax?

Bahlsen
  • 177
  • 1
  • 9
  • It's not the formatting. You'll get the exact same error with the object names as literals in the string. It's the `(temp)`; that's *not a tuple*. Use `(temp,)`. – Martijn Pieters Oct 15 '18 at 18:49
  • I do not really understand your answer. Why is then this possible? temp1 = 'Shell'; temp2 = 100; temp3 = 200; c.execute("INSERT OR IGNORE INTO financial_table (Item, Date, Price) VALUES (?, ?, ?)", (temp1, temp2, temp3)) The latter ones are no tuples either. – Bahlsen Oct 15 '18 at 19:18
  • See the duplicate. `(temp)` is the same thing as `temp`. It is the comma that makes it a tuple. – Martijn Pieters Oct 15 '18 at 20:02

0 Answers0