それぞれの条件が満たされている場合に、タイプ DATE の値を持つ複数の列に対して db レコードが存在するという条件で db 更新を実行しようとしていますが、問題があるようです。どんな助けでも大歓迎です。ありがとう!
次のコード
select_cmd = "SELECT * FROM " + self.designator + " WHERE player_fkid=" + str(fixed['player_fkid']) + \
" AND team_fkid=" + str(fixed['team_fkid']) + " AND season_fkid=" + str(fixed['season_fkid'])
update_start_cmd = "UPDATE " + self.designator + " SET date_start='" + str(update['date_start']) + \
"' WHERE date_start>'" + str(update['date_start']) + "'"
update_end_cmd = "UPDATE " + self.designator + " SET date_end='" + str(update['date_end']) + "' WHERE date_end<'" + \
str(update['date_end']) + "'"
insert_cmd = "INSERT INTO " + self.designator + " (player_fkid, team_fkid, season_fkid, date_start, date_end) VALUES (" + \
str(fixed['player_fkid']) + ", " + str(fixed['team_fkid']) + ", " + str(fixed['season_fkid']) + ", '" + \
str(update['date_start']) + "', '" + str(update['date_end']) + "')"
cmd = "IF EXISTS (" + select_cmd + ")" + "\n" + update_start_cmd + "\n" + update_end_cmd + "\nELSE " + insert_cmd
try:
cursor.execute(cmd)
cnx.commit()
except mysql.connector.errors.ProgrammingError:
print "Error: invalid command '" + cmd + "'"
次のエラーを返します。
エラー: 無効なコマンド 'IF EXISTS (SELECT * FROM roster WHERE player_fkid=1 AND team_fkid=1 AND season_fkid=1)
UPDATE roster SET date_start='2010-04-13' WHERE date_start>'2010-04-13'
UPDATE roster SET date_end='2010-04-13' WHERE date_end<'2010-04-13'
ELSE INSERT INTO 名簿 (player_fkid, team_fkid, season_fkid, date_start, date_end) VALUES (1, 1, 1, '2010-04-13', '2010-04-13')'