[issue16864] sqlite3.Cursor.lastrowid isn't populated when executing a SQL REPLACE statement

Alex Lord report at bugs.python.org
Sun May 10 23:03:51 CEST 2015


Alex Lord added the comment:

Updated the patch to have a versionchanged for lastrowid in Doc/Library/sqlite3.rst and Doc/whatsnew/3.5.rst

One thing of note is that I wasn't able to get the indentation to be on the same level for sqlite3.rst (it would either intent the description text or the versionchange text).

Now that I'm actually starting to understand the dbapi and sqlite3 I've come to the conclusion that the lastrowid method should update the lastrowid for the INSERT OR ROLLBACK, INSERT OR ABORT, INSERT OR FAIL, INSERT OR IGNORE statements as well as the INSERT and INSERT OR REPLACE statements. 

I'm unsure how hard or simple supporting those statements will be

The code in question is

 704         Py_DECREF(self->lastrowid);$
 705         if (!multiple && statement_type == STATEMENT_INSERT) {$
 706             sqlite_int64 lastrowid;$
 707             Py_BEGIN_ALLOW_THREADS$
 708             lastrowid = sqlite3_last_insert_rowid(self->connection->db);$
 709             Py_END_ALLOW_THREADS$
 710             self->lastrowid = _pysqlite_long_from_int64(lastrowid);

And the difficulty will be if sqlite3_last_insert_rowid (line 708) does or doesn't return a row id if the OR STATEMENT portion of those inserts are triggered.

The Problem I'm having is that when I tried to find sqlite3_last_insert_rowid in the Modules/_sqlite directory I got nothing

$ grep -r "sqlite3_last_insert_rowid" Modules/_sqlite/
Modules/_sqlite//cursor.c:            lastrowid = sqlite3_last_insert_rowid(self->connection->db);

When I pulled the grep out to the entire cpython repository 

$ grep -r "sqlite3_last_insert_rowid" .
Binary file ./build/lib.macosx-10.10-x86_64-3.5-pydebug/_sqlite3.cpython-35dm-darwin.so matches
Binary file ./build/lib.macosx-10.10-x86_64-3.5-pydebug/_sqlite3.so matches
Binary file ./build/temp.macosx-10.10-x86_64-3.5-pydebug/Users/alexlord/mercurial/cpython/Modules/_sqlite/cursor.o matches
./Modules/_sqlite/cursor.c:            lastrowid = sqlite3_last_insert_rowid(self->connection->db);

I still didn't find anything and I'm not sure where to go from here.

----------
Added file: http://bugs.python.org/file39336/sqlite_lastrowid_35.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue16864>
_______________________________________


More information about the Python-bugs-list mailing list