When I try to upload the PlayerScore
with the code
if Number.PlayerScore > Score.interact_database("SELECT Score FROM score WHERE Name = %s;" % Player_Name, False,)[0][0]
to the PostgreSQL Database in Python I get this error: psycopg2.ProgrammingError: column "your name" does not exist
, where 'your name' is the variable Player_Name. However, when I run it in the PostgreSQL Query Tool it works fine. Does anyone know why this errors pops up and how I can prevent it from happening again in the future?
http://initd.org/psycopg/docs/usage.html#the-problem-with-the-query-parameters
I think we'd need to see more of the code, but as per the docs:
Never, never, NEVER use Python string concatenation (+) or string parameters interpolation (%) to pass variables to a SQL query string. Not even at gunpoint.
Try passing the parameters as the second argument in your cursor.execute() method. Using something like:
cursor.execute("""SELECT Score FROM score WHERE Name = %(player)s""", {'player': player_name } )
cursor.fetchone()
Should work. It can also accept a tuple of values.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.