]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- [bug] Fixed bug in C extensions whereby
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 14 Mar 2012 03:38:30 +0000 (20:38 -0700)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 14 Mar 2012 03:38:30 +0000 (20:38 -0700)
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]

CHANGES
lib/sqlalchemy/cextension/processors.c
test/sql/test_types.py

diff --git a/CHANGES b/CHANGES
index 91262ea2660edd83621fc99ec0e292d57fdc11b4..17998bd11dd2a8984755d02f58fff89d017bb1a7 100644 (file)
--- 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
index b539f684306c165d55fef748637d90f8dcd152cd..427db5d8ea0e088a135408e1101fc81583730480 100644 (file)
@@ -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
index 793d5cb1259f6f8a8858d0502b080bad7c685a7b..f261c4ec8e414408aa46a283ea185ad9eb73d812 100644 (file)
@@ -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.