是否将数据插入特定的Sqlite3数据库行?

2024-09-25 08:41:47 发布

您现在位置:Python中文网/ 问答频道 /正文

self.cursor.execute('INSERT INTO User where User_name=(?) (user_name,user_password,user_wins,user_loses) VALUES(?,?,?,?)',(a,a,b,c,d))
self.connect.commit()

从逻辑上说,我本以为这会奏效,但我不知道为什么它没有? sql语句中的第一个“?”与“a”相同。 我得到这个错误:

sqlite3.OperationalError: near "where": syntax error

所以我想知道是否真的有可能写入SQL数据库中已经写入的行


Tags: nameselfexecuteconnectpasswordwherecursorcommit
1条回答
网友
1楼 · 发布于 2024-09-25 08:41:47

INSERT表示添加一个全新的行。如果要更改现有行,则需要UPDATE

例如

UPDATE User
SET user_password=?,
    user_wins=?,
    user_loses=?
WHERE user_name=?

将用户名作为最后一个变量传递

比如:

self.cursor.execute(
    'UPDATE User SET user_password=?, user_wins=?, user_loses=? WHERE user_name=?',
    (b,c,d,a)
)

相关问题 更多 >