[New-bugs-announce] [issue46261] [doc] fix inaccuracies in sqlite3.Cursor.lastrowid docs

Erlend E. Aasland report at bugs.python.org
Tue Jan 4 16:46:55 EST 2022

New submission from Erlend E. Aasland <erlend.aasland at innova.no>:

The sqlite3 docs say that lastrowid is set to None after executemany(), or after execute()'ing statements that are not INSERTs or REPLACEs. This is not true; in those cases, lastrowid is preserved. lastrowid is only None in a pristine cursor. Suggesting to reword the docs so they harmonise with the implementation.

Note, there is a quirk, or bug with lastrowid: it is set to 0 if the first statement that's execute()d on a cursor is a non-INSERT/REPLACE statement. For example:

    >>> import sqlite3
    >>> cx = sqlite3.connect(":memory:")
    >>> cu = cx.cursor()
    >>> cu.lastrowid
    >>> cu.execute("select 1")
    >>> cu.lastrowid

This behaviour is consistent across current main through 3.7 (though in 2.7, the behaviour is consistent with the docs, so it probably changed a long time ago). I'm not sure it's worth noting this side effect in the docs though.

assignee: docs at python
components: Documentation
messages: 409713
nosy: docs at python, erlendaasland, lemburg
priority: normal
severity: normal
status: open
title: [doc] fix inaccuracies in sqlite3.Cursor.lastrowid docs
versions: Python 3.10, Python 3.11, Python 3.9

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list