]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
add a third state to converts_unicode_strings - "conditional". at the moment
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 12 Mar 2010 02:52:54 +0000 (21:52 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 12 Mar 2010 02:52:54 +0000 (21:52 -0500)
this will have us do a check.  i.e. for MSSQL where NVARCHAR is unicode and VARCHAR is not.

lib/sqlalchemy/engine/default.py
lib/sqlalchemy/types.py

index cd2c103938bcd50aae90e2ae0e9f72d39fce5e63..454d2a593e76dd04d4b56f9d424d370d2090db1c 100644 (file)
@@ -148,9 +148,25 @@ class DefaultDialect(base.Dialect):
         )
         
         row = cursor.fetchone()
-        result = isinstance(row[0], unicode)
+        unicode_for_varchar = isinstance(row[0], unicode)
+
+        cursor.execute(
+            str(
+                expression.select( 
+                [expression.cast(
+                    expression.literal_column("'test unicode returns'"),sqltypes.VARCHAR(60))
+                ]).compile(dialect=self)
+            )
+        )
+        
+        row = cursor.fetchone()
+        unicode_for_unicode = isinstance(row[0], unicode)
         cursor.close()
-        return result
+        
+        if unicode_for_unicode and not unicode_for_varchar:
+            return "conditional"
+        else:
+            return unicode_for_varchar
         
     def type_descriptor(self, typeobj):
         """Provide a database-specific ``TypeEngine`` object, given
index bf06ec99b7d8ff1cd2c5125a3c950a0499461ce6..3b7027e23cad2bfc170f45210ddd7d402f8bb620 100644 (file)
@@ -688,7 +688,7 @@ class String(Concatenable, TypeEngine):
     def result_processor(self, dialect, coltype):
         wants_unicode = self.convert_unicode or dialect.convert_unicode
         needs_convert = wants_unicode and \
-                        (not dialect.returns_unicode_strings or 
+                        (dialect.returns_unicode_strings is not True or 
                         self.convert_unicode == 'force')
         
         if needs_convert:
@@ -697,7 +697,8 @@ class String(Concatenable, TypeEngine):
             
             if dialect.returns_unicode_strings:
                 # we wouldn't be here unless convert_unicode='force'
-                # was specified.   since we will be getting back unicode
+                # was specified, or the driver has erratic unicode-returning
+                # habits.  since we will be getting back unicode
                 # in most cases, we check for it (decode will fail).   
                 def process(value):
                     if isinstance(value, unicode):