0

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

5
  • What are the strange characters > and * in the code? Likely you should edit the post and remove them. Indent the code with 4 leading spaces to separate it from the rest of the question. Commented Sep 15, 2015 at 1:39
  • thanks, that was my first time posting so I tried a bunch of stuff Commented Sep 15, 2015 at 2:06
  • in the line cursor.execute ("select ? from game",[column]), why put column into the brackets? Commented Sep 15, 2015 at 2:52
  • @wangke1020 execute expects an array and indexes the string if you don't pass in an array/tuple Commented Sep 15, 2015 at 2:53
  • stackoverflow.com/a/13881118/2884547 seems to imply that ? notation isn't acceptable for identifier locations. That doesn't explain what the given substitution is actually doing, but it might help you move forward... Commented Sep 15, 2015 at 3:11

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.