Number of rows inserted into SQLite db is negative

元气小坏坏 提交于 2019-12-02 10:09:01
Mark Tolonen

Try cur.execute instead of con.execute. cur.rowcount then returns 1 for me for a simple insert.

http://docs.python.org/library/sqlite3.html#sqlite3.Cursor.rowcount

Although the Cursor class of the sqlite3 module implements this attribute, the database engine’s own support for the determination of “rows affected”/”rows selected” is quirky.

and

As required by the Python DB API Spec, the rowcount attribute “is -1 in case no executeXX() has been performed on the cursor or the rowcount of the last operation is not determinable by the interface”.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!