summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/dialects
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2010-12-11 17:44:46 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2010-12-11 17:44:46 -0500
commitc691b4cbdf7424964f49ac2fd05057514e5856a3 (patch)
treea4d62e1d5c0e63c90fd1b5ce125928d7a86852c6 /lib/sqlalchemy/dialects
parentb88c54f95be3e3bc2e0923181d56862fa3fda9fa (diff)
downloadsqlalchemy-c691b4cbdf7424964f49ac2fd05057514e5856a3.tar.gz
- support for cdecimal
- add --with-cdecimal flag to tests, monkeypatches cdecimal in - fix mssql/pyodbc.py to not use private '_int' accessor in decimal conversion routines - pyodbc version 2.1.8 is needed for cdecimal in any case as previous versions also called '_int', 2.1.8 adds the same string logic as our own dialect, so that logic is skipped for modern pyodbc version - make the imports for "Decimal" consistent across the whole lib. not sure yet how we should be importing "Decimal" or what the best way forward is that would allow a clean user-invoked swap of cdecimal; for now, added docs suggesting a global monkeypatch - the two decimal libs are not compatible with each other so any chance of mixing produces serious issues. adding adapters to DBAPIs tedious and adds in-python overhead. suggestions welcome on how we should be doing Decimal/cdecimal.
Diffstat (limited to 'lib/sqlalchemy/dialects')
-rw-r--r--lib/sqlalchemy/dialects/mssql/pymssql.py1
-rw-r--r--lib/sqlalchemy/dialects/mssql/pyodbc.py27
-rw-r--r--lib/sqlalchemy/dialects/oracle/cx_oracle.py12
-rw-r--r--lib/sqlalchemy/dialects/postgresql/pg8000.py3
-rw-r--r--lib/sqlalchemy/dialects/postgresql/psycopg2.py2
-rw-r--r--lib/sqlalchemy/dialects/postgresql/pypostgresql.py1
-rw-r--r--lib/sqlalchemy/dialects/sybase/pyodbc.py2
7 files changed, 28 insertions, 20 deletions
diff --git a/lib/sqlalchemy/dialects/mssql/pymssql.py b/lib/sqlalchemy/dialects/mssql/pymssql.py
index c5f471942..1368f6414 100644
--- a/lib/sqlalchemy/dialects/mssql/pymssql.py
+++ b/lib/sqlalchemy/dialects/mssql/pymssql.py
@@ -35,7 +35,6 @@ Please consult the pymssql documentation for further information.
from sqlalchemy.dialects.mssql.base import MSDialect
from sqlalchemy import types as sqltypes, util, processors
import re
-import decimal
class _MSNumeric_pymssql(sqltypes.Numeric):
def result_processor(self, dialect, type_):
diff --git a/lib/sqlalchemy/dialects/mssql/pyodbc.py b/lib/sqlalchemy/dialects/mssql/pyodbc.py
index 5bba24514..93a516706 100644
--- a/lib/sqlalchemy/dialects/mssql/pyodbc.py
+++ b/lib/sqlalchemy/dialects/mssql/pyodbc.py
@@ -88,7 +88,12 @@ class _MSNumeric_pyodbc(sqltypes.Numeric):
"""
def bind_processor(self, dialect):
- super_process = super(_MSNumeric_pyodbc, self).bind_processor(dialect)
+
+ super_process = super(_MSNumeric_pyodbc, self).\
+ bind_processor(dialect)
+
+ if not dialect._need_decimal_fix:
+ return super_process
def process(value):
if self.asdecimal and \
@@ -106,31 +111,35 @@ class _MSNumeric_pyodbc(sqltypes.Numeric):
return value
return process
+ # these routines needed for older versions of pyodbc.
+ # as of 2.1.8 this logic is integrated.
+
def _small_dec_to_string(self, value):
return "%s0.%s%s" % (
(value < 0 and '-' or ''),
'0' * (abs(value.adjusted()) - 1),
- "".join([str(nint) for nint in value._int]))
+ "".join([str(nint) for nint in value.as_tuple()[1]]))
def _large_dec_to_string(self, value):
+ _int = value.as_tuple()[1]
if 'E' in str(value):
result = "%s%s%s" % (
(value < 0 and '-' or ''),
- "".join([str(s) for s in value._int]),
- "0" * (value.adjusted() - (len(value._int)-1)))
+ "".join([str(s) for s in _int]),
+ "0" * (value.adjusted() - (len(_int)-1)))
else:
- if (len(value._int) - 1) > value.adjusted():
+ if (len(_int) - 1) > value.adjusted():
result = "%s%s.%s" % (
(value < 0 and '-' or ''),
"".join(
- [str(s) for s in value._int][0:value.adjusted() + 1]),
+ [str(s) for s in _int][0:value.adjusted() + 1]),
"".join(
- [str(s) for s in value._int][value.adjusted() + 1:]))
+ [str(s) for s in _int][value.adjusted() + 1:]))
else:
result = "%s%s" % (
(value < 0 and '-' or ''),
"".join(
- [str(s) for s in value._int][0:value.adjusted() + 1]))
+ [str(s) for s in _int][0:value.adjusted() + 1]))
return result
@@ -200,5 +209,7 @@ class MSDialect_pyodbc(PyODBCConnector, MSDialect):
self.description_encoding = description_encoding
self.use_scope_identity = self.dbapi and \
hasattr(self.dbapi.Cursor, 'nextset')
+ self._need_decimal_fix = self.dbapi and \
+ tuple(self.dbapi.version.split(".")) < (2, 1, 8)
dialect = MSDialect_pyodbc
diff --git a/lib/sqlalchemy/dialects/oracle/cx_oracle.py b/lib/sqlalchemy/dialects/oracle/cx_oracle.py
index 87a84e514..b7d663138 100644
--- a/lib/sqlalchemy/dialects/oracle/cx_oracle.py
+++ b/lib/sqlalchemy/dialects/oracle/cx_oracle.py
@@ -121,7 +121,7 @@ from sqlalchemy.engine import base
from sqlalchemy import types as sqltypes, util, exc, processors
from datetime import datetime
import random
-from decimal import Decimal
+from sqlalchemy.util.compat import decimal
import re
class _OracleNumeric(sqltypes.Numeric):
@@ -148,10 +148,10 @@ class _OracleNumeric(sqltypes.Numeric):
def to_decimal(value):
if value is None:
return None
- elif isinstance(value, Decimal):
+ elif isinstance(value, decimal.Decimal):
return value
else:
- return Decimal(fstring % value)
+ return decimal.Decimal(fstring % value)
return to_decimal
else:
if self.precision is None and self.scale is None:
@@ -569,15 +569,15 @@ class OracleDialect_cx_oracle(OracleDialect):
self._detect_decimal = \
lambda value: _detect_decimal(value.replace(char, '.'))
self._to_decimal = \
- lambda value: Decimal(value.replace(char, '.'))
+ lambda value: decimal.Decimal(value.replace(char, '.'))
def _detect_decimal(self, value):
if "." in value:
- return Decimal(value)
+ return decimal.Decimal(value)
else:
return int(value)
- _to_decimal = Decimal
+ _to_decimal = decimal.Decimal
def on_connect(self):
if self.cx_oracle_ver < (5,):
diff --git a/lib/sqlalchemy/dialects/postgresql/pg8000.py b/lib/sqlalchemy/dialects/postgresql/pg8000.py
index 7b1d8e6a7..3afa06eab 100644
--- a/lib/sqlalchemy/dialects/postgresql/pg8000.py
+++ b/lib/sqlalchemy/dialects/postgresql/pg8000.py
@@ -21,10 +21,9 @@ Passing data from/to the Interval type is not supported as of
yet.
"""
-import decimal
-
from sqlalchemy.engine import default
from sqlalchemy import util, exc
+from sqlalchemy.util.compat import decimal
from sqlalchemy import processors
from sqlalchemy import types as sqltypes
from sqlalchemy.dialects.postgresql.base import PGDialect, \
diff --git a/lib/sqlalchemy/dialects/postgresql/psycopg2.py b/lib/sqlalchemy/dialects/postgresql/psycopg2.py
index 88e6ce670..b3f42c330 100644
--- a/lib/sqlalchemy/dialects/postgresql/psycopg2.py
+++ b/lib/sqlalchemy/dialects/postgresql/psycopg2.py
@@ -86,10 +86,10 @@ The following per-statement execution options are respected:
import random
import re
-import decimal
import logging
from sqlalchemy import util, exc
+from sqlalchemy.util.compat import decimal
from sqlalchemy import processors
from sqlalchemy.engine import base, default
from sqlalchemy.sql import expression
diff --git a/lib/sqlalchemy/dialects/postgresql/pypostgresql.py b/lib/sqlalchemy/dialects/postgresql/pypostgresql.py
index b8f7991d5..9abdffb6e 100644
--- a/lib/sqlalchemy/dialects/postgresql/pypostgresql.py
+++ b/lib/sqlalchemy/dialects/postgresql/pypostgresql.py
@@ -8,7 +8,6 @@ URLs are of the form ``postgresql+pypostgresql://user@password@host:port/dbname[
"""
from sqlalchemy.engine import default
-import decimal
from sqlalchemy import util
from sqlalchemy import types as sqltypes
from sqlalchemy.dialects.postgresql.base import PGDialect, PGExecutionContext
diff --git a/lib/sqlalchemy/dialects/sybase/pyodbc.py b/lib/sqlalchemy/dialects/sybase/pyodbc.py
index 1d955a7d9..68b16c051 100644
--- a/lib/sqlalchemy/dialects/sybase/pyodbc.py
+++ b/lib/sqlalchemy/dialects/sybase/pyodbc.py
@@ -31,8 +31,8 @@ Currently *not* supported are::
from sqlalchemy.dialects.sybase.base import SybaseDialect,\
SybaseExecutionContext
from sqlalchemy.connectors.pyodbc import PyODBCConnector
-import decimal
from sqlalchemy import types as sqltypes, util, processors
+from sqlalchemy.util.compat import decimal
class _SybNumeric_pyodbc(sqltypes.Numeric):
"""Turns Decimals with adjusted() < -6 into floats.