diff options
author | Jason Kirtland <jek@discorporate.us> | 2007-08-01 20:07:07 +0000 |
---|---|---|
committer | Jason Kirtland <jek@discorporate.us> | 2007-08-01 20:07:07 +0000 |
commit | 6b7f670c4ccb6a2c45a6da459ed29b07784498b0 (patch) | |
tree | a36cfc6ec9bfe1ee8b3debb4fcce436159e622e3 | |
parent | 963087faf48b42e2885e9132c1be1c1f1b4d18ef (diff) | |
download | sqlalchemy-6b7f670c4ccb6a2c45a6da459ed29b07784498b0.tar.gz |
Stopgap for post- #646 and r3030, wedge in 0.3 Decimals-are-floats behavior for vanilla 2.3 Python.
-rw-r--r-- | lib/sqlalchemy/databases/mysql.py | 3 | ||||
-rw-r--r-- | lib/sqlalchemy/databases/postgres.py | 5 | ||||
-rw-r--r-- | lib/sqlalchemy/types.py | 2 | ||||
-rw-r--r-- | lib/sqlalchemy/util.py | 16 |
4 files changed, 20 insertions, 6 deletions
diff --git a/lib/sqlalchemy/databases/mysql.py b/lib/sqlalchemy/databases/mysql.py index 331b672bd..81a17cbe7 100644 --- a/lib/sqlalchemy/databases/mysql.py +++ b/lib/sqlalchemy/databases/mysql.py @@ -6,7 +6,6 @@ import re, datetime, inspect, warnings, weakref, operator from array import array as _array -from decimal import Decimal from sqlalchemy import sql, schema, ansisql from sqlalchemy.engine import default @@ -166,7 +165,7 @@ class MSNumeric(sqltypes.Numeric, _NumericType): return value def convert_result_value(self, value, dialect): - if not self.asdecimal and isinstance(value, Decimal): + if not self.asdecimal and isinstance(value, util.decimal_type): return float(value) else: return value diff --git a/lib/sqlalchemy/databases/postgres.py b/lib/sqlalchemy/databases/postgres.py index a40ed9bdf..b9b2f15aa 100644 --- a/lib/sqlalchemy/databases/postgres.py +++ b/lib/sqlalchemy/databases/postgres.py @@ -6,10 +6,9 @@ import re, random, warnings, operator -from sqlalchemy import sql, schema, ansisql, exceptions +from sqlalchemy import sql, schema, ansisql, exceptions, util from sqlalchemy.engine import base, default import sqlalchemy.types as sqltypes -from decimal import Decimal try: import mx.DateTime.DateTime as mxDateTime @@ -32,7 +31,7 @@ class PGNumeric(sqltypes.Numeric): return value def convert_result_value(self, value, dialect): - if not self.asdecimal and isinstance(value, Decimal): + if not self.asdecimal and isinstance(value, util.decimal_type): return float(value) else: return value diff --git a/lib/sqlalchemy/types.py b/lib/sqlalchemy/types.py index ec1459852..56bd5a777 100644 --- a/lib/sqlalchemy/types.py +++ b/lib/sqlalchemy/types.py @@ -13,13 +13,13 @@ __all__ = [ 'TypeEngine', 'TypeDecorator', 'NullTypeEngine', import inspect import datetime as dt -from decimal import Decimal try: import cPickle as pickle except: import pickle from sqlalchemy import exceptions +from sqlalchemy.util import Decimal class AbstractType(object): def __init__(self, *args, **kwargs): diff --git a/lib/sqlalchemy/util.py b/lib/sqlalchemy/util.py index 6cb65e395..7391d86fd 100644 --- a/lib/sqlalchemy/util.py +++ b/lib/sqlalchemy/util.py @@ -32,6 +32,22 @@ except: i -= 1 raise StopIteration() +try: + # Try the standard decimal for > 2.3 or the compatibility module + # for 2.3, if installed. + from decimal import Decimal + decimal_type = Decimal +except ImportError: + def Decimal(arg): + if Decimal.warn: + warnings.warn(RuntimeWarning( + "True Decimal types not available on this Python, " + "falling back to floats.")) + Decimal.warn = False + return float(arg) + Decimal.warn = True + decimal_type = float + if sys.version_info >= (2, 5): class PopulateDict(dict): """a dict which populates missing values via a creation function. |