classification
Title: Weird way of case-insensitive indexing of sqlite3.Row
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.9, Python 3.8, Python 3.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: berker.peksag, ghaering, miss-islington, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2019-09-16 10:00 by serhiy.storchaka, last changed 2019-09-17 09:37 by serhiy.storchaka. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 16190 merged serhiy.storchaka, 2019-09-16 16:32
PR 16216 merged miss-islington, 2019-09-17 06:21
PR 16217 merged miss-islington, 2019-09-17 06:21
Messages (4)
msg352533 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2019-09-16 10:00
sqlite3.Row can be indexed by integers and by strings. In the latter case string matching is case insensitive. But the code that implements this is too simple-minded. It compares UTF-8 representation of two strings ignoring some bit. It works for ASCII letters, but has weird behavior for digits, '_' and non-ASCII characters.

For example:

>>> import sqlite3
>>> con = sqlite3.connect(":memory:")
>>> con.row_factory = sqlite3.Row
>>> row = con.execute("select 1 as a_1").fetchone()
>>> row['a_1']
1
>>> row['A_1']
1
>>> row['A_\x11']
1
>>> row['A\x7f1']
1
>>> row = con.execute("select 1 as ÿ").fetchone()
>>> row["ÿ"]
1
>>> row["Ÿ"]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IndexError: No item with that key
>>> row["ß"]
1
msg352604 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2019-09-17 06:20
New changeset f669581a9527afb0d2325f9845a86715c0ba365d by Serhiy Storchaka in branch 'master':
bpo-38185: Fixed case-insensitive string comparison in sqlite3.Row indexing. (GH-16190)
https://github.com/python/cpython/commit/f669581a9527afb0d2325f9845a86715c0ba365d
msg352611 - (view) Author: miss-islington (miss-islington) Date: 2019-09-17 06:39
New changeset d8d653c2d0d267eb1e44f6cdb916945029fec3b1 by Miss Islington (bot) in branch '3.8':
bpo-38185: Fixed case-insensitive string comparison in sqlite3.Row indexing. (GH-16190)
https://github.com/python/cpython/commit/d8d653c2d0d267eb1e44f6cdb916945029fec3b1
msg352612 - (view) Author: miss-islington (miss-islington) Date: 2019-09-17 06:39
New changeset 80cb055aa45f37951b8e3097fe4367d443d455ae by Miss Islington (bot) in branch '3.7':
bpo-38185: Fixed case-insensitive string comparison in sqlite3.Row indexing. (GH-16190)
https://github.com/python/cpython/commit/80cb055aa45f37951b8e3097fe4367d443d455ae
History
Date User Action Args
2019-09-17 09:37:40serhiy.storchakasetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2019-09-17 06:39:52miss-islingtonsetmessages: + msg352612
2019-09-17 06:39:14miss-islingtonsetnosy: + miss-islington
messages: + msg352611
2019-09-17 06:21:18miss-islingtonsetpull_requests: + pull_request15818
2019-09-17 06:21:10miss-islingtonsetpull_requests: + pull_request15817
2019-09-17 06:20:59serhiy.storchakasetmessages: + msg352604
2019-09-16 16:32:34serhiy.storchakasetkeywords: + patch
stage: patch review
pull_requests: + pull_request15796
2019-09-16 10:00:11serhiy.storchakacreate