]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
start relying on new unicode detection fully - remove isinstance() from the unicode...
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 15 Nov 2009 19:46:54 +0000 (19:46 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 15 Nov 2009 19:46:54 +0000 (19:46 +0000)
lib/sqlalchemy/dialects/oracle/cx_oracle.py
lib/sqlalchemy/types.py
test/dialect/test_oracle.py
test/sql/test_types.py

index 2db37a4fc68a5f655dcf5b3ca78509313f7f4673..47f66c0705107853825a45e6aabd13b8a00539c4 100644 (file)
@@ -124,20 +124,18 @@ class _LOBMixin(object):
     def result_processor(self, dialect, coltype):
         if not dialect.auto_convert_lobs:
             # return the cx_oracle.LOB directly.
-            # don't even call super.result_processor here.
             return None
             
         super_process = super(_LOBMixin, self).result_processor(dialect, coltype)
-        lob = dialect.dbapi.LOB
         if super_process:
             def process(value):
-                if isinstance(value, lob):
+                if value is not None:
                     return super_process(value.read())
                 else:
                     return super_process(value)
         else:
             def process(value):
-                if isinstance(value, lob):
+                if value is not None:
                     return value.read()
                 else:
                     return value
@@ -158,10 +156,25 @@ class _OracleText(_LOBMixin, sqltypes.Text):
     def get_dbapi_type(self, dbapi):
         return dbapi.CLOB
 
-class _OracleUnicodeText(_LOBMixin, sqltypes.UnicodeText):
+class _OracleUnicodeText(sqltypes.UnicodeText):
     def get_dbapi_type(self, dbapi):
         return dbapi.NCLOB
 
+    def result_processor(self, dialect, coltype):
+        if not dialect.auto_convert_lobs:
+            # return the cx_oracle.LOB directly.
+            return None
+
+        if dialect._cx_oracle_native_nvarchar:
+            def process(value):
+                if value is not None:
+                    return value.read()
+                else:
+                    return value
+            return process
+        else:
+            return super(_OracleUnicodeText, self).result_processor(dialect, coltype)
+
 class _OracleInteger(sqltypes.Integer):
     def result_processor(self, dialect, coltype):
         def to_int(val):
@@ -178,7 +191,7 @@ class _OracleBinary(_LOBMixin, sqltypes.Binary):
         return None
 
 
-class _OracleRaw(_LOBMixin, oracle.RAW):
+class _OracleRaw(oracle.RAW):
     pass
 
 
@@ -195,6 +208,7 @@ colspecs = {
                                         # it would be nice if we could not use it otherwise.
     oracle.NUMBER : oracle.NUMBER, # don't let this get converted
     oracle.RAW: _OracleRaw,
+    sqltypes.Unicode: _OracleNVarChar,
     sqltypes.NVARCHAR : _OracleNVarChar,
 }
 
@@ -266,7 +280,7 @@ class Oracle_cx_oracleExecutionContext(OracleExecutionContext):
                                                     dbapi_type)
                         if result_processor is not None:
                             out_parameters[name] = \
-                                    result_processor(self.out_parameters[name].getvalue(), dbapi_type)
+                                    result_processor(self.out_parameters[name].getvalue())
                         else:
                             out_parameters[name] = self.out_parameters[name].getvalue()
             else:
index 3fa18b2c26d1d1a18a85416471b119dd2f17ceba..62dd6dfc7bc00c5e56a878f21b2fcb93777da1d2 100644 (file)
@@ -522,10 +522,16 @@ class String(Concatenable, TypeEngine):
             return None
 
     def result_processor(self, dialect, coltype):
-        if (not dialect.returns_unicode_strings or self.convert_unicode == 'force') \
-            and (self.convert_unicode or dialect.convert_unicode):
+        wants_unicode = self.convert_unicode or dialect.convert_unicode
+        needs_convert = wants_unicode and \
+                        (not dialect.returns_unicode_strings or 
+                        self.convert_unicode == 'force')
+        
+        if needs_convert:
+            # note we *assume* that we do not have a unicode object
+            # here, instead of an expensive isinstance() check.
             def process(value):
-                if value is not None and not isinstance(value, unicode):
+                if value is not None:
                     return value.decode(dialect.encoding)
                 else:
                     return value
index 57be6fe618914502c8cc9e491ff750282fa16b73..97158217862f2ca3c2801de6a5f479c825bc2f35 100644 (file)
@@ -389,7 +389,7 @@ class TypesTest(TestBase, AssertsCompiledSQL):
             (Unicode(), Unicode),
             (Text(), cx_oracle._OracleText),
             (UnicodeText(), cx_oracle._OracleUnicodeText),
-            (NCHAR(), NCHAR),
+            (NCHAR(), cx_oracle._OracleNVarChar),
             (oracle.RAW(50), cx_oracle._OracleRaw),
         ]:
             assert isinstance(start.dialect_impl(dialect), test), "wanted %r got %r" % (test, start.dialect_impl(dialect))
index a3cb03022a8da411b11f7f028553b277b4a51e6f..332e02ef5f9b90562ca798ec711d0e0c79d9f408 100644 (file)
@@ -279,8 +279,10 @@ class UnicodeTest(TestBase, AssertsExecutionResults):
         unicode_table.insert().execute(unicode_varchar=unicodedata,unicode_text=unicodedata)
         
         x = unicode_table.select().execute().first()
-        self.assert_(isinstance(x['unicode_varchar'], unicode) and x['unicode_varchar'] == unicodedata)
-        self.assert_(isinstance(x['unicode_text'], unicode) and x['unicode_text'] == unicodedata)
+        assert isinstance(x['unicode_varchar'], unicode)
+        assert isinstance(x['unicode_text'], unicode)
+        eq_(x['unicode_varchar'], unicodedata)
+        eq_(x['unicode_text'], unicodedata)
 
     def test_round_trip_executemany(self):
         # cx_oracle was producing different behavior for cursor.executemany()