diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-03-17 16:01:29 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-03-17 16:01:29 -0400 |
commit | 214ed6239eb187c32e37bb7e3e3ac76555e266aa (patch) | |
tree | 5a810f7c7a802ebdd4c697e683c7b80e7dbbdd3b | |
parent | 318f47dc80c58dee8c798afcc8c19a5dbb21eef7 (diff) | |
download | sqlalchemy-214ed6239eb187c32e37bb7e3e3ac76555e266aa.tar.gz |
- pyodbc can do *some* unicode with sybase, python-sybase not at all.
Since python-sybase source code seems to be all from 2001 with no updates,
making pyodbc the default driver.
-rw-r--r-- | doc/build/dbengine.rst | 4 | ||||
-rw-r--r-- | lib/sqlalchemy/dialects/sybase/__init__.py | 2 | ||||
-rw-r--r-- | lib/sqlalchemy/dialects/sybase/base.py | 27 | ||||
-rw-r--r-- | lib/sqlalchemy/dialects/sybase/pyodbc.py | 17 | ||||
-rw-r--r-- | lib/sqlalchemy/dialects/sybase/pysybase.py | 6 | ||||
-rw-r--r-- | lib/sqlalchemy/engine/default.py | 2 |
6 files changed, 49 insertions, 9 deletions
diff --git a/doc/build/dbengine.rst b/doc/build/dbengine.rst index 261c54c10..694b09713 100644 --- a/doc/build/dbengine.rst +++ b/doc/build/dbengine.rst @@ -118,8 +118,8 @@ sqlite3_ ``sqlite+pysqlite``\* yes yes **Sybase ASE** ------------------------------------------------------------------------------------------------------------------------------- mxodbc_ ``sybase+mxodbc`` development development no yes yes -pyodbc_ ``sybase+pyodbc`` partial development no unknown unknown -python-sybase_ ``sybase+pysybase``\* partial development no yes yes +pyodbc_ ``sybase+pyodbc``\* partial development no unknown unknown +python-sybase_ ``sybase+pysybase`` partial development no yes yes ========================= =========================== =========== =========== =========== ================= ============ .. _psycopg2: http://www.initd.org/ diff --git a/lib/sqlalchemy/dialects/sybase/__init__.py b/lib/sqlalchemy/dialects/sybase/__init__.py index 4d9b07007..400bb2976 100644 --- a/lib/sqlalchemy/dialects/sybase/__init__.py +++ b/lib/sqlalchemy/dialects/sybase/__init__.py @@ -8,7 +8,7 @@ from base import CHAR, VARCHAR, TIME, NCHAR, NVARCHAR,\ IMAGE,BIT,MONEY,SMALLMONEY,TINYINT # default dialect -base.dialect = pysybase.dialect +base.dialect = pyodbc.dialect __all__ = ( 'CHAR', 'VARCHAR', 'TIME', 'NCHAR', 'NVARCHAR', diff --git a/lib/sqlalchemy/dialects/sybase/base.py b/lib/sqlalchemy/dialects/sybase/base.py index c440015d0..c0f0879fc 100644 --- a/lib/sqlalchemy/dialects/sybase/base.py +++ b/lib/sqlalchemy/dialects/sybase/base.py @@ -23,7 +23,8 @@ from sqlalchemy import util, sql, exc from sqlalchemy.types import CHAR, VARCHAR, TIME, NCHAR, NVARCHAR,\ TEXT,DATE,DATETIME, FLOAT, NUMERIC,\ BIGINT,INT, INTEGER, SMALLINT, BINARY,\ - VARBINARY, DECIMAL, TIMESTAMP, Unicode + VARBINARY, DECIMAL, TIMESTAMP, Unicode,\ + UnicodeText RESERVED_WORDS = set([ "add", "all", "alter", "and", @@ -84,14 +85,24 @@ RESERVED_WORDS = set([ "within", "work", "writetext", ]) - -class UNICHAR(sqltypes.Unicode): +class _SybaseUnitypeMixin(object): + """these types appear to return a buffer object.""" + + def result_processor(self, dialect, coltype): + def process(value): + if value is not None: + return str(value) #.decode("ucs-2") + else: + return None + return process + +class UNICHAR(_SybaseUnitypeMixin, sqltypes.Unicode): __visit_name__ = 'UNICHAR' -class UNIVARCHAR(sqltypes.Unicode): +class UNIVARCHAR(_SybaseUnitypeMixin, sqltypes.Unicode): __visit_name__ = 'UNIVARCHAR' -class UNITEXT(sqltypes.UnicodeText): +class UNITEXT(_SybaseUnitypeMixin, sqltypes.UnicodeText): __visit_name__ = 'UNITEXT' class TINYINT(sqltypes.Integer): @@ -120,9 +131,15 @@ class SybaseTypeCompiler(compiler.GenericTypeCompiler): def visit_boolean(self, type_): return self.visit_BIT(type_) + def visit_unicode(self, type_): + return self.visit_NVARCHAR(type_) + def visit_UNICHAR(self, type_): return "UNICHAR(%d)" % type_.length + def visit_UNIVARCHAR(self, type_): + return "UNIVARCHAR(%d)" % type_.length + def visit_UNITEXT(self, type_): return "UNITEXT" diff --git a/lib/sqlalchemy/dialects/sybase/pyodbc.py b/lib/sqlalchemy/dialects/sybase/pyodbc.py index 1bfdb6151..1bb09251c 100644 --- a/lib/sqlalchemy/dialects/sybase/pyodbc.py +++ b/lib/sqlalchemy/dialects/sybase/pyodbc.py @@ -8,7 +8,24 @@ Connect strings are of the form:: sybase+pyodbc://<username>:<password>@<dsn>/ sybase+pyodbc://<username>:<password>@<host>/<database> +Unicode Support +--------------- +The pyodbc driver currently supports usage of these Sybase types with +Unicode or multibyte strings:: + + CHAR + NCHAR + NVARCHAR + TEXT + VARCHAR + +Currently *not* supported are:: + + UNICHAR + UNITEXT + UNIVARCHAR + """ from sqlalchemy.dialects.sybase.base import SybaseDialect, SybaseExecutionContext diff --git a/lib/sqlalchemy/dialects/sybase/pysybase.py b/lib/sqlalchemy/dialects/sybase/pysybase.py index 200ce11a2..8944465ee 100644 --- a/lib/sqlalchemy/dialects/sybase/pysybase.py +++ b/lib/sqlalchemy/dialects/sybase/pysybase.py @@ -13,6 +13,12 @@ Connect strings are of the form:: sybase+pysybase://<username>:<password>@<dsn>/[database name] +Unicode Support +--------------- + +The python-sybase driver does not appear to support non-ASCII strings of any +kind at this time. + """ from sqlalchemy.dialects.sybase.base import SybaseDialect, \ diff --git a/lib/sqlalchemy/engine/default.py b/lib/sqlalchemy/engine/default.py index 2ef8fd104..720edf66c 100644 --- a/lib/sqlalchemy/engine/default.py +++ b/lib/sqlalchemy/engine/default.py @@ -184,7 +184,7 @@ class DefaultDialect(base.Dialect): # detect if there's an NVARCHAR type with different behavior available unicode_for_unicode = check_unicode(sqltypes.Unicode(60)) - + if unicode_for_unicode and not unicode_for_varchar: return "conditional" else: |