summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2012-03-13 20:38:30 -0700
committerMike Bayer <mike_mp@zzzcomputing.com>2012-03-13 20:38:30 -0700
commitbf57355feeb6f04d33ad778709f2fb39ad699aee (patch)
tree69e1c51d7a912fa5286e6efae33a6ff498aea73f
parent4d2c1e2f17c702fd40af91532a36ec1b12db08fd (diff)
downloadsqlalchemy-bf57355feeb6f04d33ad778709f2fb39ad699aee.tar.gz
- [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]
-rw-r--r--CHANGES8
-rw-r--r--lib/sqlalchemy/cextension/processors.c25
-rw-r--r--test/sql/test_types.py18
3 files changed, 35 insertions, 16 deletions
diff --git a/CHANGES b/CHANGES
index 91262ea26..17998bd11 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 b539f6843..427db5d8e 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 793d5cb12..f261c4ec8 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.