vendredi 22 mai 2015

Python/sqlite: query database by table name from user input

In Python 3 I'm trying to do a simple query on a sqlite table, where the user inputs the table name. However I can't manage to add the input variable to the query. Part of the code goes like this:

choice = input ("Enter table name ")
    c.execute("SELECT * FROM ?", choice)
    print(c.fetchall())

Errormsg. is:

sqlite3.OperationalError: near "?": syntax error

I've tried different variations, without luck. Anyone know if there is good solution?

Thanks, -Espen

Aucun commentaire:

Enregistrer un commentaire