0

最近まで、次のコードは正しく機能していました。

for player in away_starters_names:
    on = 0
    this_player = player[0]
    if this_player in event:
        player_id = away_team_dict[this_player]
        player_id = int(player_id[0])
        team = 0
        team_id = away_id
        cur.execute("""INSERT INTO football.match_subs(player, time, added, game_id, home, on, team_id) VALUES (%s, %s, %s, %s, %s, %s, %s) ON DUPLICATE KEY UPDATE game_id = game_id""", (player_id, time, added, game_id, team, on, team_id))
        db.commit()

次のエラーが発生します。

    Traceback (most recent call last):
  File "Z:\Coding\bbc\find_teams.py", line 508, in <module>
    cur.execute("""INSERT INTO football.match_subs(player, time, added, game_id, home, on, team_id) VALUES (%s, %s, %s, %s, %s, %s, %s) ON DUPLICATE KEY UPDATE game_id = game_id""", (player_id, time, added, game_id, team, on, team_id))
  File "C:\Python27\lib\site-packages\MySQLdb\cursors.py", line 202, in execute
    self.errorhandler(self, exc, value)
  File "C:\Python27\lib\site-packages\MySQLdb\connections.py", line 36, in defaulterrorhandler
    raise errorclass, errorvalue
ProgrammingError: (1064, "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 'on, team_id) VALUES (299191, 89.33, 0, 21570967, 0, 0, 2) ON DUPLICATE KEY UPDAT' at line 1")

なにが問題ですか?

4

1 に答える 1

2

フィールド名の前後にバッククォートを使用します。ONMySQLの予約語です

于 2013-03-04T22:59:23.307 に答える