Rename additional macro as suggested by Amaury Forgeot d'Arc; added additional
support for full Unicode; in Python 2.x allow for keyword arguments which use strings and simply convert them to Unicode on the way through.
This commit is contained in:
parent
030d6528b5
commit
eae705cef1
24
Connection.c
24
Connection.c
|
@ -264,11 +264,11 @@ static int Connection_GetConnection(
|
||||||
environment->errorHandle);
|
environment->errorHandle);
|
||||||
if (Environment_CheckForError(environment, status,
|
if (Environment_CheckForError(environment, status,
|
||||||
"Connection_GetConnection(): set user name") < 0) {
|
"Connection_GetConnection(): set user name") < 0) {
|
||||||
StringBuffer_CLEAR(&buffer);
|
StringBuffer_Clear(&buffer);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
StringBuffer_CLEAR(&buffer);
|
StringBuffer_Clear(&buffer);
|
||||||
|
|
||||||
// set the password, if applicable
|
// set the password, if applicable
|
||||||
if (StringBuffer_Fill(&buffer, self->password) < 0)
|
if (StringBuffer_Fill(&buffer, self->password) < 0)
|
||||||
|
@ -280,11 +280,11 @@ static int Connection_GetConnection(
|
||||||
environment->errorHandle);
|
environment->errorHandle);
|
||||||
if (Environment_CheckForError(environment, status,
|
if (Environment_CheckForError(environment, status,
|
||||||
"Connection_GetConnection(): set password") < 0) {
|
"Connection_GetConnection(): set password") < 0) {
|
||||||
StringBuffer_CLEAR(&buffer);
|
StringBuffer_Clear(&buffer);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
StringBuffer_CLEAR(&buffer);
|
StringBuffer_Clear(&buffer);
|
||||||
|
|
||||||
// if no user name or password are set, using external credentials
|
// if no user name or password are set, using external credentials
|
||||||
if (!pool && externalCredentials)
|
if (!pool && externalCredentials)
|
||||||
|
@ -300,11 +300,11 @@ static int Connection_GetConnection(
|
||||||
environment->errorHandle);
|
environment->errorHandle);
|
||||||
if (Environment_CheckForError(environment, status,
|
if (Environment_CheckForError(environment, status,
|
||||||
"Connection_GetConnection(): set connection class") < 0) {
|
"Connection_GetConnection(): set connection class") < 0) {
|
||||||
StringBuffer_CLEAR(&buffer);
|
StringBuffer_Clear(&buffer);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
StringBuffer_CLEAR(&buffer);
|
StringBuffer_Clear(&buffer);
|
||||||
|
|
||||||
// set the purity, if applicable
|
// set the purity, if applicable
|
||||||
if (purity != OCI_ATTR_PURITY_DEFAULT) {
|
if (purity != OCI_ATTR_PURITY_DEFAULT) {
|
||||||
|
@ -326,7 +326,7 @@ static int Connection_GetConnection(
|
||||||
&self->handle, authInfo, (text*) buffer.ptr, buffer.size, NULL, 0,
|
&self->handle, authInfo, (text*) buffer.ptr, buffer.size, NULL, 0,
|
||||||
NULL, NULL, &found, mode);
|
NULL, NULL, &found, mode);
|
||||||
Py_END_ALLOW_THREADS
|
Py_END_ALLOW_THREADS
|
||||||
StringBuffer_CLEAR(&buffer);
|
StringBuffer_Clear(&buffer);
|
||||||
if (Environment_CheckForError(environment, status,
|
if (Environment_CheckForError(environment, status,
|
||||||
"Connection_GetConnection(): get connection") < 0)
|
"Connection_GetConnection(): get connection") < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -469,7 +469,7 @@ static int Connection_Connect(
|
||||||
self->environment->errorHandle, (text*) buffer.ptr, buffer.size,
|
self->environment->errorHandle, (text*) buffer.ptr, buffer.size,
|
||||||
OCI_DEFAULT);
|
OCI_DEFAULT);
|
||||||
Py_END_ALLOW_THREADS
|
Py_END_ALLOW_THREADS
|
||||||
StringBuffer_CLEAR(&buffer);
|
StringBuffer_Clear(&buffer);
|
||||||
if (Environment_CheckForError(self->environment, status,
|
if (Environment_CheckForError(self->environment, status,
|
||||||
"Connection_Connect(): server attach") < 0)
|
"Connection_Connect(): server attach") < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -522,11 +522,11 @@ static int Connection_Connect(
|
||||||
self->environment->errorHandle);
|
self->environment->errorHandle);
|
||||||
if (Environment_CheckForError(self->environment, status,
|
if (Environment_CheckForError(self->environment, status,
|
||||||
"Connection_Connect(): set user name") < 0) {
|
"Connection_Connect(): set user name") < 0) {
|
||||||
StringBuffer_CLEAR(&buffer);
|
StringBuffer_Clear(&buffer);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
StringBuffer_CLEAR(&buffer);
|
StringBuffer_Clear(&buffer);
|
||||||
|
|
||||||
// set password in session handle
|
// set password in session handle
|
||||||
if (StringBuffer_Fill(&buffer, self->password) < 0)
|
if (StringBuffer_Fill(&buffer, self->password) < 0)
|
||||||
|
@ -538,11 +538,11 @@ static int Connection_Connect(
|
||||||
self->environment->errorHandle);
|
self->environment->errorHandle);
|
||||||
if (Environment_CheckForError(self->environment, status,
|
if (Environment_CheckForError(self->environment, status,
|
||||||
"Connection_Connect(): set password") < 0) {
|
"Connection_Connect(): set password") < 0) {
|
||||||
StringBuffer_CLEAR(&buffer);
|
StringBuffer_Clear(&buffer);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
StringBuffer_CLEAR(&buffer);
|
StringBuffer_Clear(&buffer);
|
||||||
|
|
||||||
#ifdef OCI_ATTR_DRIVER_NAME
|
#ifdef OCI_ATTR_DRIVER_NAME
|
||||||
status = OCIAttrSet(self->sessionHandle, OCI_HTYPE_SESSION,
|
status = OCIAttrSet(self->sessionHandle, OCI_HTYPE_SESSION,
|
||||||
|
|
8
Cursor.c
8
Cursor.c
|
@ -216,7 +216,7 @@ static int Cursor_FreeHandle(
|
||||||
status = OCIStmtRelease(self->handle,
|
status = OCIStmtRelease(self->handle,
|
||||||
self->environment->errorHandle, (text*) buffer.ptr,
|
self->environment->errorHandle, (text*) buffer.ptr,
|
||||||
buffer.size, OCI_DEFAULT);
|
buffer.size, OCI_DEFAULT);
|
||||||
StringBuffer_CLEAR(&buffer);
|
StringBuffer_Clear(&buffer);
|
||||||
if (raiseException && Environment_CheckForError(
|
if (raiseException && Environment_CheckForError(
|
||||||
self->environment, status, "Cursor_FreeHandle()") < 0)
|
self->environment, status, "Cursor_FreeHandle()") < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -1115,7 +1115,7 @@ static int Cursor_InternalPrepare(
|
||||||
if (StringBuffer_Fill(&statementBuffer, statement) < 0)
|
if (StringBuffer_Fill(&statementBuffer, statement) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
if (StringBuffer_Fill(&tagBuffer, statementTag) < 0) {
|
if (StringBuffer_Fill(&tagBuffer, statementTag) < 0) {
|
||||||
StringBuffer_CLEAR(&statementBuffer);
|
StringBuffer_Clear(&statementBuffer);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
status = OCIStmtPrepare2(self->connection->handle, &self->handle,
|
status = OCIStmtPrepare2(self->connection->handle, &self->handle,
|
||||||
|
@ -1123,8 +1123,8 @@ static int Cursor_InternalPrepare(
|
||||||
statementBuffer.size, (text*) tagBuffer.ptr, tagBuffer.size,
|
statementBuffer.size, (text*) tagBuffer.ptr, tagBuffer.size,
|
||||||
OCI_NTV_SYNTAX, OCI_DEFAULT);
|
OCI_NTV_SYNTAX, OCI_DEFAULT);
|
||||||
Py_END_ALLOW_THREADS
|
Py_END_ALLOW_THREADS
|
||||||
StringBuffer_CLEAR(&statementBuffer);
|
StringBuffer_Clear(&statementBuffer);
|
||||||
StringBuffer_CLEAR(&tagBuffer);
|
StringBuffer_Clear(&tagBuffer);
|
||||||
if (Environment_CheckForError(self->environment, status,
|
if (Environment_CheckForError(self->environment, status,
|
||||||
"Cursor_InternalPrepare(): prepare") < 0) {
|
"Cursor_InternalPrepare(): prepare") < 0) {
|
||||||
// this is needed to avoid "invalid handle" errors since Oracle doesn't
|
// this is needed to avoid "invalid handle" errors since Oracle doesn't
|
||||||
|
|
|
@ -255,12 +255,12 @@ static int SessionPool_Init(
|
||||||
if (StringBuffer_Fill(&username, self->username) < 0)
|
if (StringBuffer_Fill(&username, self->username) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
if (StringBuffer_Fill(&password, self->password) < 0) {
|
if (StringBuffer_Fill(&password, self->password) < 0) {
|
||||||
StringBuffer_CLEAR(&username);
|
StringBuffer_Clear(&username);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (StringBuffer_Fill(&dsn, self->dsn) < 0) {
|
if (StringBuffer_Fill(&dsn, self->dsn) < 0) {
|
||||||
StringBuffer_CLEAR(&username);
|
StringBuffer_Clear(&username);
|
||||||
StringBuffer_CLEAR(&password);
|
StringBuffer_Clear(&password);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
Py_BEGIN_ALLOW_THREADS
|
Py_BEGIN_ALLOW_THREADS
|
||||||
|
@ -271,9 +271,9 @@ static int SessionPool_Init(
|
||||||
(OraText*) username.ptr, username.size, (OraText*) password.ptr,
|
(OraText*) username.ptr, username.size, (OraText*) password.ptr,
|
||||||
password.size, poolMode);
|
password.size, poolMode);
|
||||||
Py_END_ALLOW_THREADS
|
Py_END_ALLOW_THREADS
|
||||||
StringBuffer_CLEAR(&username);
|
StringBuffer_Clear(&username);
|
||||||
StringBuffer_CLEAR(&password);
|
StringBuffer_Clear(&password);
|
||||||
StringBuffer_CLEAR(&dsn);
|
StringBuffer_Clear(&dsn);
|
||||||
if (Environment_CheckForError(self->environment, status,
|
if (Environment_CheckForError(self->environment, status,
|
||||||
"SessionPool_New(): create pool") < 0)
|
"SessionPool_New(): create pool") < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
@ -73,12 +73,12 @@ static int StringBuffer_Fill(
|
||||||
#define cxString_FromAscii(str) \
|
#define cxString_FromAscii(str) \
|
||||||
PyUnicode_DecodeASCII(str, strlen(str), NULL)
|
PyUnicode_DecodeASCII(str, strlen(str), NULL)
|
||||||
#ifdef Py_UNICODE_WIDE
|
#ifdef Py_UNICODE_WIDE
|
||||||
#define StringBuffer_CLEAR(buffer) \
|
#define StringBuffer_Clear(buffer) \
|
||||||
Py_XDECREF((buffer)->encodedString)
|
Py_XDECREF((buffer)->encodedString)
|
||||||
#define cxString_FromEncodedString(buffer, numBytes) \
|
#define cxString_FromEncodedString(buffer, numBytes) \
|
||||||
PyUnicode_DecodeUTF16(buffer, numBytes, NULL, NULL)
|
PyUnicode_DecodeUTF16(buffer, numBytes, NULL, NULL)
|
||||||
#else
|
#else
|
||||||
#define StringBuffer_CLEAR(buffer)
|
#define StringBuffer_Clear(buffer)
|
||||||
#define cxString_FromEncodedString(buffer, numBytes) \
|
#define cxString_FromEncodedString(buffer, numBytes) \
|
||||||
PyUnicode_FromUnicode((Py_UNICODE*) (buffer), (numBytes) / 2)
|
PyUnicode_FromUnicode((Py_UNICODE*) (buffer), (numBytes) / 2)
|
||||||
#endif
|
#endif
|
||||||
|
@ -88,7 +88,7 @@ static int StringBuffer_Fill(
|
||||||
#define cxString_Type &PyBytes_Type
|
#define cxString_Type &PyBytes_Type
|
||||||
#define cxString_Format PyBytes_Format
|
#define cxString_Format PyBytes_Format
|
||||||
#define cxString_Check PyBytes_Check
|
#define cxString_Check PyBytes_Check
|
||||||
#define StringBuffer_CLEAR(buffer)
|
#define StringBuffer_Clear(buffer)
|
||||||
#define cxString_FromAscii(str) \
|
#define cxString_FromAscii(str) \
|
||||||
PyBytes_FromString(str)
|
PyBytes_FromString(str)
|
||||||
#define cxString_FromEncodedString(buffer, numBytes) \
|
#define cxString_FromEncodedString(buffer, numBytes) \
|
||||||
|
|
10
StringVar.c
10
StringVar.c
|
@ -358,10 +358,14 @@ static int StringVar_SetValue(
|
||||||
|
|
||||||
// get the buffer data and size for binding
|
// get the buffer data and size for binding
|
||||||
encodedString = NULL;
|
encodedString = NULL;
|
||||||
|
#ifdef WITH_UNICODE
|
||||||
|
if (var->type == &vt_Binary) {
|
||||||
|
#else
|
||||||
if (var->type->charsetForm == SQLCS_IMPLICIT) {
|
if (var->type->charsetForm == SQLCS_IMPLICIT) {
|
||||||
if (PyString_Check(value)) {
|
#endif
|
||||||
buffer = PyString_AS_STRING(value);
|
if (PyBytes_Check(value)) {
|
||||||
bufferSize = PyString_GET_SIZE(value);
|
buffer = PyBytes_AS_STRING(value);
|
||||||
|
bufferSize = PyBytes_GET_SIZE(value);
|
||||||
} else if (PyBuffer_Check(value)) {
|
} else if (PyBuffer_Check(value)) {
|
||||||
if (PyObject_AsReadBuffer(value, &buffer, &bufferSize) < 0)
|
if (PyObject_AsReadBuffer(value, &buffer, &bufferSize) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
36
Variable.c
36
Variable.c
|
@ -1006,22 +1006,24 @@ static int Variable_InternalBind(
|
||||||
|
|
||||||
// perform the bind
|
// perform the bind
|
||||||
if (var->boundName) {
|
if (var->boundName) {
|
||||||
|
udt_StringBuffer buffer;
|
||||||
|
if (StringBuffer_Fill(&buffer, var->boundName) < 0)
|
||||||
|
return -1;
|
||||||
if (var->isArray) {
|
if (var->isArray) {
|
||||||
status = OCIBindByName(var->boundCursorHandle, &var->bindHandle,
|
status = OCIBindByName(var->boundCursorHandle, &var->bindHandle,
|
||||||
var->environment->errorHandle,
|
var->environment->errorHandle, (text*) buffer.ptr,
|
||||||
(unsigned char*) PyString_AS_STRING(var->boundName),
|
buffer.size, var->data, var->maxLength,
|
||||||
PyString_GET_SIZE(var->boundName), var->data,
|
var->type->oracleType, var->indicator, var->actualLength,
|
||||||
var->maxLength, var->type->oracleType, var->indicator,
|
var->returnCode, var->allocatedElements,
|
||||||
var->actualLength, var->returnCode, var->allocatedElements,
|
|
||||||
&var->actualElements, OCI_DEFAULT);
|
&var->actualElements, OCI_DEFAULT);
|
||||||
} else {
|
} else {
|
||||||
status = OCIBindByName(var->boundCursorHandle, &var->bindHandle,
|
status = OCIBindByName(var->boundCursorHandle, &var->bindHandle,
|
||||||
var->environment->errorHandle,
|
var->environment->errorHandle, (text*) buffer.ptr,
|
||||||
(unsigned char*) PyString_AS_STRING(var->boundName),
|
buffer.size, var->data, var->maxLength,
|
||||||
PyString_GET_SIZE(var->boundName), var->data,
|
var->type->oracleType, var->indicator, var->actualLength,
|
||||||
var->maxLength, var->type->oracleType, var->indicator,
|
var->returnCode, 0, 0, OCI_DEFAULT);
|
||||||
var->actualLength, var->returnCode, 0, 0, OCI_DEFAULT);
|
|
||||||
}
|
}
|
||||||
|
StringBuffer_Clear(&buffer);
|
||||||
} else {
|
} else {
|
||||||
if (var->isArray) {
|
if (var->isArray) {
|
||||||
status = OCIBindByPos(var->boundCursorHandle, &var->bindHandle,
|
status = OCIBindByPos(var->boundCursorHandle, &var->bindHandle,
|
||||||
|
@ -1095,11 +1097,19 @@ static int Variable_Bind(
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
// set the instance variables specific for binding
|
// set the instance variables specific for binding
|
||||||
Py_XDECREF(var->boundName);
|
|
||||||
Py_XINCREF(name);
|
|
||||||
var->boundName = name;
|
|
||||||
var->boundPos = pos;
|
var->boundPos = pos;
|
||||||
var->boundCursorHandle = cursor->handle;
|
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
|
// perform the bind
|
||||||
return Variable_InternalBind(var);
|
return Variable_InternalBind(var);
|
||||||
|
|
|
@ -27,7 +27,8 @@ if hasattr(cx_Oracle, "UNICODE") or sys.version_info[0] >= 3:
|
||||||
]
|
]
|
||||||
else:
|
else:
|
||||||
moduleNames = [
|
moduleNames = [
|
||||||
"uConnection"
|
"uConnection",
|
||||||
|
"uCursor"
|
||||||
]
|
]
|
||||||
|
|
||||||
class BaseTestCase(unittest.TestCase):
|
class BaseTestCase(unittest.TestCase):
|
||||||
|
|
Loading…
Reference in New Issue