Advertisement
Guest User

Untitled

a guest
May 23rd, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. ('mokaiaaa',)
  2. INSERT INTO drinks ('navn') VALUES ('mokaiaaa')
  3. Traceback (most recent call last):
  4. File "C:UsersRasmusworkspaceEksamensrcDatabaseConnector.py", line 60, in <module>
  5. d.Insert("drinks", "mokaiaaa")
  6. File "C:UsersRasmusworkspaceEksamensrcDatabaseConnector.py", line 17, in Insert
  7. cursor.execute(query)
  8. File "C:Anaconda3libsite-packagesmysqlconnectorcursor.py", line 515, in execute
  9. self._handle_result(self._connection.cmd_query(stmt))
  10. File "C:Anaconda3libsite-packagesmysqlconnectorconnection.py", line 488, in cmd_query
  11. result = self._handle_result(self._send_cmd(ServerCmd.QUERY, query))
  12. File "C:Anaconda3libsite-packagesmysqlconnectorconnection.py", line 395, in _handle_result
  13. raise errors.get_exception(packet)
  14. mysql.connector.errors.ProgrammingError: 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''navn') VALUES ('mokaiaaa')' at line 1
  15.  
  16. class MysqlManager():
  17. def __init__(self):
  18. self.sqlQueries = {"drinks" : """INSERT INTO drinks ('navn') VALUES ('%s')"""}
  19.  
  20. def Insert(self, tableName, *args):
  21. print(args)
  22. cursor, cnx = self.Connect()
  23.  
  24. query = self.sqlQueries[tableName] % args
  25.  
  26. print(query)
  27.  
  28. cursor.execute(query)
  29.  
  30. cnx.commit
  31. cursor.close()
  32. cnx.close()
  33.  
  34. def Connect(self):
  35. cnx = mysql.connector.connect(user="root", password="pass", host="127.0.0.1", database="mydb")
  36. cursor = cnx.cursor()
  37. return cursor, cnx
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement