简体   繁体   English

如何将数字添加到sqlite3列值

[英]How to add number to sqlite3 column values

Am able to to successfully update sqlite3 column values with this function 能够使用此功能成功更新sqlite3列值

fgr = 1043

con = sqlite3.connect("test.db")
cur = con.cursor()
cur.executescript("UPDATE '{}' SET BALANCE=BALANCE+50".format(fgr))
con.commit()
con.close()

What i want to update it using the row Id greater than 4 , when i run the function it execute successfully but when the check the data in the column no changes has been applied. 我想使用大于4row Id更新它,当我运行该函数时,它会成功执行,但是当检查column的数据时,未应用任何更改。

Funtion Funtion

fgr = 1043

con = sqlite3.connect("test.db")
cur = con.cursor()
cur.executescript("UPDATE '{}' SET BALANCE=BALANCE+50".format(fgr))
cur.executescript("UPDATE '{}' SET BALANCE=BALANCE+50 WHERE ID > ?".format(fgr, (4),))
con.commit()
con.close()

I suspect that you are building your update query incorrectly. 我怀疑您在错误地构建更新查询。 Try this version: 试试这个版本:

fgr = 1043
ID = 4
cur.executescript("UPDATE \"" + fgr + "\" SET BALANCE = BALANCE + 50 WHERE ID > ?", (ID,))

If the above still update no records, then maybe you don't have any matching records in your SQLite database. 如果以上仍然没有更新记录,则可能您的SQLite数据库中没有任何匹配的记录。 Try to confirm this by running the following select: 尝试通过运行以下选择来确认这一点:

SELECT COUNT(*)
FROM 1043
WHERE ID > 4;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM