Advertisement
Guest User

Untitled

a guest
Jan 18th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. def interact_database(command):
  2. connection = psycopg2.connect("dbname=NAME user=NAME password=PASSWORD")
  3. cursor = connection.cursor()
  4.  
  5. cursor.execute(command)
  6. connection.commit()
  7.  
  8. results = None
  9. try:
  10. results = cursor.fetchall()
  11. except psycopg2.ProgrammingError:
  12. print("Connection failure.")
  13. pass
  14.  
  15. cursor.close()
  16. connection.close()
  17.  
  18. return results
  19.  
  20.  
  21. def pick_question(type):
  22. if type == 'G':
  23. QuestionID = random.randint(1,38)
  24. elif type == 'Gr':
  25. QuestionID = random.randint(39,60)
  26. elif type == 'R':
  27. QuestionID = random.randint(61,89)
  28. else:
  29. QuestionID = random.randint(90,119)
  30. interact_database("SELECT Question FROM Questions WHERE Question_ID = %s")(QuestionID)
  31.  
  32. pick_question('G')
  33.  
  34. psycopg2.ProgrammingError: syntax error at or near "%"
  35. LINE 1: SELECT Question FROM Questions WHERE Question_ID = %s
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement