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:
Anthony Tuininga 2008-10-14 16:53:05 +00:00
parent 030d6528b5
commit eae705cef1
7 changed files with 57 additions and 42 deletions

View File

@ -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,

View File

@ -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

View File

@ -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;

View File

@ -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) \

View File

@ -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;

View File

@ -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);

View File

@ -27,7 +27,8 @@ if hasattr(cx_Oracle, "UNICODE") or sys.version_info[0] >= 3:
]
else:
moduleNames = [
"uConnection"
"uConnection",
"uCursor"
]
class BaseTestCase(unittest.TestCase):