Python、sqlite3 和 UPDATE 几行
Python, sqlite3 and UPDATE several rows
这是我要执行的代码
db.execute('''UPDATE WARDWINS \
SET map = ?,
SET team1wards = ?,
SET team2wards = ?,
SET mostwards = ?,
SET winningteam = ?,
SET mostwardswin = ?
where matchID = ?''', (dic['mapID'][0], dic['team1wards'], dic['team2wards'], dic['mostwards'], dic['winningteam'], dic['wardswins'], match))
我想要实现的是让一个执行命令同时更新以上所有行,但出于某种原因我似乎无法弄清楚如何做到这一点。我收到以下错误消息:
>>> dic['mostwards'], dic['winningteam'], dic['wardswins'], match))
sqlite3.OperationalError: near "SET": syntax error
事实证明,答案几乎是正确的。 (不总是这样吗?)
sqlite3.execute 命令只需要一个 SET,其他的都是多余的,并且会造成语法错误。正确的做法如下:
db.execute('''UPDATE WARDWINS \
SET map = ?,
team1wards = ?,
team2wards = ?,
mostwards = ?,
winningteam = ?,
mostwardswin = ?
where matchID = ?''', (dic['mapID'][0], dic['team1wards'], dic['team2wards'], dic['mostwards'], dic['winningteam'], dic['wardswins'], match))
这是我要执行的代码
db.execute('''UPDATE WARDWINS \
SET map = ?,
SET team1wards = ?,
SET team2wards = ?,
SET mostwards = ?,
SET winningteam = ?,
SET mostwardswin = ?
where matchID = ?''', (dic['mapID'][0], dic['team1wards'], dic['team2wards'], dic['mostwards'], dic['winningteam'], dic['wardswins'], match))
我想要实现的是让一个执行命令同时更新以上所有行,但出于某种原因我似乎无法弄清楚如何做到这一点。我收到以下错误消息:
>>> dic['mostwards'], dic['winningteam'], dic['wardswins'], match))
sqlite3.OperationalError: near "SET": syntax error
事实证明,答案几乎是正确的。 (不总是这样吗?) sqlite3.execute 命令只需要一个 SET,其他的都是多余的,并且会造成语法错误。正确的做法如下:
db.execute('''UPDATE WARDWINS \
SET map = ?,
team1wards = ?,
team2wards = ?,
mostwards = ?,
winningteam = ?,
mostwardswin = ?
where matchID = ?''', (dic['mapID'][0], dic['team1wards'], dic['team2wards'], dic['mostwards'], dic['winningteam'], dic['wardswins'], match))