python - 更新多列: the Username disappears

标签 python sqlite

我正在尝试使用 Python 和 SQLite 更新我的用户详细信息。

目标是一次性升级我用户的所有栏目。

我的代码是:

def update():
  new_username = input("Input your NEW username:\n")
  new_firstname = input("Input your NEW firstname:\n")
  new_lastname = input("Input your NEW lastname:\n")
  new_email = input("Input your NEW email:\n")
  new_password = input("Input your NEW password:\n")
  update_customer =("""UPDATE customer SET username = ? AND firstname = ? AND lastname = ? AND email = ? AND password = ?""")
  cursor.execute(update_customer, [(new_username), (new_firstname), (new_lastname), (new_email), (new_password)])

我在运行 python 函数之前和之后检查了数据库。但是,更改不会保存到数据库中。除了消失的用户名之外什么都没有改变。

最佳答案

您不能使用 AND 来设置其他列。相反,您可以使用逗号分隔要设置的列。

所以你想要

update_customer =("""UPDATE customer SET username = ?, firstname = ?, lastname = ?, email = ?, password = ?""")

如果没有将所有行设置为相同的值,则使用 WHERE 子句。

根据:-

enter image description here

SQL As Understood By SQLite - UPDATE

关于python - 更新多列: the Username disappears,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53891137/

相关文章:

sqlite - 如何在 SQLite 中获取子字符串的最后一个索引?

android - 将游标数据复制到 arraylist

java - Android - CursorAdapter-ish 子类,用于 ListView

以相反顺序访问 numpy 数组的 Pythonic 方法

python - 如何在网页上即时显示文字?

python - 如何使 django 评论模型字段不需要站点

C++, SQLite - 指向字符串指针的指针

android - 如何限制 Android SQLite 表中的行数

python - gRPC/proto Google 云客户端库与 GAPIC Google 云客户端库

python - 使用 TFlearn 塑造线性回归数据