From: Paul Johnston Date: Sun, 25 Nov 2007 23:34:39 +0000 (+0000) Subject: Fix: test_decimal on MSSQL - use a value that is accurately represented as a float... X-Git-Tag: rel_0_4_2~138 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=2c873f0ee45db04cb880de7c24b56564eb9605a4;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Fix: test_decimal on MSSQL - use a value that is accurately represented as a float, and make when asdecimal=False, convert Decimal to float --- diff --git a/lib/sqlalchemy/databases/mssql.py b/lib/sqlalchemy/databases/mssql.py index a1cefb0193..d060458d4e 100644 --- a/lib/sqlalchemy/databases/mssql.py +++ b/lib/sqlalchemy/databases/mssql.py @@ -43,12 +43,23 @@ from sqlalchemy import sql, schema, exceptions, util from sqlalchemy.sql import compiler, expression, operators as sqlops from sqlalchemy.engine import default, base from sqlalchemy import types as sqltypes +from sqlalchemy.util import Decimal as _python_Decimal MSSQL_RESERVED_WORDS = util.Set(['function']) class MSNumeric(sqltypes.Numeric): def result_processor(self, dialect): - return None + if self.asdecimal: + def process(value): + if value is not None: + return _python_Decimal(str(value)) + else: + return value + return process + else: + def process(value): + return float(value) + return process def bind_processor(self, dialect): def process(value): diff --git a/test/sql/testtypes.py b/test/sql/testtypes.py index 7a9add9471..8c247897f4 100644 --- a/test/sql/testtypes.py +++ b/test/sql/testtypes.py @@ -587,8 +587,8 @@ class NumericTest(AssertMixin): def test_decimal(self): from decimal import Decimal - numeric_table.insert().execute(numericcol=3.5, floatcol=5.6, ncasdec=12.4, fcasdec=15.78) - numeric_table.insert().execute(numericcol=Decimal("3.5"), floatcol=Decimal("5.6"), ncasdec=Decimal("12.4"), fcasdec=Decimal("15.78")) + numeric_table.insert().execute(numericcol=3.5, floatcol=5.6, ncasdec=12.4, fcasdec=15.75) + numeric_table.insert().execute(numericcol=Decimal("3.5"), floatcol=Decimal("5.6"), ncasdec=Decimal("12.4"), fcasdec=Decimal("15.75")) l = numeric_table.select().execute().fetchall() print l rounded = [ @@ -596,8 +596,8 @@ class NumericTest(AssertMixin): (l[1][0], l[1][1], round(l[1][2], 5), l[1][3], l[1][4]), ] assert rounded == [ - (1, 3.5, 5.6, Decimal("12.4"), Decimal("15.78")), - (2, 3.5, 5.6, Decimal("12.4"), Decimal("15.78")), + (1, 3.5, 5.6, Decimal("12.4"), Decimal("15.75")), + (2, 3.5, 5.6, Decimal("12.4"), Decimal("15.75")), ]