Added support for specifying the encodings to use for strings in the database

at the session pool level in addition to for standalone connections.
This commit is contained in:
Anthony Tuininga 2017-01-13 17:10:49 -07:00
parent 6356f78bd9
commit 2b9e80308e
2 changed files with 14 additions and 6 deletions

View File

@ -179,6 +179,7 @@ static int SessionPool_Init(
int threaded, events, homogeneous, externalAuth; int threaded, events, homogeneous, externalAuth;
udt_Buffer username, password, dsn; udt_Buffer username, password, dsn;
PyTypeObject *connectionType; PyTypeObject *connectionType;
char *encoding, *nencoding;
PyObject *externalAuthObj; PyObject *externalAuthObj;
unsigned poolNameLength; unsigned poolNameLength;
const char *poolName; const char *poolName;
@ -189,21 +190,22 @@ static int SessionPool_Init(
// define keyword arguments // define keyword arguments
static char *keywordList[] = { "user", "password", "dsn", "min", "max", static char *keywordList[] = { "user", "password", "dsn", "min", "max",
"increment", "connectiontype", "threaded", "getmode", "events", "increment", "connectiontype", "threaded", "getmode", "events",
"homogeneous", "externalauth", NULL }; "homogeneous", "externalauth", "encoding", "nencoding", NULL };
// parse arguments and keywords // parse arguments and keywords
homogeneous = 1; homogeneous = 1;
externalAuthObj = NULL; externalAuthObj = NULL;
encoding = nencoding = NULL;
threaded = events = externalAuth = 0; threaded = events = externalAuth = 0;
threadedObj = eventsObj = homogeneousObj = passwordObj = NULL; threadedObj = eventsObj = homogeneousObj = passwordObj = NULL;
connectionType = &g_ConnectionType; connectionType = &g_ConnectionType;
getMode = OCI_SPOOL_ATTRVAL_NOWAIT; getMode = OCI_SPOOL_ATTRVAL_NOWAIT;
if (!PyArg_ParseTupleAndKeywords(args, keywordArgs, "O!O!O!iii|OObOOO", if (!PyArg_ParseTupleAndKeywords(args, keywordArgs, "O!O!O!iii|OObOOOss",
keywordList, cxString_Type, &self->username, keywordList, cxString_Type, &self->username,
cxString_Type, &passwordObj, cxString_Type, &self->dsn, cxString_Type, &passwordObj, cxString_Type, &self->dsn,
&minSessions, &maxSessions, &sessionIncrement, &connectionType, &minSessions, &maxSessions, &sessionIncrement, &connectionType,
&threadedObj, &getMode, &eventsObj, &homogeneousObj, &threadedObj, &getMode, &eventsObj, &homogeneousObj,
&externalAuthObj)) &externalAuthObj, &encoding, &nencoding))
return -1; return -1;
if (!PyType_Check(connectionType)) { if (!PyType_Check(connectionType)) {
PyErr_SetString(g_ProgrammingErrorException, PyErr_SetString(g_ProgrammingErrorException,
@ -249,8 +251,8 @@ static int SessionPool_Init(
self->externalAuth = externalAuth; self->externalAuth = externalAuth;
// set up the environment // set up the environment
self->environment = Environment_NewFromScratch(threaded, events, NULL, self->environment = Environment_NewFromScratch(threaded, events, encoding,
NULL); nencoding);
if (!self->environment) if (!self->environment)
return -1; return -1;

View File

@ -126,7 +126,7 @@ Module Interface
This method is an extension to the DB API definition. This method is an extension to the DB API definition.
.. function:: SessionPool(user, password, database, min, max, increment, [connectiontype, threaded, getmode=cx_Oracle.SPOOL_ATTRVAL_NOWAIT, homogeneous=True, externalauth=True]) .. function:: SessionPool(user, password, database, min, max, increment, [connectiontype, threaded, getmode=cx_Oracle.SPOOL_ATTRVAL_NOWAIT, homogeneous=True, externalauth=True, encoding=None, nencoding=None])
Create a session pool (see Oracle documentation for more information) and Create a session pool (see Oracle documentation for more information) and
return a session pool object (:ref:`sesspool`). This allows for very fast return a session pool object (:ref:`sesspool`). This allows for very fast
@ -140,6 +140,12 @@ Module Interface
single threaded applications imposes a performance penalty of about 10-15% single threaded applications imposes a performance penalty of about 10-15%
which is why the default is False. which is why the default is False.
The encoding argument is expected to be a string if specified and sets the
encoding to use for regular database strings.
The nencoding argument is expected to be a string if specified and sets the
national encoding to use for national character set database strings.
.. note:: .. note::
This method is an extension to the DB API definition. This method is an extension to the DB API definition.