Skip to content

Commit

Permalink
Ensure that binding a boolean value outside of PL/SQL simply binds th…
Browse files Browse the repository at this point in the history
…e integer

0 or 1 (#181).
  • Loading branch information
anthony-tuininga committed May 20, 2018
1 parent 67d374b commit 8cc7b89
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/cxoConnection.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/cxoModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/cxoObject.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/cxoTransform.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
3 changes: 2 additions & 1 deletion src/cxoVar.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions src/cxoVarType.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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.",
Expand Down
11 changes: 11 additions & 0 deletions test/Cursor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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") ])

0 comments on commit 8cc7b89

Please sign in to comment.