[docs] Please document sqlite3 return values

Julien Palard julien at palard.fr
Wed May 22 10:12:41 EDT 2019


Hi Bjartur, thanks for reporting,

> when I use the Python 3.7 from the public Docker image 2afe3d389ba0, fetchone seems to return (0,) when no row matches the query. Confusingly, fetchmany and fetchall are only documented as returnig "a list". A more specific type declaration or description of the hierarchical return type would be appreciated.

Do you have a script to reproduce the issue?

Here what I have tested (out of docker):

>>> import sqlite3
>>> con = sqlite3.connect(":memory:")
>>> cur = con.cursor()
>>> cur.executescript("""
...     create table person(
...         firstname,
...         lastname,
...         age
...     );
...
...     create table book(
...         title,
...         author,
...         published
...     );
...
...     insert into book(title, author, published)
...     values (
...         'Dirk Gently''s Holistic Detective Agency',
...         'Douglas Adams',
...         1987
...     );
...     """)
<sqlite3.Cursor object at 0x7f53c5c645e0>
>>> cur.execute("select * from book").fetchall()
[("Dirk Gently's Holistic Detective Agency", 'Douglas Adams', 1987)]
>>> cur.execute("select * from book").fetchone()
("Dirk Gently's Holistic Detective Agency", 'Douglas Adams', 1987)
>>> cur.execute("select * from book")
<sqlite3.Cursor object at 0x7f53c5c645e0>
>>> cur.fetchone()
("Dirk Gently's Holistic Detective Agency", 'Douglas Adams', 1987)
>>> cur.fetchone()
>>> cur.fetchone() is None
True
>>> cur.execute("select * from book where title = 'pouette'")
<sqlite3.Cursor object at 0x7f53c5c645e0>
>>> cur.fetchone()
>>> cur.fetchone() is None
True

-- 
Julien Palard
https://mdk.fr



More information about the docs mailing list