This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Add get() method to sqlite3.Row class
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.8
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: rhettinger, serhiy.storchaka, wsanchez
Priority: normal Keywords:

Created on 2018-05-25 21:58 by wsanchez, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (5)
msg317719 - (view) Author: Wilfredo Sanchez (wsanchez) Date: 2018-05-25 21:58
The sqlite3.Row class has mapping-like behavior but does not implement the get() method, so providing default values in code requires a bit of boilerplate that is not necessary with dictionaries.
msg317723 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2018-05-26 00:20
How is this needed?  SQL queries return rows that are homogenous and with known fields.  This is isn't like other dictionaries when you might not know in advance whether a given key is present.
msg317729 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-05-26 07:45
I have the same question. Do you have a concrete example where this can be useful?

sqlite3.Row is not a mapping. It is a sequence.

>>> import sqlite3
>>> import collections.abc
>>> issubclass(sqlite3.Row, collections.abc.Sequence)
True
msg317778 - (view) Author: Wilfredo Sanchez (wsanchez) Date: 2018-05-27 03:34
Well, sequence and mapping are not mutually exclusive, and sqlite3.Row does allow mapping-style indexing, which is why I expected .get() to work.

But I hear Raymond's point about all field being known, and I think that's a good point… and I agree I don't actually need .get().

Feel free to close. Thanks for the quick replies.
msg317781 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2018-05-27 04:18
> But I hear Raymond's point about all field being known, 
> and I think that's a good point… and I agree I don't 
> actually need .get().

> Feel free to close. Thanks for the quick replies.

Okay, done.
History
Date User Action Args
2022-04-11 14:59:00adminsetgithub: 77832
2018-05-27 04:18:14rhettingersetstatus: open -> closed
versions: + Python 3.8, - Python 3.6
messages: + msg317781

resolution: rejected
stage: resolved
2018-05-27 03:34:18wsanchezsetmessages: + msg317778
2018-05-26 07:45:39serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg317729
2018-05-26 00:20:03rhettingersetnosy: + rhettinger
messages: + msg317723
2018-05-25 21:58:55wsanchezcreate