0

feel free to comment and tell me if the title needs changing, anyway, I've been trying to query my "User_Messages" Table and get any messages related to an id. This is the line of code im using:

c.execute("SELECT * FROM User_Messages WHERE ID = $1", (ID)) (id is an integer eg. 190332830289)

it keeps giving out this error when I run it from terminal

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: parameters are of unsupported type

however when ran from a .py file it returns None and fails to give out an error. Any ideas how I should solve this?

On an related note can I also use a placeholder for the table name? something like this: SELECT * FROM %1 WHERE ID = %2 so that I can pass in multiple table names?

Any help would be greatly appreciated. Tia

IsaacWP121
  • 111
  • 1
  • 10

1 Answers1

0

You should pass a tuple --> (ID,)

See https://docs.python.org/3/library/sqlite3.html

and an example:

t = ('RHAT',)
c.execute('SELECT * FROM stocks WHERE symbol=?', t)
balderman
  • 22,927
  • 7
  • 34
  • 52