summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sqlalchemy')
-rw-r--r--lib/sqlalchemy/databases/mysql.py3
-rw-r--r--lib/sqlalchemy/databases/postgres.py5
-rw-r--r--lib/sqlalchemy/types.py2
-rw-r--r--lib/sqlalchemy/util.py16
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.