dabo Commit
Revision 6123
Date: 2010-10-21 15:44:33 -0700 (Thu, 21 Oct 2010)
Author: Paul
Trac: http://trac.dabodev.com/changeset/6123
Changed:
U trunk/dabo/db/dCursorMixin.py
U trunk/dabo/db/dbSQLite.py
Log:
Set the sqlite connection text_factory to str, to tell the adapter not to
decode the
field values but to just return the bytes. This allows the dabo layer to do the
decoding, and for the trial of various encodings upon UnicodeDecodeError. More
importantly, it seems to fix the problems I've seen with the recent release of
my
application.
Removed the setting of dCursor.Encoding based on the first trial encoding that
didn't
result in a UnicodeDecodeError. We should leave dCursor.Encoding alone even
though
we decoded a specific field using a different encoding. dCursor.Encoding should
come from what the database reports, and stay that way unless the appdev changes
it.
I think. Please, people with more unicode experience, critique me on anything
and
everything I'm doing.
Diff:
Modified: trunk/dabo/db/dCursorMixin.py
===================================================================
--- trunk/dabo/db/dCursorMixin.py 2010-10-21 22:12:34 UTC (rev 6122)
+++ trunk/dabo/db/dCursorMixin.py 2010-10-21 22:44:33 UTC (rev 6123)
@@ -275,7 +275,14 @@
continue
if ok:
# change self.Encoding
and log the message
- self.Encoding = enc
+ ## pkm 2010-10-21: I
think that mismatched encoding should be treated as exceptional,
+ ## and
shouldn't trigger changing the cursor Encoding which should
+ ## have
been set based on what the database reported (currently it is
+ ## not
set that way, but I hope it will be in the future). But it is
+ ## nice
to at least try some different common encodings if the default
+ ## one
doesn't work, especially since Dabo currently allows non-utf8-encoded
+ ##
bytes to get saved to the database.
+ #self.Encoding = enc
dabo.log.error(_("Field
%(fname)s: Incorrect unicode encoding set; using '%(enc)s' instead")
%
{'fname':field_name, 'enc':enc} )
return ret
Modified: trunk/dabo/db/dbSQLite.py
===================================================================
--- trunk/dabo/db/dbSQLite.py 2010-10-21 22:12:34 UTC (rev 6122)
+++ trunk/dabo/db/dbSQLite.py 2010-10-21 22:44:33 UTC (rev 6123)
@@ -67,8 +67,14 @@
# Database file does not exist; raise an error
raise DBFileDoesNotExistException(_("Database
file '%s' does not exist") % pth)
pth = pth.decode(dabo.fileSystemEncoding).encode("utf-8")
+
# Need to specify "isolation_level=None" to have transactions
working correctly.
self._connection = self.dbapi.connect(pth,
factory=DictConnection, isolation_level=None)
+
+ # Non-utf8-encoded bytestrings could be in the database, and
Dabo will try various encodings
+ # to deal with it. So tell sqlite not to decode with utf-8, but
to just return the bytes:
+ self._connection.text_factory = str
+
self._connection.connectInfo = connectInfo
return self._connection
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev
Searchable Archives: http://leafe.com/archives/search/dabo-dev
This message:
http://leafe.com/archives/byMID/[email protected]