@@ -160,11 +160,12 @@ static int cxoSessionPool_init(cxoSessionPool *pool, PyObject *args,
160160{
161161 cxoBuffer userNameBuffer , passwordBuffer , dsnBuffer , editionBuffer ;
162162 PyObject * threadedObj , * eventsObj , * homogeneousObj , * passwordObj ;
163+ PyObject * usernameObj , * dsnObj , * sessionCallbackObj ;
163164 uint32_t minSessions , maxSessions , sessionIncrement ;
164165 PyObject * externalAuthObj , * editionObj ;
165166 dpiCommonCreateParams dpiCommonParams ;
166167 dpiPoolCreateParams dpiCreateParams ;
167- PyObject * usernameObj , * dsnObj ;
168+ cxoBuffer sessionCallbackBuffer ;
168169 PyTypeObject * connectionType ;
169170 const char * encoding ;
170171 int status , temp ;
@@ -173,11 +174,12 @@ static int cxoSessionPool_init(cxoSessionPool *pool, PyObject *args,
173174 static char * keywordList [] = { "user" , "password" , "dsn" , "min" , "max" ,
174175 "increment" , "connectiontype" , "threaded" , "getmode" , "events" ,
175176 "homogeneous" , "externalauth" , "encoding" , "nencoding" , "edition" ,
176- "timeout" , "waitTimeout" , "maxLifetimeSession" , NULL };
177+ "timeout" , "waitTimeout" , "maxLifetimeSession" , "sessionCallback" ,
178+ NULL };
177179
178180 // parse arguments and keywords
179181 usernameObj = passwordObj = dsnObj = editionObj = Py_None ;
180- externalAuthObj = NULL ;
182+ externalAuthObj = sessionCallbackObj = NULL ;
181183 threadedObj = eventsObj = homogeneousObj = passwordObj = NULL ;
182184 connectionType = & cxoPyTypeConnection ;
183185 minSessions = 1 ;
@@ -192,13 +194,14 @@ static int cxoSessionPool_init(cxoSessionPool *pool, PyObject *args,
192194 (uint32_t ) strlen (dpiCommonParams .driverName );
193195 if (dpiContext_initPoolCreateParams (cxoDpiContext , & dpiCreateParams ) < 0 )
194196 return cxoError_raiseAndReturnInt ();
195- if (!PyArg_ParseTupleAndKeywords (args , keywordArgs , "|OOOiiiOObOOOssOiii " ,
197+ if (!PyArg_ParseTupleAndKeywords (args , keywordArgs , "|OOOiiiOObOOOssOiiiO " ,
196198 keywordList , & usernameObj , & passwordObj , & dsnObj , & minSessions ,
197199 & maxSessions , & sessionIncrement , & connectionType , & threadedObj ,
198200 & dpiCreateParams .getMode , & eventsObj , & homogeneousObj ,
199201 & externalAuthObj , & dpiCommonParams .encoding ,
200202 & dpiCommonParams .nencoding , & editionObj , & dpiCreateParams .timeout ,
201- & dpiCreateParams .waitTimeout , & dpiCreateParams .maxLifetimeSession ))
203+ & dpiCreateParams .waitTimeout , & dpiCreateParams .maxLifetimeSession ,
204+ & sessionCallbackObj ))
202205 return -1 ;
203206 if (!PyType_Check (connectionType )) {
204207 cxoError_raiseFromString (cxoProgrammingErrorException ,
@@ -237,25 +240,35 @@ static int cxoSessionPool_init(cxoSessionPool *pool, PyObject *args,
237240 pool -> sessionIncrement = sessionIncrement ;
238241 pool -> homogeneous = dpiCreateParams .homogeneous ;
239242 pool -> externalAuth = dpiCreateParams .externalAuth ;
243+ Py_XINCREF (sessionCallbackObj );
244+ pool -> sessionCallback = sessionCallbackObj ;
240245
241246 // populate parameters
242247 encoding = cxoUtils_getAdjustedEncoding (dpiCommonParams .encoding );
243248 cxoBuffer_init (& userNameBuffer );
244249 cxoBuffer_init (& passwordBuffer );
245250 cxoBuffer_init (& dsnBuffer );
246251 cxoBuffer_init (& editionBuffer );
252+ cxoBuffer_init (& sessionCallbackBuffer );
253+ if (sessionCallbackObj && !PyCallable_Check (sessionCallbackObj ) &&
254+ cxoBuffer_fromObject (& sessionCallbackBuffer , sessionCallbackObj ,
255+ encoding ) < 0 )
256+ return -1 ;
247257 if (cxoBuffer_fromObject (& userNameBuffer , usernameObj , encoding ) < 0 ||
248258 cxoBuffer_fromObject (& passwordBuffer , passwordObj , encoding ) < 0 ||
249259 cxoBuffer_fromObject (& dsnBuffer , dsnObj , encoding ) < 0 ||
250260 cxoBuffer_fromObject (& editionBuffer , editionObj , encoding ) < 0 ) {
251261 cxoBuffer_clear (& userNameBuffer );
252262 cxoBuffer_clear (& passwordBuffer );
253263 cxoBuffer_clear (& dsnBuffer );
264+ cxoBuffer_clear (& sessionCallbackBuffer );
254265 return -1 ;
255266 }
256267 dpiCreateParams .minSessions = minSessions ;
257268 dpiCreateParams .maxSessions = maxSessions ;
258269 dpiCreateParams .sessionIncrement = sessionIncrement ;
270+ dpiCreateParams .plsqlFixupCallback = sessionCallbackBuffer .ptr ;
271+ dpiCreateParams .plsqlFixupCallbackLength = sessionCallbackBuffer .size ;
259272 dpiCommonParams .edition = editionBuffer .ptr ;
260273 dpiCommonParams .editionLength = editionBuffer .size ;
261274
@@ -303,6 +316,7 @@ static void cxoSessionPool_free(cxoSessionPool *pool)
303316 Py_CLEAR (pool -> username );
304317 Py_CLEAR (pool -> dsn );
305318 Py_CLEAR (pool -> name );
319+ Py_CLEAR (pool -> sessionCallback );
306320 Py_TYPE (pool )-> tp_free ((PyObject * ) pool );
307321}
308322
@@ -425,34 +439,37 @@ static PyObject *cxoSessionPool_release(cxoSessionPool *pool, PyObject *args,
425439 PyObject * keywordArgs )
426440{
427441 static char * keywordList [] = { "connection" , "tag" , NULL };
428- cxoConnection * connection ;
429- dpiConnCloseMode mode ;
442+ cxoConnection * conn ;
430443 cxoBuffer tagBuffer ;
431444 PyObject * tagObj ;
445+ uint32_t mode ;
432446 int status ;
433447
434448 // parse arguments
435449 tagObj = NULL ;
436450 if (!PyArg_ParseTupleAndKeywords (args , keywordArgs , "O!|O" ,
437- keywordList , & cxoPyTypeConnection , & connection , & tagObj ))
451+ keywordList , & cxoPyTypeConnection , & conn , & tagObj ))
438452 return NULL ;
453+ if (!tagObj )
454+ tagObj = conn -> tag ;
439455 if (cxoBuffer_fromObject (& tagBuffer , tagObj ,
440456 pool -> encodingInfo .encoding ) < 0 )
441457 return NULL ;
442- mode = (tagBuffer .size > 0 ) ? DPI_MODE_CONN_CLOSE_RETAG :
443- DPI_MODE_CONN_CLOSE_DEFAULT ;
458+ mode = DPI_MODE_CONN_CLOSE_DEFAULT ;
459+ if (tagObj && tagObj != Py_None )
460+ mode |= DPI_MODE_CONN_CLOSE_RETAG ;
444461 Py_BEGIN_ALLOW_THREADS
445- status = dpiConn_close (connection -> handle , mode , (char * ) tagBuffer .ptr ,
462+ status = dpiConn_close (conn -> handle , mode , (char * ) tagBuffer .ptr ,
446463 tagBuffer .size );
447464 Py_END_ALLOW_THREADS
448465 cxoBuffer_clear (& tagBuffer );
449466 if (status < 0 )
450467 return cxoError_raiseAndReturnNull ();
451468
452469 // mark connection as closed
453- Py_CLEAR (connection -> sessionPool );
454- dpiConn_release (connection -> handle );
455- connection -> handle = NULL ;
470+ Py_CLEAR (conn -> sessionPool );
471+ dpiConn_release (conn -> handle );
472+ conn -> handle = NULL ;
456473 Py_RETURN_NONE ;
457474}
458475
0 commit comments