lundi 14 septembre 2015

Issue reading columns in sqlite with python

I am attempting to create a function that I can call with a column name and have it return the contents of the column from a table (tablename is in the code).

I am past the point of errors but cannot get it to return the values in the column, instead it returns a list filled with the column name that is as long as the fields in the column.

> **def retrieve_data_game(column):
>      with sqlite3.connect("gamereview.db") as db:
>         cursor = db.cursor()
>         cursor.execute ("select ? from game",[column])
>         output= cursor.fetchall()
>         db.commit()
>         return output**

calling this with:

**> if __name__ == "__main__":
>         a="gameID"
>         gameID = retrieve_data_game(a)
>         print(gameID)**

this print statement will return:

[('gameID',), ('gameID',), ('gameID',), ('gameID',)]

any help would be greatly appreciated kind regards

Aucun commentaire:

Enregistrer un commentaire