0

I created a table and added records to it but I want to print each record as I add more records.But the code below doesn't seem to be working for me.. Btw I input model from user..

Cursor.execute("SELECT * FROM Top_Cars WHERE MODEL=?;",(model))
print(Cursor.fetchone())
schwifty
  • 145
  • 1
  • 12

1 Answers1

0

It is a common mistake with tuples. (model,) is a 1-tuple, but (model) is just a parenthesed expression containing only model. As a string is an iterable of characters, execute sees as many bindings as letters in model word. Fix it trivial:

Cursor.execute("SELECT * FROM Top_Cars WHERE MODEL=?;",(model,))

or:

Cursor.execute("SELECT * FROM Top_Cars WHERE MODEL=?;",[model])
Serge Ballesta
  • 143,923
  • 11
  • 122
  • 252
  • BTW: I did not see that immediately in you question, but it became evident after you gave the error message. The reason why you should **always** show the exact error messages. – Serge Ballesta Jul 05 '19 at 08:35
  • you are right , this completely got off of my mind...Thanks a bunch. – schwifty Jul 05 '19 at 08:38