Corrected support for binding decimal values in object attribute values and
collection element values.
This commit is contained in:
parent
2e9c412d41
commit
18e06bf14a
2
odpi
2
odpi
|
@ -1 +1 @@
|
|||
Subproject commit 8f9790a04c81e14552fa104444a24aa4a9e488a3
|
||||
Subproject commit 422c3e8aec834eb361f23bea4d8556c861933302
|
23
src/Object.c
23
src/Object.c
|
@ -188,10 +188,12 @@ static PyObject *Object_Repr(udt_Object *self)
|
|||
static int Object_ConvertFromPython(udt_Object *obj, PyObject *value,
|
||||
dpiNativeTypeNum *nativeTypeNum, dpiData *data, udt_Buffer *buffer)
|
||||
{
|
||||
PyObject *textValue, *valueType;
|
||||
dpiTimestamp *timestamp;
|
||||
udt_Object *otherObj;
|
||||
dpiBytes *bytes;
|
||||
udt_LOB *lob;
|
||||
int status;
|
||||
|
||||
// None is treated as null
|
||||
if (value == Py_None) {
|
||||
|
@ -201,10 +203,23 @@ static int Object_ConvertFromPython(udt_Object *obj, PyObject *value,
|
|||
|
||||
// convert the different Python types
|
||||
data->isNull = 0;
|
||||
if (PyUnicode_Check(value) || PyBytes_Check(value)) {
|
||||
if (cxBuffer_FromObject(buffer, value,
|
||||
obj->objectType->connection->encodingInfo.encoding) < 0)
|
||||
return -1;
|
||||
valueType = (PyObject*) Py_TYPE(value);
|
||||
if (PyUnicode_Check(value) || PyBytes_Check(value) ||
|
||||
valueType == (PyObject*) g_DecimalType) {
|
||||
if (valueType == (PyObject*) g_DecimalType) {
|
||||
textValue = PyObject_Str(value);
|
||||
if (!textValue)
|
||||
return -1;
|
||||
status = cxBuffer_FromObject(buffer, textValue,
|
||||
obj->objectType->connection->encodingInfo.encoding);
|
||||
Py_DECREF(textValue);
|
||||
if (status < 0)
|
||||
return -1;
|
||||
} else {
|
||||
if (cxBuffer_FromObject(buffer, value,
|
||||
obj->objectType->connection->encodingInfo.encoding) < 0)
|
||||
return -1;
|
||||
}
|
||||
*nativeTypeNum = DPI_NATIVE_TYPE_BYTES;
|
||||
bytes = &data->value.asBytes;
|
||||
bytes->ptr = (char*) buffer->ptr;
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
|
||||
import cx_Oracle
|
||||
import datetime
|
||||
import decimal
|
||||
|
||||
class TestObjectVar(BaseTestCase):
|
||||
|
||||
|
@ -77,14 +78,14 @@ class TestObjectVar(BaseTestCase):
|
|||
obj.TIMESTAMPVALUE = None
|
||||
subTypeObj = self.connection.gettype("UDT_SUBOBJECT")
|
||||
subObj = subTypeObj.newobject()
|
||||
subObj.SUBNUMBERVALUE = 15
|
||||
subObj.SUBNUMBERVALUE = decimal.Decimal("18.25")
|
||||
subObj.SUBSTRINGVALUE = "Sub String"
|
||||
obj.SUBOBJECTVALUE = subObj
|
||||
result = self.cursor.callfunc("pkg_TestBindObject.GetStringRep", str,
|
||||
(obj,))
|
||||
self.assertEqual(result,
|
||||
"udt_Object(null, 'Test With Dates', null, null, null, " \
|
||||
"udt_SubObject(15, 'Sub String'), null)")
|
||||
"udt_SubObject(18.25, 'Sub String'), null)")
|
||||
|
||||
def testCopyObject(self):
|
||||
"test copying an object"
|
||||
|
|
Loading…
Reference in New Issue