本文介绍了如何确定 Python sqlite UPDATE 是否有效?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Python 中使用 sqlite3.我想知道我的 UPDATE 语句是否在不执行另一个数据库查询的情况下工作:

I'm using sqlite3 in Python. I want to know if my UPDATE statement worked or not without doing another database query:

c.execute('update students set gpa=3.5 where stuid=123')

如果没有学生的 stuid 为 123,那么显然更新失败.

If there isn't a student with stuid 123 then obviously the update fails.

推荐答案

cursor.rowcount 如果更新成功(影响 1 行)则为 1,如果失败则为 0.

cursor.rowcount will be 1 if the update was successful (affecting 1 row) or 0 if it failed.

这篇关于如何确定 Python sqlite UPDATE 是否有效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 20:30