bool oci_return_connection_to_pool(void * connection_handle) { function_success = SUCCESS; OCISvcCtx *svchp = (OCISvcCtx *)connection_handle; if (svchp != NULL) checkerr(errhp, OCISessionRelease(svchp, errhp, NULL, 0, OCI_DEFAULT)); if(function_success != SUCCESS) return false; return true; }
/* thread_function can be run in multi-threads, each thread will have its own error handle */ void thread_function(void *ptr) { OCIError *errhp = NULL; int i=0; /* allocate error handle * note: for OCIHandleAlloc(), we always check error on environment handle */ checkenv(envhp, OCIHandleAlloc(envhp, /* environment handle */ (void **) &errhp, /* returned err handle */ OCI_HTYPE_ERROR,/*type of handle to allocate*/ (size_t) 0, /* extra memory size: optional */ (void **) NULL)); /* returned extra memory */ for(i=0; i<iteration; i++) { OCISvcCtx *svchp = NULL; /* OCI Service Context is a database connection */ /* get the database connection */ checkerr(errhp, OCISessionGet(envhp, errhp, &svchp, /* returned database connection */ authp, /* initialized authentication handle */ /* connect pool name */ (OraText *) poolName, poolNameLen, /* session tagging parameters: optional */ NULL, 0, NULL, NULL, NULL, OCI_SESSGET_SPOOL)); do_workload(svchp, errhp, ptr,i); /* destroy the connection */ checkerr(errhp, OCISessionRelease(svchp, errhp, NULL, 0, OCI_DEFAULT)); print_progress(ptr, i); /* print progress */ if (waittime > 0) sleep(waittime); /* Thinking time between database sessions */ } if (errhp) OCIHandleFree(errhp, OCI_HTYPE_ERROR); }
ocisession::~ocisession(void) { intf_ret r; // delete all the statements for (list<ocistmt*>::const_iterator it = _statements.begin(); it != _statements.end(); it++) (*it)->close(); _statements.clear(); checkerr(&r, OCISessionRelease((OCISvcCtx*)_svchp, (OCIError*)_errhp, NULL, 0, OCI_DEFAULT)); if(r.fn_ret != SUCCESS) { REMOTE_LOG("failed OCISessionRelease %s\n", r.gerrbuf); throw r; } (void) OCIHandleFree(_errhp, OCI_HTYPE_ERROR); // cleanup the environment if this is the last oci session from this environment _sessions.remove(this); //REMOTE_LOG("release session %p\n", _svchp); }