diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-03-11 21:52:54 -0500 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-03-11 21:52:54 -0500 |
| commit | 6c2e82ff8ce42d22a974ccd8890f96f671680faa (patch) | |
| tree | 600da841b0b0051e832d69284013b6d3bd7ebacf | |
| parent | 875487b8b78761dc162be55602da9b99bf0aca69 (diff) | |
| download | sqlalchemy-6c2e82ff8ce42d22a974ccd8890f96f671680faa.tar.gz | |
add a third state to converts_unicode_strings - "conditional". at the moment
this will have us do a check. i.e. for MSSQL where NVARCHAR is unicode and VARCHAR is not.
| -rw-r--r-- | lib/sqlalchemy/engine/default.py | 20 | ||||
| -rw-r--r-- | lib/sqlalchemy/types.py | 5 |
2 files changed, 21 insertions, 4 deletions
diff --git a/lib/sqlalchemy/engine/default.py b/lib/sqlalchemy/engine/default.py index cd2c10393..454d2a593 100644 --- a/lib/sqlalchemy/engine/default.py +++ b/lib/sqlalchemy/engine/default.py @@ -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 diff --git a/lib/sqlalchemy/types.py b/lib/sqlalchemy/types.py index bf06ec99b..3b7027e23 100644 --- a/lib/sqlalchemy/types.py +++ b/lib/sqlalchemy/types.py @@ -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): |
