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

0

1 Answer 1

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)
Sign up to request clarification or add additional context in comments.

2 Comments

Any idea how to replace the table name as well?
@IsaacWP121 - the placeholder concept of the SQL API is not relevant to the table name. You will have to do it your self. Did (ID,) work for you?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.