[New-bugs-announce] [issue13921] sqlite3: OptimizedUnicode doesn't work in Py3k
report at bugs.python.org
Wed Feb 1 21:57:38 CET 2012
New submission from Petri Lehtinen <petri at digip.org>:
Connection.text_factory can be used to control what objects are
returned for the TEXT data type. An excerpt from the docs:
For efficiency reasons, there’s also a way to return str
objects only for non-ASCII data, and bytes otherwise. To
activate it, set this attribute to sqlite3.OptimizedUnicode.
However, it always returns Unicode strings now. There's even a
test for this feature which is obviously wrong:
self.con.text_factory = sqlite.OptimizedUnicode
austria = "Österreich"
germany = "Deutchland"
a_row = self.con.execute("select ?", (austria,)).fetchone()
d_row = self.con.execute("select ?", (germany,)).fetchone()
self.assertTrue(type(a_row) == str, "type of non-ASCII row must be str")
self.assertTrue(type(d_row) == str, "type of ASCII-only row must be str")
It checks for str in both cases even though it should test for
bytes in the latter case.
The user can get bytes if he wants to by saying so explicitly.
Having the library mix bytes and unicode by itself makes it
harder for the user. Furthermore, I don't really buy
the "efficiency" reason here, so I'd vote for removing the whole
OptimizeUnicode thing. It has never worked for Py3k so it would
components: Library (Lib)
nosy: petri.lehtinen, pitrou
title: sqlite3: OptimizedUnicode doesn't work in Py3k
versions: Python 3.2, Python 3.3
Python tracker <report at bugs.python.org>
More information about the New-bugs-announce