A
A
Alexander2018-07-08 14:57:29
Python
Alexander, 2018-07-08 14:57:29

How to pass the name of the table through a character?

Hello, there is such a function:

def check_user_bd(user_id, table):
    cursor.execute('SELECT * FROM (?) WHERE user_id=(?)', (table, str(user_id)))
    if not cursor.fetchall():
        return False
    else:
        return True

Python swears at ? after FROM
sqlite3.OperationalError: near "?": syntax error
How can I pass the table name?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Denis Melnikov, 2018-07-08
@Mi11er

c.execute("UPDATE data SET pass = ? WHERE name = ?", (password, login))
Just ?, without () try

A
Alexander Proshchenkov, 2018-07-08
@Keltor

cursor.execute("SELECT * FROM '{}' WHERE user_id='{}' ".format(table, str(user_id)))

Use format method and {} inside string

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question