Warm tip: This article is reproduced from serverfault.com, please click

其他-在SQlite中更改数据时出现错误;

(其他 - I get an error when changing data in SQlite; Python)

发布于 2020-11-28 20:36:40

我正在尝试将新数据保存在sqlite中并出现错误。代码:

 def saveChanges(player_to_save, player_id):
    db = sqlite3.connect('db_player.db')
    sql = db.cursor()
    sql.execute(f"""UPDATE users SET (lvl = {player_to_save.lvl}, exp = {player_to_save.exp}, hp = {player_to_save.hp}, items = {converToJson_items(player_to_save)}, weapon = {convertToJson_weapon(player_to_save)}, armour = {convertToJson_armour(player_to_save)}, bounus = {convertToJson_bounus(player_to_save)}, bonuses_award = {convertToJson_bonuses_award(player_to_save)}, stats = {converToJson_stats(player_to_save)} ) WHERE login = '{player_id}'""")

错误:

line 384, in saveChanges
sql.execute(f"""UPDATE users SET (lvl = {player_to_save.lvl}, exp = {player_to_save.exp}, hp = {player_to_save.hp}, items = {converToJson_items(player_to_save)}, weapon = {convertToJson_weapon(player_to_save)}, armour = {convertToJson_armour(player_to_save)}, bounus = {convertToJson_bounus(player_to_save)}, bonuses_award = {convertToJson_bonuses_award(player_to_save)}, stats = {converToJson_stats(player_to_save)} ) WHERE login = '{player_id}'""")
sqlite3.OperationalError: near "=": syntax error

我该如何解决?

Questioner
Frei
Viewed
0
Shradha 2020-11-29 16:25:29

使用此语法-

sql.execute('''UPDATE tablename SET v1 = ?, v2 = ? where c1 = ?;''', (new_val1, new_val2, condition))