在 Python 中执行 sqlite3 后获取修改的行数 [英] Get number of modified rows after sqlite3 execute in Python

查看:17
本文介绍了在 Python 中执行 sqlite3 后获取修改的行数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当执行UPDATEINSERT等SQL语句时,Cursor<上常用的.fetch*()方法/code> 实例显然不适用于修改的行数.

When performing SQL statements such as UPDATE, and INSERT, the usual .fetch*() methods on the Cursor instance obviously don't apply to the number of rows modified.

在执行上述语句之一的情况下,在Python中获取相应行数的正确方法是什么,以及Sqlite3 C接口中的相应API?

In the event of executing one of the aforementioned statements, what is the correct way to obtain the corresponding row count in Python, and the corresponding API in the Sqlite3 C interface?

推荐答案

在使用 UPDATE 或 INSERT 语句调用 Cursor.execute*() 方法后,您可以使用 Cursor.rowcount 查看受执行调用影响的行数.

After calling your Cursor.execute*() methods with your UPDATE or INSERT statements you can use Cursor.rowcount to see the # of rows affected by the execute call.

如果我不得不猜测,我会说 python 库正在调用 int sqlite3_changes(sqlite3*) 来自 C API,但我没有看过代码,所以我不能肯定.

If I had to guess I would say the python lib is calling int sqlite3_changes(sqlite3*) from the C API but I have not looked at the code so I can't say for sure.

这篇关于在 Python 中执行 sqlite3 后获取修改的行数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