Skip to content

Commit 7ad13e7

Browse files
Added parameter stmtcachesize to cx_Oracle.connect() and
cx_Oracle.SessionPool() in order to facilitate specifying the initial size of the statement cache.
1 parent cb1061a commit 7ad13e7

4 files changed

Lines changed: 39 additions & 19 deletions

File tree

doc/src/api_manual/module.rst

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@ Module Interface
4141
events=False, cclass=None, purity=cx_Oracle.ATTR_PURITY_DEFAULT, \
4242
newpassword=None, encoding=None, nencoding=None, edition=None, \
4343
appcontext=[], tag=None, matchanytag=None, shardingkey=[], \
44-
supershardingkey=[])
44+
supershardingkey=[], stmtcachesize=20)
4545
Connection(user=None, password=None, dsn=None, \
4646
mode=cx_Oracle.DEFAULT_AUTH, handle=0, pool=None, threaded=False, \
4747
events=False, cclass=None, purity=cx_Oracle.ATTR_PURITY_DEFAULT, \
4848
newpassword=None, encoding=None, nencoding=None, edition=None, \
4949
appcontext=[], tag=None, matchanytag=False, shardingkey=[], \
50-
supershardingkey=[])
50+
supershardingkey=[], stmtcachesize=20)
5151

5252
Constructor for creating a connection to the database. Return a
5353
:ref:`connection object <connobj>`. All parameters are optional and can be
@@ -126,6 +126,12 @@ Module Interface
126126
to be a sequence of values which will be used to identify the database
127127
shard to connect to. The key values can be strings, numbers, bytes or dates.
128128

129+
The stmtcachesize parameter, if specified, is expected to be an integer
130+
which specifies the initial value of :data:`~Connection.stmtcachesize`.
131+
132+
.. versionchanged:: 8.2
133+
134+
The parameter `stmtcachesize` was added.
129135

130136
.. function:: Cursor(connection)
131137

@@ -320,19 +326,22 @@ Module Interface
320326
used for any given shard in a sharded database. This value is ignored if
321327
the Oracle client library version is less than 18.3.
322328

329+
The stmtcachesize parameter, if specified, is expected to be an integer
330+
which specifies the initial value of :data:`~SessionPool.stmtcachesize`.
331+
323332
.. note::
324333

325334
This method is an extension to the DB API definition.
326335

327336
.. versionchanged:: 8.2
328337

329-
For consistency and compliance with the PEP 8 naming style, the
330-
parameter `waitTimeout` was renamed to `wait_timeout`, the parameter
331-
`maxLifetimeSession` was renamed to `max_lifetime_session`, the
332-
parameter `sessionCallback` was renamed to `session_callback` and the
333-
parameter `maxSessionsPerShard` was renamed to
334-
`max_sessions_per_shard`. The old names will continue to work as
335-
keyword parameters for a period of time.
338+
The parameter `stmtcachesize` was added. For consistency and
339+
compliance with the PEP 8 naming style, the parameter `waitTimeout` was
340+
renamed to `wait_timeout`, the parameter `maxLifetimeSession` was
341+
renamed to `max_lifetime_session`, the parameter `sessionCallback` was
342+
renamed to `session_callback` and the parameter `maxSessionsPerShard`
343+
was renamed to `max_sessions_per_shard`. The old names will continue to
344+
work as keyword parameters for a period of time.
336345

337346

338347
.. function:: Time(hour, minute, second)

doc/src/release_notes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ Version 8.2 (TBD)
1717
:meth:`SodaCollection.insertManyAndGet()` and
1818
:meth:`SodaCollection.saveAndGet()`. All of these require Oracle Client
1919
21.3 or higher (or Oracle Client 19 from 19.11).
20+
#) Added parameter `stmtcachesize` to :meth:`cx_Oracle.connect()` and
21+
:meth:`cx_Oracle.SessionPool()` in order to permit specifying the size of
22+
the statement cache during the creation of pools and standalone
23+
connections.
2024
#) Eliminated memory leak when calling :meth:`SodaOperation.filter()` with a
2125
dictionary.
2226
#) The distributed transaction handle assosciated with the connection is now

