diff --git a/Connection.c b/Connection.c index 7d8fe0e..95ca11c 100644 --- a/Connection.c +++ b/Connection.c @@ -264,11 +264,11 @@ static int Connection_GetConnection( environment->errorHandle); if (Environment_CheckForError(environment, status, "Connection_GetConnection(): set user name") < 0) { - StringBuffer_CLEAR(&buffer); + StringBuffer_Clear(&buffer); return -1; } } - StringBuffer_CLEAR(&buffer); + StringBuffer_Clear(&buffer); // set the password, if applicable if (StringBuffer_Fill(&buffer, self->password) < 0) @@ -280,11 +280,11 @@ static int Connection_GetConnection( environment->errorHandle); if (Environment_CheckForError(environment, status, "Connection_GetConnection(): set password") < 0) { - StringBuffer_CLEAR(&buffer); + StringBuffer_Clear(&buffer); return -1; } } - StringBuffer_CLEAR(&buffer); + StringBuffer_Clear(&buffer); // if no user name or password are set, using external credentials if (!pool && externalCredentials) @@ -300,11 +300,11 @@ static int Connection_GetConnection( environment->errorHandle); if (Environment_CheckForError(environment, status, "Connection_GetConnection(): set connection class") < 0) { - StringBuffer_CLEAR(&buffer); + StringBuffer_Clear(&buffer); return -1; } } - StringBuffer_CLEAR(&buffer); + StringBuffer_Clear(&buffer); // set the purity, if applicable if (purity != OCI_ATTR_PURITY_DEFAULT) { @@ -326,7 +326,7 @@ static int Connection_GetConnection( &self->handle, authInfo, (text*) buffer.ptr, buffer.size, NULL, 0, NULL, NULL, &found, mode); Py_END_ALLOW_THREADS - StringBuffer_CLEAR(&buffer); + StringBuffer_Clear(&buffer); if (Environment_CheckForError(environment, status, "Connection_GetConnection(): get connection") < 0) return -1; @@ -469,7 +469,7 @@ static int Connection_Connect( self->environment->errorHandle, (text*) buffer.ptr, buffer.size, OCI_DEFAULT); Py_END_ALLOW_THREADS - StringBuffer_CLEAR(&buffer); + StringBuffer_Clear(&buffer); if (Environment_CheckForError(self->environment, status, "Connection_Connect(): server attach") < 0) return -1; @@ -522,11 +522,11 @@ static int Connection_Connect( self->environment->errorHandle); if (Environment_CheckForError(self->environment, status, "Connection_Connect(): set user name") < 0) { - StringBuffer_CLEAR(&buffer); + StringBuffer_Clear(&buffer); return -1; } } - StringBuffer_CLEAR(&buffer); + StringBuffer_Clear(&buffer); // set password in session handle if (StringBuffer_Fill(&buffer, self->password) < 0) @@ -538,11 +538,11 @@ static int Connection_Connect( self->environment->errorHandle); if (Environment_CheckForError(self->environment, status, "Connection_Connect(): set password") < 0) { - StringBuffer_CLEAR(&buffer); + StringBuffer_Clear(&buffer); return -1; } } - StringBuffer_CLEAR(&buffer); + StringBuffer_Clear(&buffer); #ifdef OCI_ATTR_DRIVER_NAME status = OCIAttrSet(self->sessionHandle, OCI_HTYPE_SESSION, diff --git a/Cursor.c b/Cursor.c index 8ed7e99..fb786fe 100644 --- a/Cursor.c +++ b/Cursor.c @@ -216,7 +216,7 @@ static int Cursor_FreeHandle( status = OCIStmtRelease(self->handle, self->environment->errorHandle, (text*) buffer.ptr, buffer.size, OCI_DEFAULT); - StringBuffer_CLEAR(&buffer); + StringBuffer_Clear(&buffer); if (raiseException && Environment_CheckForError( self->environment, status, "Cursor_FreeHandle()") < 0) return -1; @@ -1115,7 +1115,7 @@ static int Cursor_InternalPrepare( if (StringBuffer_Fill(&statementBuffer, statement) < 0) return -1; if (StringBuffer_Fill(&tagBuffer, statementTag) < 0) { - StringBuffer_CLEAR(&statementBuffer); + StringBuffer_Clear(&statementBuffer); return -1; } status = OCIStmtPrepare2(self->connection->handle, &self->handle, @@ -1123,8 +1123,8 @@ static int Cursor_InternalPrepare( statementBuffer.size, (text*) tagBuffer.ptr, tagBuffer.size, OCI_NTV_SYNTAX, OCI_DEFAULT); Py_END_ALLOW_THREADS - StringBuffer_CLEAR(&statementBuffer); - StringBuffer_CLEAR(&tagBuffer); + StringBuffer_Clear(&statementBuffer); + StringBuffer_Clear(&tagBuffer); if (Environment_CheckForError(self->environment, status, "Cursor_InternalPrepare(): prepare") < 0) { // this is needed to avoid "invalid handle" errors since Oracle doesn't diff --git a/SessionPool.c b/SessionPool.c index 44e7913..5bc98f7 100644 --- a/SessionPool.c +++ b/SessionPool.c @@ -255,12 +255,12 @@ static int SessionPool_Init( if (StringBuffer_Fill(&username, self->username) < 0) return -1; if (StringBuffer_Fill(&password, self->password) < 0) { - StringBuffer_CLEAR(&username); + StringBuffer_Clear(&username); return -1; } if (StringBuffer_Fill(&dsn, self->dsn) < 0) { - StringBuffer_CLEAR(&username); - StringBuffer_CLEAR(&password); + StringBuffer_Clear(&username); + StringBuffer_Clear(&password); return -1; } Py_BEGIN_ALLOW_THREADS @@ -271,9 +271,9 @@ static int SessionPool_Init( (OraText*) username.ptr, username.size, (OraText*) password.ptr, password.size, poolMode); Py_END_ALLOW_THREADS - StringBuffer_CLEAR(&username); - StringBuffer_CLEAR(&password); - StringBuffer_CLEAR(&dsn); + StringBuffer_Clear(&username); + StringBuffer_Clear(&password); + StringBuffer_Clear(&dsn); if (Environment_CheckForError(self->environment, status, "SessionPool_New(): create pool") < 0) return -1; diff --git a/StringUtils.c b/StringUtils.c index f7fb067..5581ec2 100644 --- a/StringUtils.c +++ b/StringUtils.c @@ -73,12 +73,12 @@ static int StringBuffer_Fill( #define cxString_FromAscii(str) \ PyUnicode_DecodeASCII(str, strlen(str), NULL) #ifdef Py_UNICODE_WIDE - #define StringBuffer_CLEAR(buffer) \ + #define StringBuffer_Clear(buffer) \ Py_XDECREF((buffer)->encodedString) #define cxString_FromEncodedString(buffer, numBytes) \ PyUnicode_DecodeUTF16(buffer, numBytes, NULL, NULL) #else - #define StringBuffer_CLEAR(buffer) + #define StringBuffer_Clear(buffer) #define cxString_FromEncodedString(buffer, numBytes) \ PyUnicode_FromUnicode((Py_UNICODE*) (buffer), (numBytes) / 2) #endif @@ -88,7 +88,7 @@ static int StringBuffer_Fill( #define cxString_Type &PyBytes_Type #define cxString_Format PyBytes_Format #define cxString_Check PyBytes_Check - #define StringBuffer_CLEAR(buffer) + #define StringBuffer_Clear(buffer) #define cxString_FromAscii(str) \ PyBytes_FromString(str) #define cxString_FromEncodedString(buffer, numBytes) \ diff --git a/StringVar.c b/StringVar.c index 902b526..b7488f1 100644 --- a/StringVar.c +++ b/StringVar.c @@ -358,10 +358,14 @@ static int StringVar_SetValue( // get the buffer data and size for binding encodedString = NULL; +#ifdef WITH_UNICODE + if (var->type == &vt_Binary) { +#else if (var->type->charsetForm == SQLCS_IMPLICIT) { - if (PyString_Check(value)) { - buffer = PyString_AS_STRING(value); - bufferSize = PyString_GET_SIZE(value); +#endif + if (PyBytes_Check(value)) { + buffer = PyBytes_AS_STRING(value); + bufferSize = PyBytes_GET_SIZE(value); } else if (PyBuffer_Check(value)) { if (PyObject_AsReadBuffer(value, &buffer, &bufferSize) < 0) return -1; diff --git a/Variable.c b/Variable.c index 5dba50b..da37f68 100644 --- a/Variable.c +++ b/Variable.c @@ -1006,22 +1006,24 @@ static int Variable_InternalBind( // perform the bind if (var->boundName) { + udt_StringBuffer buffer; + if (StringBuffer_Fill(&buffer, var->boundName) < 0) + return -1; if (var->isArray) { status = OCIBindByName(var->boundCursorHandle, &var->bindHandle, - var->environment->errorHandle, - (unsigned char*) PyString_AS_STRING(var->boundName), - PyString_GET_SIZE(var->boundName), var->data, - var->maxLength, var->type->oracleType, var->indicator, - var->actualLength, var->returnCode, var->allocatedElements, + var->environment->errorHandle, (text*) buffer.ptr, + buffer.size, var->data, var->maxLength, + var->type->oracleType, var->indicator, var->actualLength, + var->returnCode, var->allocatedElements, &var->actualElements, OCI_DEFAULT); } else { status = OCIBindByName(var->boundCursorHandle, &var->bindHandle, - var->environment->errorHandle, - (unsigned char*) PyString_AS_STRING(var->boundName), - PyString_GET_SIZE(var->boundName), var->data, - var->maxLength, var->type->oracleType, var->indicator, - var->actualLength, var->returnCode, 0, 0, OCI_DEFAULT); + var->environment->errorHandle, (text*) buffer.ptr, + buffer.size, var->data, var->maxLength, + var->type->oracleType, var->indicator, var->actualLength, + var->returnCode, 0, 0, OCI_DEFAULT); } + StringBuffer_Clear(&buffer); } else { if (var->isArray) { status = OCIBindByPos(var->boundCursorHandle, &var->bindHandle, @@ -1095,11 +1097,19 @@ static int Variable_Bind( return 0; // set the instance variables specific for binding - Py_XDECREF(var->boundName); - Py_XINCREF(name); - var->boundName = name; var->boundPos = pos; var->boundCursorHandle = cursor->handle; + Py_XDECREF(var->boundName); +#if defined(WITH_UNICODE) && Py_MAJOR_VERSION < 3 + if (name && PyBytes_Check(name)) { + var->boundName = PyObject_Unicode(name); + if (!var->boundName) + return -1; + return Variable_InternalBind(var); + } +#endif + Py_XINCREF(name); + var->boundName = name; // perform the bind return Variable_InternalBind(var); diff --git a/test/test.py b/test/test.py index 0a552ed..6308940 100644 --- a/test/test.py +++ b/test/test.py @@ -27,7 +27,8 @@ if hasattr(cx_Oracle, "UNICODE") or sys.version_info[0] >= 3: ] else: moduleNames = [ - "uConnection" + "uConnection", + "uCursor" ] class BaseTestCase(unittest.TestCase):