Message179049
sqlite3 doesn't populate the lastrowid member of the Cursor object when a SQL REPLACE statement is executed.
The following snippet doesn't work as I would expect:
cursor = db.execute("REPLACE INTO table(column) VALUES ('datum')")
print cursor.lastrowid # prints None
The following snippet, with SQL which is in effect identical to SQLite, does work as expected:
cursor = db.execute("INSERT OR REPLACE INTO table(column) VALUES ('datum')")
print cursor.lastrowid # prints some rowid
Looking at Modules/_sqlite/cursor.c, in _pysqlite_query_execute(), the following snippet is found:
if (!multiple && statement_type == STATEMENT_INSERT) {
Py_BEGIN_ALLOW_THREADS
lastrowid = sqlite3_last_insert_rowid(self->connection->db);
Py_END_ALLOW_THREADS
self->lastrowid = PyLong_FromLong((long)lastrowid);
} else {
Py_INCREF(Py_None);
self->lastrowid = Py_None;
}
I suggest this should read something like:
if (!multiple && (statement_type == STATEMENT_INSERT || statement_type == STATEMENT_REPLACE)) {
instead of:
if (!multiple && statement_type == STATEMENT_INSERT) {
Thanks,
Jim |
|
| Date |
User |
Action |
Args |
| 2013-01-04 17:24:20 | jim_minter | set | recipients:
+ jim_minter |
| 2013-01-04 17:24:20 | jim_minter | set | messageid: <[email protected]> |
| 2013-01-04 17:24:20 | jim_minter | link | issue16864 messages |
| 2013-01-04 17:24:19 | jim_minter | create | |
|