New submission from Serhiy Storchaka <storchaka+cpyt...@gmail.com>:

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

----------
components: Library (Lib)
messages: 352533
nosy: berker.peksag, ghaering, serhiy.storchaka
priority: normal
severity: normal
status: open
title: Weird way of case-insensitive indexing of sqlite3.Row
type: behavior
versions: Python 3.7, Python 3.8, Python 3.9

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue38185>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to