]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- pyodbc can do *some* unicode with sybase, python-sybase not at all.
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 17 Mar 2010 20:01:29 +0000 (16:01 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 17 Mar 2010 20:01:29 +0000 (16:01 -0400)
Since python-sybase source code seems to be all from 2001 with no updates,
making pyodbc the default driver.

doc/build/dbengine.rst
lib/sqlalchemy/dialects/sybase/__init__.py
lib/sqlalchemy/dialects/sybase/base.py
lib/sqlalchemy/dialects/sybase/pyodbc.py
lib/sqlalchemy/dialects/sybase/pysybase.py
lib/sqlalchemy/engine/default.py

index 261c54c10e8ca2d9c53e78ce5108f5fd0deaed6b..694b097137f0f26dec59bd513253622777d6fdd9 100644 (file)
@@ -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/
index 4d9b07007a65faf082f6fcc2e1549db87e6d2a9e..400bb29765d16415908bf1b602d164a546fd0884 100644 (file)
@@ -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',
index c440015d0f056aad82e4827078af0959e5dff856..c0f0879fcd5c552c8007f1cf1e88b0cdec3b06d7 100644 (file)
@@ -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"
 
index 1bfdb6151a4f043f285a4ad216046f41d2bbc877..1bb09251cca5a48ad9bd8d785f33d0361cd1ff38 100644 (file)
@@ -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
index 200ce11a2419df1b252bcfb47fea71d2ec026c86..8944465eecbbcd83912661fb114f31d045903f05 100644 (file)
@@ -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, \
index 2ef8fd104ca03d17f340e2440d14009fbc9440c3..720edf66c87e2d0e25c2d946466844dbda5cb22a 100644 (file)
@@ -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: