Author: phd
Date: Mon Apr 18 05:24:34 2011
New Revision: 4378
Log:
Set connection.text_factory to work around a bug in PySQLite.
Modified:
SQLObject/trunk/docs/News.txt
SQLObject/trunk/sqlobject/sqlite/sqliteconnection.py
SQLObject/trunk/sqlobject/tests/test_sqlite.py
Modified: SQLObject/trunk/docs/News.txt
==============================================================================
--- SQLObject/trunk/docs/News.txt Mon Apr 18 05:15:57 2011 (r4377)
+++ SQLObject/trunk/docs/News.txt Mon Apr 18 05:24:34 2011 (r4378)
@@ -37,6 +37,14 @@
* Parameter ``backend`` in DB URI is no longer supported, use parameter
``driver``.
+Internals
+---------
+
+* A different workaround is used in SQLiteConnection to prevent PySQLite
+ from converting strings to unicode - in the case of a registered text
+ conversion function PySQLite silently converts empty strings to Nones;
+ now SQLObject uses text_factory instead.
+
SQLObject 0.15.1
================
Modified: SQLObject/trunk/sqlobject/sqlite/sqliteconnection.py
==============================================================================
--- SQLObject/trunk/sqlobject/sqlite/sqliteconnection.py Mon Apr 18 05:15:57 2011 (r4377)
+++ SQLObject/trunk/sqlobject/sqlite/sqliteconnection.py Mon Apr 18 05:24:34 2011 (r4378)
@@ -59,10 +59,6 @@
if self.using_sqlite2:
if autoCommit:
opts["isolation_level"] = None
- opts["detect_types"] = sqlite.PARSE_DECLTYPES
- for col_type in "text", "char", "varchar", "date", "time", "datetime", "timestamp":
- sqlite.register_converter(col_type, stop_pysqlite2_converting_strings)
- sqlite.register_converter(col_type.upper(), stop_pysqlite2_converting_strings)
global sqlite2_Binary
if sqlite2_Binary is None:
sqlite2_Binary = sqlite.Binary
@@ -95,6 +91,9 @@
if self._memory:
self._memoryConn = sqlite.connect(
self.filename, **self._connOptions)
+ # Convert text data from SQLite to str, not unicode -
+ # SQLObject converts it to unicode itself.
+ self._memoryConn.text_factory = str
def _connectionFromParams(cls, user, password, host, port, path, args):
assert host is None and port is None, (
@@ -188,7 +187,9 @@
def makeConnection(self):
if self._memory:
return self._memoryConn
- return self.module.connect(self.filename, **self._connOptions)
+ conn = self.module.connect(self.filename, **self._connOptions)
+ conn.text_factory = str # Convert text data to str, not unicode
+ return conn
def _executeRetry(self, conn, cursor, query):
if self.debug:
@@ -394,7 +395,3 @@
if self._memory:
return
os.unlink(self.filename)
-
-
-def stop_pysqlite2_converting_strings(s):
- return s
Modified: SQLObject/trunk/sqlobject/tests/test_sqlite.py
==============================================================================
--- SQLObject/trunk/sqlobject/tests/test_sqlite.py Mon Apr 18 05:15:57 2011 (r4377)
+++ SQLObject/trunk/sqlobject/tests/test_sqlite.py Mon Apr 18 05:24:34 2011 (r4378)
@@ -97,3 +97,10 @@
# made above (at least will with most database drivers, but
# this will cause an error in SQLite):
do_select()
+
+
+def test_empty_string():
+ setupClass(TestSO1)
+ test = TestSO1(name=None, passwd='')
+ assert test.name is None
+ assert test.passwd == ''
|