[pysqlite] Explanation of 2.5.0 behavioral change
Gerhard Häring <[email protected]> Sun, 12 Oct 2008 20:48:17 +0200
| Newsgroups | gmane.comp.python.db.pysqlite.user |
|---|---|
| Message-ID | <[email protected]> |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Michael Bayer brought to my attention that I forgot to tell something
important in the 2.5.0 release.
pysqlite now helps to not shoot yourself in the foot with Unicode vs.
bytestrings. And it's quite strict about it. If you do this:
gerhard@lara:~/tmp$ cat x.py
# coding: utf-8
from pysqlite2 import dbapi2 as sqlite3
con = sqlite3.connect(":memory:")
data = <some non-ASCII bytestring>
res = con.execute("select ?", (data,)).fetchone()[0]
You will get
"""
pysqlite2.dbapi2.ProgrammingError: You must not use 8-bit bytestrings
unless you use a text_factory that can interpret 8-bit bytestrings (like
text_factory = str). It is highly recommended that you instead just
switch your application to Unicode strings.
"""
So it's now either:
- - Unicode in, Unicode out
or
- - bytestring in, bytestring out
This change is not entirely backwards compatible, but at the time I
believed it was worth it. This way, errors are raised early, at insert
time into the database, instead of failing days/weeks/months later when
trying to fetch them from the database.
- -- Gerhard
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFI8kZxdIO4ozGCH14RAsedAJ44PUaQCbGy0KgpiT9qi8f8lCgvFQCgqynH
QfxfnTC1i+cKl98T9vmz3vY=
=6OE4
-----END PGP SIGNATURE-----