Author: Amaury Forgeot d'Arc <[email protected]>
Branch: py3k
Changeset: r63846:c00110d1c1d0
Date: 2013-05-04 11:45 +0200
http://bitbucket.org/pypy/pypy/changeset/c00110d1c1d0/

Log:    Port CPython fc6f90545cb4 for sqlite: fix error message when a
        fetched value cannot be decoded from utf8.

diff --git a/lib_pypy/_sqlite3.py b/lib_pypy/_sqlite3.py
--- a/lib_pypy/_sqlite3.py
+++ b/lib_pypy/_sqlite3.py
@@ -956,7 +956,19 @@
                     text = 
_lib.sqlite3_column_text(self.__statement._statement, i)
                     text_len = 
_lib.sqlite3_column_bytes(self.__statement._statement, i)
                     val = _ffi.buffer(text, text_len)[:]
-                    val = self.__connection.text_factory(val)
+                    try:
+                        val = self.__connection.text_factory(val)
+                    except Exception:
+                        column_name = _lib.sqlite3_column_name(
+                            self.__statement._statement, i)
+                        if column_name:
+                            column_name = 
_ffi.string(column_name).decode('utf-8')
+                        else:
+                            column_name = "<unknown column name>"
+                        val = val.decode('ascii', 'replace')
+                        raise OperationalError(
+                            "Could not decode to UTF-8 column '%s' with text 
'%s'" % (
+                                column_name, val))
                 elif typ == _lib.SQLITE_BLOB:
                     blob = 
_lib.sqlite3_column_blob(self.__statement._statement, i)
                     blob_len = 
_lib.sqlite3_column_bytes(self.__statement._statement, i)
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to