diff --git a/src/cxoConnection.c b/src/cxoConnection.c index 08ff2cbe..ea3804ea 100644 --- a/src/cxoConnection.c +++ b/src/cxoConnection.c @@ -361,7 +361,7 @@ static int cxoConnectionParams_processShardingKeyValue( { cxoTransformNum transformNum; - transformNum = cxoTransform_getNumFromValue(value); + transformNum = cxoTransform_getNumFromValue(value, 0); if (cxoTransform_fromPython(transformNum, value, &column->value, buffer, params->encoding, params->nencoding, NULL, 0) < 0) return -1; diff --git a/src/cxoModule.h b/src/cxoModule.h index 381c5c0f..b6a0124b 100644 --- a/src/cxoModule.h +++ b/src/cxoModule.h @@ -445,7 +445,7 @@ int cxoTransform_fromPython(cxoTransformNum transformNum, PyObject *pyValue, const char *nencoding, cxoVar *var, uint32_t arrayPos); cxoTransformNum cxoTransform_getNumFromDataTypeInfo(dpiDataTypeInfo *info); cxoTransformNum cxoTransform_getNumFromType(PyTypeObject *type); -cxoTransformNum cxoTransform_getNumFromValue(PyObject *value); +cxoTransformNum cxoTransform_getNumFromValue(PyObject *value, int plsql); void cxoTransform_getTypeInfo(cxoTransformNum transformNum, dpiOracleTypeNum *oracleTypeNum, dpiNativeTypeNum *nativeTypeNum); int cxoTransform_init(void); @@ -464,7 +464,7 @@ int cxoUtils_initializeDPI(void); cxoVarType *cxoVarType_fromDataTypeInfo(dpiDataTypeInfo *info); cxoVarType *cxoVarType_fromPythonType(PyTypeObject *type); cxoVarType *cxoVarType_fromPythonValue(PyObject *value, int *isArray, - Py_ssize_t *size, Py_ssize_t *numElements); + Py_ssize_t *size, Py_ssize_t *numElements, int plsql); int cxoVar_bind(cxoVar *var, cxoCursor *cursor, PyObject *name, uint32_t pos); int cxoVar_check(PyObject *object); diff --git a/src/cxoObject.c b/src/cxoObject.c index 32cd90d9..dbad1b9e 100644 --- a/src/cxoObject.c +++ b/src/cxoObject.c @@ -173,7 +173,7 @@ static int cxoObject_convertFromPython(cxoObject *obj, PyObject *value, } // convert the different Python types - transformNum = cxoTransform_getNumFromValue(value); + transformNum = cxoTransform_getNumFromValue(value, 1); if (cxoTransform_fromPython(transformNum, value, &data->value, buffer, obj->objectType->connection->encodingInfo.encoding, obj->objectType->connection->encodingInfo.nencoding, NULL, 0) < 0) diff --git a/src/cxoTransform.c b/src/cxoTransform.c index cb152195..6cfcaf31 100644 --- a/src/cxoTransform.c +++ b/src/cxoTransform.c @@ -518,14 +518,14 @@ cxoTransformNum cxoTransform_getNumFromType(PyTypeObject *type) // cxoTransform_getNumFromValue() // Get the appropriate transformation to use for the specified Python object. //----------------------------------------------------------------------------- -cxoTransformNum cxoTransform_getNumFromValue(PyObject *value) +cxoTransformNum cxoTransform_getNumFromValue(PyObject *value, int plsql) { cxoLob *lob; if (value == Py_None) return CXO_TRANSFORM_NONE; if (PyBool_Check(value)) { - if (cxoClientVersionInfo.versionNum < 12) + if (cxoClientVersionInfo.versionNum < 12 || !plsql) return CXO_TRANSFORM_NATIVE_INT; return CXO_TRANSFORM_BOOLEAN; } diff --git a/src/cxoVar.c b/src/cxoVar.c index a834f187..0640cee1 100644 --- a/src/cxoVar.c +++ b/src/cxoVar.c @@ -272,7 +272,8 @@ cxoVar *cxoVar_newByValue(cxoCursor *cursor, PyObject *value, } // default processing - varType = cxoVarType_fromPythonValue(value, &isArray, &size, &numElements); + varType = cxoVarType_fromPythonValue(value, + &isArray, &size, &numElements, cursor->stmtInfo.isPLSQL); if (!varType) return NULL; if (varType->transformNum == CXO_TRANSFORM_OBJECT) { diff --git a/src/cxoVarType.c b/src/cxoVarType.c index 9fc4fb44..355f17b4 100644 --- a/src/cxoVarType.c +++ b/src/cxoVarType.c @@ -243,7 +243,7 @@ static Py_ssize_t cxoVarType_calculateSize(PyObject *value, // does not have a corresponding variable type. //----------------------------------------------------------------------------- cxoVarType *cxoVarType_fromPythonValue(PyObject *value, int *isArray, - Py_ssize_t *size, Py_ssize_t *numElements) + Py_ssize_t *size, Py_ssize_t *numElements, int plsql) { cxoTransformNum transformNum, tempTransformNum; PyObject *elementValue; @@ -260,7 +260,7 @@ cxoVarType *cxoVarType_fromPythonValue(PyObject *value, int *isArray, transformNum = CXO_TRANSFORM_NONE; for (i = 0; i < PyList_GET_SIZE(value); i++) { elementValue = PyList_GET_ITEM(value, i); - tempTransformNum = cxoTransform_getNumFromValue(elementValue); + tempTransformNum = cxoTransform_getNumFromValue(elementValue, 1); if (tempTransformNum == CXO_TRANSFORM_UNSUPPORTED) { snprintf(message, sizeof(message), "element %u value is unsupported", (unsigned) i); @@ -288,7 +288,7 @@ cxoVarType *cxoVarType_fromPythonValue(PyObject *value, int *isArray, } // handle scalar values - transformNum = cxoTransform_getNumFromValue(value); + transformNum = cxoTransform_getNumFromValue(value, plsql); if (transformNum == CXO_TRANSFORM_UNSUPPORTED) { snprintf(message, sizeof(message), "Python value of type %s not supported.", diff --git a/test/Cursor.py b/test/Cursor.py index 5f1a09cb..ec713c0a 100644 --- a/test/Cursor.py +++ b/test/Cursor.py @@ -553,3 +553,14 @@ def testArrayVarNegative(self): "test cursor.arrayvar() with invalid parameters" self.assertRaises(TypeError, self.cursor.arrayvar, 5, 1) + def testBooleanWithoutPlsql(self): + "test binding boolean data without the use of PL/SQL" + self.cursor.execute("truncate table TestTempTable") + self.cursor.execute("insert into TestTempTable values (:1, :2)", + (False, "Value should be 0")) + self.cursor.execute("insert into TestTempTable values (:1, :2)", + (True, "Value should be 1")) + self.cursor.execute("select * from TestTempTable order by IntCol") + self.assertEqual(self.cursor.fetchall(), + [ (0, "Value should be 0"), (1, "Value should be 1") ]) +