New submission from Erlend E. Aasland <erlend.aasl...@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
    0

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@python
components: Documentation
messages: 409713
nosy: docs@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 <rep...@bugs.python.org>
<https://bugs.python.org/issue46261>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to