MySQL INSERT fails in Python but works fine in MySQL Workbench -
here query have runs fine in mysql workbench included sample values , works fine if manually plug in values in code, fails when use values parameters. ideas?
python code:
print player cur.execute(""" insert scoredata (gameid, playerid, starter, pos, min, fgm, fga, tpm, tpa, ftm, fta, oreb, reb, ast, stl, blk, tos, pf, pts) values (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s); """), (player[0], int(player[20]), int(player[19]), player[3], int(player[4]), int(player[5]), int(player[6]), int(player[7]), int(player[8]), int(player[9]), int(player[10]), int(player[11]), int(player[12]), int(player[13]), int(player[14]), int(player[15]), int(player[16]), int(player[17]), int(player[18]) ) db.commit()
error message:
['330060130', 103, 'roy devyn marble', 'g-f', '28', '4', '9', '3', '6', '3', '3', '0', '2', '1', '0', '0', '0', '1', '14', 1, 1391] traceback (most recent call last): file "c:\users\jcaine\workspace\basketballstats\src\basketballstats\basketballstats.py", line 350, in <module> insert_game_data('20130106', '20130106') file "c:\users\jcaine\workspace\basketballstats\src\basketballstats\basketballstats.py", line 284, in insert_game_data """), (player[0], int(player[20]), int(player[19]), player[3], int(player[4]), int(player[5]), int(player[6]), int(player[7]), int(player[8]), int(player[9]), int(player[10]), int(player[11]), int(player[12]), int(player[13]), int(player[14]), int(player[15]), int(player[16]), int(player[17]), int(player[18]) ) file "c:\users\jcaine\appdata\local\temp\easy_install-7_fysp\mysql_python-1.2.3-py2.7-win32.egg.tmp\mysqldb\cursors.py", line 174, in execute file "c:\users\jcaine\appdata\local\temp\easy_install-7_fysp\mysql_python-1.2.3-py2.7-win32.egg.tmp\mysqldb\connections.py", line 36, in defaulterrorhandler _mysql_exceptions.programmingerror: (1064, "you have error in sql syntax; check manual corresponds mysql server version right syntax use near '%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)' @ line 4")
mysql scoredata table columns:
gameid varchar playerid int starter int pos varchar min int fgm int fga int tpm int tpa int ftm int fta int oreb int reb int ast int stl int blk int tos int pf int pts int
mysql code runs fine in workbench:
insert scoredata (gameid, playerid, starter, pos, min, fgm, fga, tpm, tpa, ftm, fta, oreb, reb, ast, stl, blk, tos, pf, pts) values ('3300601300', 1391, 1, 'g-f', 28, 4, 9, 3, 6, 3, 3, 0, 2, 1, 0, 0, 0, 1, 14)
you're not passing data execute call. note closing brace in example.
cur.execute(""" insert scoredata (gameid, playerid, starter, pos, min, fgm, fga, tpm, tpa, ftm, fta, oreb, reb, ast, stl, blk, tos, pf, pts) values (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s); """)//*remove me* , (player[0], int(player[20]), int(player[19]), player[3], int(player[4]), int(player[5]), int(player[6]), int(player[7]), int(player[8]), int(player[9]), int(player[10]), int(player[11]), int(player[12]), int(player[13]), int(player[14]), int(player[15]), int(player[16]), int(player[17]), int(player[18]) ) db.commit()
Comments
Post a Comment