]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
turning the decimals to floats allows the E notation to work with sybase+pyodbc for...
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 18 Mar 2010 16:05:20 +0000 (12:05 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 18 Mar 2010 16:05:20 +0000 (12:05 -0400)
lib/sqlalchemy/dialects/mssql/base.py
lib/sqlalchemy/dialects/sybase/base.py
lib/sqlalchemy/dialects/sybase/pyodbc.py
test/sql/test_types.py

index 070650d97f4bf2541813e06eb34402265cef66af..6425291c8a29d838a2f99133a140e1b5b7edeeae 100644 (file)
@@ -283,7 +283,8 @@ class _MSNumeric(sqltypes.Numeric):
             # TODO: this seems exceedingly complex. 
             # need to know exactly what tests cover this, so far
             # test_types.NumericTest.test_enotation_decimal
-            
+            # see the _SybNumeric type in sybase/pyodbc for possible
+            # generalized solution on pyodbc
             if isinstance(value, decimal.Decimal):
                 if value.adjusted() < 0:
                     result = "%s0.%s%s" % (
index e182cc9e7c5d94f7fc5e18bfb5f3992d7ebc0ad9..5814f70da3c1365400570f52b661de5338c9b1b2 100644 (file)
@@ -85,6 +85,7 @@ RESERVED_WORDS = set([
     "within", "work", "writetext",
     ])
 
+        
 class _SybaseUnitypeMixin(object):
     """these types appear to return a buffer object."""
     
@@ -161,9 +162,6 @@ class SybaseTypeCompiler(compiler.GenericTypeCompiler):
     def visit_UNIQUEIDENTIFIER(self, type_):
         return "UNIQUEIDENTIFIER"
         
-colspecs = {
-}
-
 ischema_names = {
     'integer' : INTEGER,
     'unsigned int' : INTEGER, # TODO: unsigned flags
@@ -359,7 +357,7 @@ class SybaseDialect(default.DefaultDialect):
     supports_unicode_binds = False
     postfetch_lastrowid = True
 
-    colspecs = colspecs
+    colspecs = {}
     ischema_names = ischema_names
 
     type_compiler = SybaseTypeCompiler
index 1bb09251cca5a48ad9bd8d785f33d0361cd1ff38..61cf333da9486df654424769a25ef0181396204d 100644 (file)
@@ -31,6 +31,26 @@ Currently *not* supported are::
 from sqlalchemy.dialects.sybase.base import SybaseDialect, SybaseExecutionContext
 from sqlalchemy.connectors.pyodbc import PyODBCConnector
 
+import decimal
+from sqlalchemy import processors, types as sqltypes
+
+# TODO: should this be part of pyodbc connectors ??? applies to MSSQL too ?
+class _SybNumeric(sqltypes.Numeric):
+    def bind_processor(self, dialect):
+        super_process = super(_SybNumeric, self).bind_processor(dialect)
+        
+        def process(value):
+            if self.asdecimal and \
+                    isinstance(value, decimal.Decimal) and \
+                    value.adjusted() < -6:
+                return processors.to_float(value)
+            elif super_process:
+                return super_process(value)
+            else:
+                return value
+        return process
+
+
 class SybaseExecutionContext_pyodbc(SybaseExecutionContext):
     def set_ddl_autocommit(self, connection, value):
         if value:
@@ -39,7 +59,13 @@ class SybaseExecutionContext_pyodbc(SybaseExecutionContext):
             connection.autocommit = False
 
 
+
 class SybaseDialect_pyodbc(PyODBCConnector, SybaseDialect):
     execution_ctx_cls = SybaseExecutionContext_pyodbc
 
+    colspecs = {
+        sqltypes.Numeric:_SybNumeric,
+        sqltypes.Float:sqltypes.Float,
+    }
+
 dialect = SybaseDialect_pyodbc
index 507ca5a091b6447b7080fa20d59f0de1a9f84aa0..56eca39ac559116f86af187d98aa573d64e81f6a 100644 (file)
@@ -1155,7 +1155,6 @@ class NumericTest(TestBase, AssertsExecutionResults):
         finally:
             t.drop(testing.db)
 
-    @testing.fails_on('sybase', "Driver doesn't appear to handle E notation, won't accept strings")
     def test_enotation_decimal(self):
         """test exceedingly small decimals.