From: Mike Bayer Date: Wed, 14 Mar 2012 03:38:30 +0000 (-0700) Subject: - [bug] Fixed bug in C extensions whereby X-Git-Tag: rel_0_7_6~15 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bf57355feeb6f04d33ad778709f2fb39ad699aee;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - [bug] Fixed bug in C extensions whereby string format would not be applied to a Numeric value returned as integer; this affected primarily SQLite which does not maintain numeric scale settings. [ticket:2432] --- diff --git a/CHANGES b/CHANGES index 91262ea266..17998bd11d 100644 --- a/CHANGES +++ b/CHANGES @@ -181,6 +181,14 @@ CHANGES commit or rollback transaction with errors on engine.begin(). +- sqlite + - [bug] Fixed bug in C extensions whereby + string format would not be applied to a + Numeric value returned as integer; this + affected primarily SQLite which does + not maintain numeric scale settings. + [ticket:2432] + - mssql - [feature] Added support for MSSQL INSERT, UPDATE, and DELETE table hints, using diff --git a/lib/sqlalchemy/cextension/processors.c b/lib/sqlalchemy/cextension/processors.c index b539f68430..427db5d8ea 100644 --- a/lib/sqlalchemy/cextension/processors.c +++ b/lib/sqlalchemy/cextension/processors.c @@ -342,23 +342,18 @@ DecimalResultProcessor_process(DecimalResultProcessor *self, PyObject *value) if (value == Py_None) Py_RETURN_NONE; - if (PyFloat_CheckExact(value)) { - /* Decimal does not accept float values directly */ - args = PyTuple_Pack(1, value); - if (args == NULL) - return NULL; + args = PyTuple_Pack(1, value); + if (args == NULL) + return NULL; - str = PyString_Format(self->format, args); - Py_DECREF(args); - if (str == NULL) - return NULL; + str = PyString_Format(self->format, args); + Py_DECREF(args); + if (str == NULL) + return NULL; - result = PyObject_CallFunctionObjArgs(self->type, str, NULL); - Py_DECREF(str); - return result; - } else { - return PyObject_CallFunctionObjArgs(self->type, value, NULL); - } + result = PyObject_CallFunctionObjArgs(self->type, str, NULL); + Py_DECREF(str); + return result; } static void diff --git a/test/sql/test_types.py b/test/sql/test_types.py index 793d5cb125..f261c4ec8e 100644 --- a/test/sql/test_types.py +++ b/test/sql/test_types.py @@ -1547,7 +1547,7 @@ class NumericTest(fixtures.TestBase): metadata.drop_all() @testing.emits_warning(r".*does \*not\* support Decimal objects natively") - def _do_test(self, type_, input_, output, filter_ = None): + def _do_test(self, type_, input_, output, filter_=None, check_scale=False): t = Table('t', metadata, Column('x', type_)) t.create() t.insert().execute([{'x':x} for x in input_]) @@ -1560,6 +1560,11 @@ class NumericTest(fixtures.TestBase): #print result #print output eq_(result, output) + if check_scale: + eq_( + [str(x) for x in result], + [str(x) for x in output], + ) def test_numeric_as_decimal(self): self._do_test( @@ -1676,6 +1681,17 @@ class NumericTest(fixtures.TestBase): numbers ) + def test_numeric_no_decimal(self): + numbers = set([ + decimal.Decimal("1.000") + ]) + self._do_test( + Numeric(precision=5, scale=3), + numbers, + numbers, + check_scale=True + ) + class NumericRawSQLTest(fixtures.TestBase): """Test what DBAPIs and dialects return without any typing information supplied at the SQLA level.