mirror of
https://github.com/psycopg/psycopg2.git
synced 2025-04-07 18:14:13 +03:00
Fix Decimal('Infinity')
adaptation
Closes https://github.com/psycopg/psycopg2/issues/1724
This commit is contained in:
parent
eaeeb76944
commit
4dbc04fd82
|
@ -47,11 +47,24 @@ pdecimal_getquoted(pdecimalObject *self, PyObject *args)
|
|||
}
|
||||
goto output;
|
||||
}
|
||||
else if (check) {
|
||||
|
||||
check = PyObject_CallMethod(self->wrapped, "is_nan", NULL);
|
||||
if (check == Py_True) {
|
||||
res = Bytes_FromString("'NaN'::numeric");
|
||||
goto end;
|
||||
}
|
||||
|
||||
/* If the decimal is not finite and not NaN, it must be infinity,
|
||||
* so all that is left is to check if it is positive or negative. */
|
||||
check = PyObject_CallMethod(self->wrapped, "is_signed", NULL);
|
||||
if (check == Py_True) {
|
||||
res = Bytes_FromString("'-Infinity'::numeric");
|
||||
goto end;
|
||||
} else {
|
||||
res = Bytes_FromString("'Infinity'::numeric");
|
||||
goto end;
|
||||
}
|
||||
|
||||
/* is_finite() was introduced 2.5.1 < somewhere <= 2.5.4.
|
||||
* We assume we are here because we didn't find the method. */
|
||||
PyErr_Clear();
|
||||
|
|
|
@ -75,11 +75,11 @@ class TypesBasicTests(ConnectingTestCase):
|
|||
self.failUnless(type(s) == decimal.Decimal,
|
||||
"wrong decimal conversion: " + repr(s))
|
||||
s = self.execute("SELECT %s AS foo", (decimal.Decimal("infinity"),))
|
||||
self.failUnless(str(s) == "NaN", "wrong decimal quoting: " + str(s))
|
||||
self.failUnless(str(s) == "Infinity", "wrong decimal quoting: " + str(s))
|
||||
self.failUnless(type(s) == decimal.Decimal,
|
||||
"wrong decimal conversion: " + repr(s))
|
||||
s = self.execute("SELECT %s AS foo", (decimal.Decimal("-infinity"),))
|
||||
self.failUnless(str(s) == "NaN", "wrong decimal quoting: " + str(s))
|
||||
self.failUnless(str(s) == "-Infinity", "wrong decimal quoting: " + str(s))
|
||||
self.failUnless(type(s) == decimal.Decimal,
|
||||
"wrong decimal conversion: " + repr(s))
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user