src/cxoConnection.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,7 @@ static int cxoConnection_init(cxoConnection *conn, PyObject *args,
475475
dpiCommonCreateParams dpiCommonParams;
476476
dpiConnCreateParams dpiCreateParams;
477477
unsigned long long externalHandle;
478+
unsigned int stmtCacheSize;
478479
cxoConnectionParams params;
479480
PyObject *newPasswordObj;
480481
cxoSessionPool *pool;
@@ -483,7 +484,8 @@ static int cxoConnection_init(cxoConnection *conn, PyObject *args,
483484
static char *keywordList[] = { "user", "password", "dsn", "mode",
484485
"handle", "pool", "threaded", "events", "cclass", "purity",
485486
"newpassword", "encoding", "nencoding", "edition", "appcontext",
486-
"tag", "matchanytag", "shardingkey", "supershardingkey", NULL };
487+
"tag", "matchanytag", "shardingkey", "supershardingkey",
488+
"stmtcachesize", NULL };
487489

488490
// parse arguments
489491
pool = NULL;
@@ -492,20 +494,21 @@ static int cxoConnection_init(cxoConnection *conn, PyObject *args,
492494
passwordObj = dsnObj = cclassObj = editionObj = NULL;
493495
threadedObj = eventsObj = newPasswordObj = usernameObj = NULL;
494496
matchAnyTagObj = contextObj = shardingKeyObj = superShardingKeyObj = NULL;
497+
stmtCacheSize = DPI_DEFAULT_STMT_CACHE_SIZE;
495498
if (cxoUtils_initializeDPI(NULL) < 0)
496499
return -1;
497500
if (dpiContext_initCommonCreateParams(cxoDpiContext, &dpiCommonParams) < 0)
498501
return cxoError_raiseAndReturnInt();
499502
if (dpiContext_initConnCreateParams(cxoDpiContext, &dpiCreateParams) < 0)
500503
return cxoError_raiseAndReturnInt();
501504
if (!PyArg_ParseTupleAndKeywords(args, keywordArgs,
502-
"|OOOiKO!OOOiOssOOOOOO", keywordList, &usernameObj, &passwordObj,
505+
"|OOOiKO!OOOiOssOOOOOOI", keywordList, &usernameObj, &passwordObj,
503506
&dsnObj, &dpiCreateParams.authMode, &externalHandle,
504507
&cxoPyTypeSessionPool, &pool, &threadedObj, &eventsObj, &cclassObj,
505508
&dpiCreateParams.purity, &newPasswordObj,
506509
&dpiCommonParams.encoding, &dpiCommonParams.nencoding, &editionObj,
507510
&contextObj, &tagObj, &matchAnyTagObj, &shardingKeyObj,
508-
&superShardingKeyObj))
511+
&superShardingKeyObj, &stmtCacheSize))
509512
return -1;
510513
dpiCreateParams.externalHandle = (void*) externalHandle;
511514
if (cxoUtils_getBooleanValue(threadedObj, 0, &temp) < 0)
@@ -593,6 +596,7 @@ static int cxoConnection_init(cxoConnection *conn, PyObject *args,
593596
dpiCreateParams.newPasswordLength = params.newPasswordBuffer.size;
594597
dpiCommonParams.edition = params.editionBuffer.ptr;
595598
dpiCommonParams.editionLength = params.editionBuffer.size;
599+
dpiCommonParams.stmtCacheSize = stmtCacheSize;
596600
dpiCreateParams.tag = params.tagBuffer.ptr;
597601
dpiCreateParams.tagLength = params.tagBuffer.size;
598602
dpiCreateParams.appContext = params.appContext;

src/cxoSessionPool.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ static int cxoSessionPool_init(cxoSessionPool *pool, PyObject *args,
4343
dpiPoolCreateParams dpiCreateParams;
4444
cxoBuffer sessionCallbackBuffer;
4545
PyTypeObject *connectionType;
46+
unsigned int stmtCacheSize;
4647
const char *encoding;
4748
int status, temp;
4849

@@ -51,9 +52,9 @@ static int cxoSessionPool_init(cxoSessionPool *pool, PyObject *args,
5152
"increment", "connectiontype", "threaded", "getmode", "events",
5253
"homogeneous", "externalauth", "encoding", "nencoding", "edition",
5354
"timeout", "wait_timeout", "max_lifetime_session",
54-
"session_callback", "max_sessions_per_shard", "waitTimeout",
55-
"maxLifetimeSession", "sessionCallback", "maxSessionsPerShard",
56-
NULL };
55+
"session_callback", "max_sessions_per_shard", "stmtcachesize",
56+
"waitTimeout", "maxLifetimeSession", "sessionCallback",
57+
"maxSessionsPerShard", NULL };
5758

5859
// parse arguments and keywords
5960
usernameObj = passwordObj = dsnObj = editionObj = Py_None;
@@ -66,23 +67,24 @@ static int cxoSessionPool_init(cxoSessionPool *pool, PyObject *args,
6667
maxSessionsPerShard = maxSessionsPerShardDeprecated = 0;
6768
waitTimeoutDeprecated = maxLifetimeSessionDeprecated = 0;
6869
maxSessionsPerShardDeprecated = 0;
70+
stmtCacheSize = DPI_DEFAULT_STMT_CACHE_SIZE;
6971
if (cxoUtils_initializeDPI(NULL) < 0)
7072
return -1;
7173
if (dpiContext_initCommonCreateParams(cxoDpiContext, &dpiCommonParams) < 0)
7274
return cxoError_raiseAndReturnInt();
7375
if (dpiContext_initPoolCreateParams(cxoDpiContext, &dpiCreateParams) < 0)
7476
return cxoError_raiseAndReturnInt();
7577
if (!PyArg_ParseTupleAndKeywords(args, keywordArgs,
76-
"|OOOiiiOObOOOssOiiiOiiiOi", keywordList, &usernameObj,
78+
"|OOOiiiOObOOOssOiiiOiIiiOi", keywordList, &usernameObj,
7779
&passwordObj, &dsnObj, &minSessions, &maxSessions,
7880
&sessionIncrement, &connectionType, &threadedObj,
7981
&dpiCreateParams.getMode, &eventsObj, &homogeneousObj,
8082
&externalAuthObj, &dpiCommonParams.encoding,
8183
&dpiCommonParams.nencoding, &editionObj, &dpiCreateParams.timeout,
8284
&dpiCreateParams.waitTimeout, &dpiCreateParams.maxLifetimeSession,
83-
&sessionCallbackObj, &maxSessionsPerShard, &waitTimeoutDeprecated,
84-
&maxLifetimeSessionDeprecated, &sessionCallbackObjDeprecated,
85-
&maxSessionsPerShardDeprecated))
85+
&sessionCallbackObj, &maxSessionsPerShard, &stmtCacheSize,
86+
&waitTimeoutDeprecated, &maxLifetimeSessionDeprecated,
87+
&sessionCallbackObjDeprecated, &maxSessionsPerShardDeprecated))
8688
return -1;
8789
if (!PyType_Check(connectionType)) {
8890
cxoError_raiseFromString(cxoProgrammingErrorException,
@@ -190,6 +192,7 @@ static int cxoSessionPool_init(cxoSessionPool *pool, PyObject *args,
190192
dpiCreateParams.maxSessionsPerShard = maxSessionsPerShard;
191193
dpiCommonParams.edition = editionBuffer.ptr;
192194
dpiCommonParams.editionLength = editionBuffer.size;
195+
dpiCommonParams.stmtCacheSize = stmtCacheSize;
193196

194197
// create pool
195198
Py_BEGIN_ALLOW_THREADS

0 commit comments

Comments
 (0)