# 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" % (
"within", "work", "writetext",
])
+
class _SybaseUnitypeMixin(object):
"""these types appear to return a buffer object."""
def visit_UNIQUEIDENTIFIER(self, type_):
return "UNIQUEIDENTIFIER"
-colspecs = {
-}
-
ischema_names = {
'integer' : INTEGER,
'unsigned int' : INTEGER, # TODO: unsigned flags
supports_unicode_binds = False
postfetch_lastrowid = True
- colspecs = colspecs
+ colspecs = {}
ischema_names = ischema_names
type_compiler = SybaseTypeCompiler
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:
connection.autocommit = False
+
class SybaseDialect_pyodbc(PyODBCConnector, SybaseDialect):
execution_ctx_cls = SybaseExecutionContext_pyodbc
+ colspecs = {
+ sqltypes.Numeric:_SybNumeric,
+ sqltypes.Float:sqltypes.Float,
+ }
+
dialect = SybaseDialect_pyodbc
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.