Get number of modified rows after sqlite3 execute

2019-04-18 14:33发布

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.

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?

标签: python c sqlite3
2条回答
Fickle 薄情
2楼-- · 2019-04-18 14:45

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.

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.

查看更多
Anthone
3楼-- · 2019-04-18 14:53

Assume table test(rowid, value) as follows. (1, '3') (2, 'a') After executing update test set value = '3' where rowid=1. Cursor.row=1. I think what it returns is the matched row

查看更多
登录 后发表回答