I'm currently working on code to analyze trading cards, which I'm storing in an SQLite database. One of the functions which queries the database for specific cards is listed below:
def colors_search(conn,deck_color,card_ID):
"""
Query all rows in the colors table
:param conn: the Connection object
:return:
"""
color = (deck_color,)
test = (color,card_ID)
sql = ''' SELECT Number
FROM Colors
WHERE Color=?
AND Card_ID=?'''
cur = conn.cursor()
cur.execute(sql,test)
number = cur.fetchall()
return number
When I try and run this function, I keep getting the following error:
sqlite3.InterfaceError: Error binding parameter 0 - probably unsupported type.
This is referring to the line
cur.execute(sql,test)
I feel that the error is coming from how I'm trying to query two variables, but I'm not sure. If this is the problem, how would I format the 'sql' variable to take in two parameters? The deck_color and card_ID variables are a string and integer, respectively, and will vary throughout my program, so I can't hard code either of those in.
Alternately, if this isn't the issue, how can I reformat this to run correctly? Thanks!
testwhich you need to print. I suspectcoloris a tuple from a previous querycolor = (deck_color,). It serves no purpose. That's why the query fails and making it a tuple doesn't, to my knowledge, do anything other than cause this error. Your query already protects against SQL injection.