static VALUE complex_logoff_execute(void *arg) { complex_logoff_arg_t *cla = (complex_logoff_arg_t *)arg; OCIError *errhp = oci8_errhp; sword rv = OCI_SUCCESS; OCITransRollback(cla->svchp, errhp, OCI_DEFAULT); if (cla->state & OCI8_STATE_SESSION_BEGIN_WAS_CALLED) { rv = OCISessionEnd(cla->svchp, oci8_errhp, cla->usrhp, OCI_DEFAULT); cla->state &= ~OCI8_STATE_SESSION_BEGIN_WAS_CALLED; } if (cla->state & OCI8_STATE_SERVER_ATTACH_WAS_CALLED) { rv = OCIServerDetach(cla->srvhp, oci8_errhp, OCI_DEFAULT); cla->state &= ~OCI8_STATE_SERVER_ATTACH_WAS_CALLED; } if (cla->usrhp != NULL) { OCIHandleFree(cla->usrhp, OCI_HTYPE_SESSION); } if (cla->srvhp != NULL) { OCIHandleFree(cla->srvhp, OCI_HTYPE_SERVER); } if (cla->svchp != NULL) { OCIHandleFree(cla->svchp, OCI_HTYPE_SVCCTX); } free(cla); return (VALUE)rv; }
static void yada_oracle_disconnect(yada_t *_yada) { yada_rc_t *yrc; /* invalidate all result sets associated with this connection */ for(yrc=_yada->_priv->rc_head; yrc; yrc=yrc->next) { if(yrc->t != YADA_RESULT) continue; ((extinfo*)yrc->data)->invalid = 1; OCIStmtRelease(((extinfo*)yrc->data)->stmt, _yada->_mod->err, NULL, 0, OCI_DEFAULT); OCIHandleFree(((extinfo*)yrc->data)->stmt, OCI_HTYPE_STMT); } /* cleanup OCI */ if(_yada->_mod->ses) OCISessionEnd(_yada->_mod->ctx, _yada->_mod->err, _yada->_mod->ses, OCI_DEFAULT); if(_yada->_mod->srv) OCIServerDetach(_yada->_mod->srv, _yada->_mod->err, OCI_DEFAULT); if(_yada->_mod->env) OCIHandleFree(_yada->_mod->env, OCI_HTYPE_ENV); /* re-initialize extended structure */ _yada->_mod->env = NULL; _yada->_mod->err = NULL; _yada->_mod->srv = NULL; _yada->_mod->ctx = NULL; _yada->_mod->ses = NULL; _yada->errmsg = _yada->_priv->errbuf; }
/* ** Close a Connection object. */ static int conn_close (lua_State *L) { env_data *env; conn_data *conn = (conn_data *)luaL_checkudata (L, 1, LUASQL_CONNECTION_OCI8); luaL_argcheck (L, conn != NULL, 1, LUASQL_PREFIX"connection expected"); if (conn->closed) { lua_pushboolean (L, 0); return 1; } if (conn->cur_counter > 0) return luaL_error (L, LUASQL_PREFIX"there are open cursors"); /* Nullify structure fields. */ conn->closed = 1; if (conn->svchp) { if (conn->loggedon) OCILogoff (conn->svchp, conn->errhp); else OCIHandleFree ((dvoid *)conn->svchp, OCI_HTYPE_SVCCTX); } if (conn->errhp) OCIHandleFree ((dvoid *)conn->errhp, OCI_HTYPE_ERROR); /* Decrement connection counter on environment object */ lua_rawgeti (L, LUA_REGISTRYINDEX, conn->env); env = lua_touserdata (L, -1); env->conn_counter--; luaL_unref (L, LUA_REGISTRYINDEX, conn->env); lua_pushboolean (L, 1); return 1; }
OGROCISession::~OGROCISession() { if( hDescribe != NULL ) OCIHandleFree((dvoid *)hDescribe, (ub4)OCI_HTYPE_DESCRIBE); if( hSvcCtx != NULL ) { OCISessionEnd(hSvcCtx, hError, hSession, (ub4) 0); if( hSvcCtx && hError) OCIServerDetach(hServer, hError, (ub4) OCI_DEFAULT); if( hServer ) OCIHandleFree((dvoid *) hServer, (ub4) OCI_HTYPE_SERVER); if( hSvcCtx ) OCIHandleFree((dvoid *) hSvcCtx, (ub4) OCI_HTYPE_SVCCTX); if( hError ) OCIHandleFree((dvoid *) hError, (ub4) OCI_HTYPE_ERROR); if( hSession ) OCIHandleFree((dvoid *) hSession, (ub4) OCI_HTYPE_SESSION); } CPLFree( pszUserid ); CPLFree( pszPassword ); CPLFree( pszDatabase ); }
gboolean oracle_session_close (GSQLSession *session, gchar *buffer) { GSQL_TRACE_FUNC; /* End session and detach from server */ GSQLEOracleSession *o_session; o_session = (GSQLEOracleSession *) session->spec; gsql_session_close (session); OCISessionEnd (o_session->svchp, o_session->errhp, o_session->usrhp, OCI_DEFAULT); OCIServerDetach (o_session->srvhp, o_session->errhp, OCI_DEFAULT); OCIHandleFree ((dvoid *)o_session->errhp, OCI_HTYPE_ERROR); OCIHandleFree ((dvoid *)o_session->srvhp, OCI_HTYPE_SERVER); OCIHandleFree ((dvoid *)o_session->svchp, OCI_HTYPE_SVCCTX); OCIHandleFree ((dvoid *)o_session->usrhp, OCI_HTYPE_SESSION); OCIHandleFree ((dvoid *)o_session->envhp, OCI_HTYPE_ENV); g_free(o_session); return TRUE; }
static int o_shutdown (void) /* {{{ */ { size_t i; for (i = 0; i < databases_num; i++) if (databases[i]->oci_service_context != NULL) { OCIHandleFree (databases[i]->oci_service_context, OCI_HTYPE_SVCCTX); databases[i]->oci_service_context = NULL; } for (i = 0; i < queries_num; i++) { OCIStmt *oci_statement; oci_statement = udb_query_get_user_data (queries[i]); if (oci_statement != NULL) { OCIHandleFree (oci_statement, OCI_HTYPE_STMT); udb_query_set_user_data (queries[i], NULL); } } OCIHandleFree (oci_env, OCI_HTYPE_ENV); oci_env = NULL; udb_query_free (queries, queries_num); queries = NULL; queries_num = 0; return (0); } /* }}} int o_shutdown */
void FreeHandles() { OCIHandleFree(hser, OCI_HTYPE_SERVER); OCIHandleFree(herr, OCI_HTYPE_ERROR); OCIHandleFree(husr, OCI_HTYPE_SESSION); OCIHandleFree(hsvc, OCI_HTYPE_SVCCTX); OCIHandleFree(hsql, OCI_HTYPE_STMT); }
void _sessionDelete(unsigned int i) { std::map<uint32_t, sessionInfo*>::iterator pos = _sessions.find(i); if(pos != _sessions.end()) { sessionInfo *obj = pos->second; OCIHandleFree (obj->errhp, OCI_HTYPE_ERROR); OCIHandleFree (obj->srvhp, OCI_HTYPE_SERVER); OCIHandleFree (obj->svchp, OCI_HTYPE_SVCCTX); OCIHandleFree (obj->authp, OCI_HTYPE_SESSION); OCIHandleFree (obj->envhp, OCI_HTYPE_ENV); obj->errhp = 0; obj->srvhp = 0; obj->svchp = 0; obj->authp = 0; obj->envhp = 0; delete obj; _sessions.erase(pos); } }
ResultSet_T OracleConnection_executeQuery(T C, const char *sql, va_list ap) { OCIStmt* stmtp; va_list ap_copy; assert(C); C->rowsChanged = 0; va_copy(ap_copy, ap); StringBuffer_vset(C->sb, sql, ap_copy); va_end(ap_copy); StringBuffer_trim(C->sb); /* Build statement */ C->lastError = OCIHandleAlloc(C->env, (void **)&stmtp, OCI_HTYPE_STMT, 0, NULL); if (C->lastError != OCI_SUCCESS && C->lastError != OCI_SUCCESS_WITH_INFO) return NULL; C->lastError = OCIStmtPrepare(stmtp, C->err, StringBuffer_toString(C->sb), StringBuffer_length(C->sb), OCI_NTV_SYNTAX, OCI_DEFAULT); if (C->lastError != OCI_SUCCESS && C->lastError != OCI_SUCCESS_WITH_INFO) { OCIHandleFree(stmtp, OCI_HTYPE_STMT); return NULL; } /* Execute and create Result Set */ C->lastError = OCIStmtExecute(C->svc, stmtp, C->err, 0, 0, NULL, NULL, OCI_DEFAULT); if (C->lastError != OCI_SUCCESS && C->lastError != OCI_SUCCESS_WITH_INFO) { ub4 parmcnt = 0; OCIAttrGet(stmtp, OCI_HTYPE_STMT, &parmcnt, NULL, OCI_ATTR_PARSE_ERROR_OFFSET, C->err); DEBUG("Error occured in StmtExecute %d (%s), offset is %d\n", C->lastError, OracleConnection_getLastError(C), parmcnt); OCIHandleFree(stmtp, OCI_HTYPE_STMT); return NULL; } C->lastError = OCIAttrGet(stmtp, OCI_HTYPE_STMT, &C->rowsChanged, 0, OCI_ATTR_ROW_COUNT, C->err); if (C->lastError != OCI_SUCCESS && C->lastError != OCI_SUCCESS_WITH_INFO) DEBUG("OracleConnection_execute: Error in OCIAttrGet %d (%s)\n", C->lastError, OracleConnection_getLastError(C)); return ResultSet_new(OracleResultSet_new(stmtp, C->env, C->usr, C->err, C->svc, true, C->maxRows), (Rop_T)&oraclerops); }
int main(int argc, char *argv[]) { OCIError *errhp = NULL; printf("stage4: Demonstrating OCI statement caching \n"); /* parse command line options */ parse_options(argc, argv); checkenv(envhp, OCIEnvCreate(&envhp, /* returned env handle */ OCI_THREADED, /* initialization modes */ NULL, NULL, NULL, NULL, /* callbacks, context */ (size_t) 0, /* extra memory size: optional */ (void **) NULL)); /* returned extra memory */ /* 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 */ create_session_pool(envhp, errhp, &poolName, &poolNameLen); /* allocate auth handle * note: for OCIHandleAlloc(), we check error on environment handle */ checkenv(envhp, OCIHandleAlloc(envhp, (void **) &authp, OCI_HTYPE_AUTHINFO, (size_t) 0, (void **) NULL)); /* setup username and password */ checkerr(errhp, OCIAttrSet(authp, OCI_HTYPE_AUTHINFO, (void *) username, strlen((char *)username), OCI_ATTR_USERNAME, errhp)); checkerr(errhp, OCIAttrSet(authp, OCI_HTYPE_AUTHINFO, apppassword, strlen((char *) apppassword), OCI_ATTR_PASSWORD, errhp)); spawn_threads(envhp, errhp, &thread_function); /* Destroy the session pool */ OCISessionPoolDestroy(spoolhp, errhp, OCI_DEFAULT); /* clean up */ if (authp) OCIHandleFree(authp, OCI_HTYPE_AUTHINFO); if (spoolhp) OCIHandleFree(spoolhp, OCI_HTYPE_SPOOL); if (errhp) OCIHandleFree(errhp, OCI_HTYPE_ERROR); if (envhp) OCIHandleFree(envhp, OCI_HTYPE_ENV); return 0; }
/* ** Execute an SQL statement. ** Return a Cursor object if the statement is a query, otherwise ** return the number of tuples affected by the statement. */ static int conn_execute (lua_State *L) { env_data *env; conn_data *conn = getconnection (L); const char *statement = luaL_checkstring (L, 2); sword status; ub4 prefetch = 0; ub4 iters; ub4 mode; ub2 type; OCIStmt *stmthp; /* get environment */ lua_rawgeti (L, LUA_REGISTRYINDEX, conn->env); if (!lua_isuserdata (L, -1)) luaL_error(L,LUASQL_PREFIX"invalid environment in connection!"); env = (env_data *)lua_touserdata (L, -1); /* statement handle */ ASSERT (L, OCIHandleAlloc ((dvoid *)env->envhp, (dvoid **)&stmthp, OCI_HTYPE_STMT, (size_t)0, (dvoid **)0), conn->errhp); ASSERT (L, OCIAttrSet ((dvoid *)stmthp, (ub4)OCI_HTYPE_STMT, (dvoid *)&prefetch, (ub4)0, (ub4)OCI_ATTR_PREFETCH_ROWS, conn->errhp), conn->errhp); ASSERT (L, OCIStmtPrepare (stmthp, conn->errhp, (text *)statement, (ub4) strlen(statement), (ub4) OCI_NTV_SYNTAX, (ub4) OCI_DEFAULT), conn->errhp); /* statement type */ ASSERT (L, OCIAttrGet ((dvoid *)stmthp, (ub4) OCI_HTYPE_STMT, (dvoid *)&type, (ub4 *)0, (ub4)OCI_ATTR_STMT_TYPE, conn->errhp), conn->errhp); if (type == OCI_STMT_SELECT) iters = 0; else iters = 1; if (conn->auto_commit) mode = OCI_COMMIT_ON_SUCCESS; else mode = OCI_DEFAULT; /* execute statement */ status = OCIStmtExecute (conn->svchp, stmthp, conn->errhp, iters, (ub4)0, (CONST OCISnapshot *)NULL, (OCISnapshot *)NULL, mode); if (status && (status != OCI_NO_DATA)) { OCIHandleFree ((dvoid *)stmthp, OCI_HTYPE_STMT); return checkerr (L, status, conn->errhp); } if (type == OCI_STMT_SELECT) { /* create cursor */ return create_cursor (L, 1, conn, stmthp, statement); } else { /* return number of rows */ int rows_affected; ASSERT (L, OCIAttrGet ((dvoid *)stmthp, (ub4)OCI_HTYPE_STMT, (dvoid *)&rows_affected, (ub4 *)0, (ub4)OCI_ATTR_ROW_COUNT, conn->errhp), conn->errhp); OCIHandleFree ((dvoid *)stmthp, OCI_HTYPE_STMT); lua_pushnumber (L, rows_affected); return 1; } }
/* Freeing the allocated handles */ static void cleanup () { OCISessionEnd (svchp, errhp, sesnhp, OCI_DEFAULT ); OCIHandleFree((dvoid *) sesnhp, OCI_HTYPE_SESSION); OCIServerDetach(svrhp, errhp, OCI_DEFAULT ); OCIHandleFree((dvoid *) svrhp, OCI_HTYPE_SERVER); OCIHandleFree((dvoid *) svchp, OCI_HTYPE_SVCCTX); OCIHandleFree((dvoid *) errhp, OCI_HTYPE_ERROR); return; }/* End of cleanup() */
~connection() { OCISessionEnd(svcctx, error, session, OCI_DEFAULT); OCIServerDetach(server, error, OCI_DEFAULT); OCIHandleFree(session, OCI_HTYPE_SESSION); OCIHandleFree(svcctx, OCI_HTYPE_SVCCTX); OCIHandleFree(error, OCI_HTYPE_ERROR); OCIHandleFree(server, OCI_HTYPE_SERVER); }
void zbx_db_close() { #if defined(HAVE_IBM_DB2) if (ibm_db2.hdbc) { SQLDisconnect(ibm_db2.hdbc); SQLFreeHandle(SQL_HANDLE_DBC, ibm_db2.hdbc); } if (ibm_db2.henv) SQLFreeHandle(SQL_HANDLE_ENV, ibm_db2.henv); memset(&ibm_db2, 0, sizeof(ibm_db2)); #elif defined(HAVE_MYSQL) mysql_close(conn); conn = NULL; #elif defined(HAVE_ORACLE) /* deallocate statement handle */ if (NULL != oracle.stmthp) { OCIHandleFree((dvoid *)oracle.stmthp, OCI_HTYPE_STMT); oracle.stmthp = NULL; } if (NULL != oracle.svchp) { OCILogoff(oracle.svchp, oracle.errhp); oracle.svchp = NULL; } if (NULL != oracle.errhp) { OCIHandleFree(oracle.errhp, OCI_HTYPE_ERROR); oracle.errhp = NULL; } if (NULL != oracle.envhp) { OCIHandleFree((dvoid *)oracle.envhp, OCI_HTYPE_ENV); oracle.envhp = NULL; } if (NULL != oracle.srvhp) { OCIHandleFree(oracle.srvhp, OCI_HTYPE_SERVER); oracle.srvhp = NULL; } #elif defined(HAVE_POSTGRESQL) PQfinish(conn); conn = NULL; #elif defined(HAVE_SQLITE3) sqlite3_close(conn); conn = NULL; #endif }
void FC_FUNC_(oraclesim_delete, ORACLESIM_DELETE) (OracleDbConnection **fdbconnid) { OracleDbConnection *dbconnid = *fdbconnid; if (dbconnid != NULL) { if (dbconnid->svchp != NULL) OCILogoff(dbconnid->svchp, dbconnid->errhp); if (dbconnid->stmthp != NULL) OCIHandleFree(dbconnid->stmthp, OCI_HTYPE_STMT); if (dbconnid->errhp != NULL) OCIHandleFree(dbconnid->errhp, OCI_HTYPE_ERROR); if (dbconnid->envhp != NULL) OCIHandleFree(dbconnid->envhp, OCI_HTYPE_ENV); free(dbconnid); } *fdbconnid = 0; }
void OraSession::endSession() { sword status; status = OCIHandleFree((dvoid *)ociHandles.stmthp, (ub4)OCI_HTYPE_STMT); status = OCISessionEnd(ociHandles.svchp, ociHandles.errhp, ociHandles.usrhp, (ub4)OCI_DEFAULT); status = OCIServerDetach(ociHandles.srvhp, ociHandles.errhp, (ub4)OCI_DEFAULT ); status = OCIHandleFree((dvoid *)ociHandles.srvhp, (ub4)OCI_HTYPE_SERVER); status = OCIHandleFree((dvoid *)ociHandles.svchp, (ub4)OCI_HTYPE_SVCCTX); status = OCIHandleFree((dvoid *)ociHandles.errhp, (ub4)OCI_HTYPE_ERROR); connectedUser = ""; }
static void oci8_svcctx_free(oci8_base_t *base) { oci8_svcctx_t *svcctx = (oci8_svcctx_t *)base; if (svcctx->authhp) { OCIHandleFree(svcctx->authhp, OCI_HTYPE_SESSION); svcctx->authhp = NULL; } if (svcctx->srvhp) { OCIHandleFree(svcctx->srvhp, OCI_HTYPE_SERVER); svcctx->srvhp = NULL; } }
static void oracle_close_conn(void *theconn) { struct ora_conn *conn = (struct ora_conn*) theconn; gw_assert(conn != NULL); if (conn->svchp != NULL) oracle_checkerr(conn->errhp, OCILogoff(conn->svchp, conn->errhp)); OCIHandleFree(conn->errhp, OCI_HTYPE_ERROR); OCIHandleFree(conn->envp, OCI_HTYPE_ENV); /* OCITerminate(OCI_DEFAULT); */ gw_free(conn); }
int COracleDB::oracle_close( void ) { ORACLE_HANDLE* handle = ( ORACLE_HANDLE* ) _handle; if ( handle == NULL ) return DB_ERR_SUCCESS; int status; if ( handle->svchp != NULL ) { while ( ( status = OCISessionEnd( handle->svchp, handle->errhp, handle->authp, OCI_DEFAULT ) ) == OCI_STILL_EXECUTING ) { my_usleep(); } } if ( handle->srvhp != NULL ) { while ( ( status = OCIServerDetach( handle->srvhp, handle->errhp, OCI_DEFAULT ) ) == OCI_STILL_EXECUTING ) { my_usleep(); } } if ( handle->envhp != NULL ) { OCIHandleFree( ( dvoid * ) ( handle->envhp ), OCI_HTYPE_ENV ); } if ( handle != NULL ) { delete handle; handle = NULL; } return 0; }
static VALUE ensure_func(cb_arg_t *arg) { if (arg->stmtp != NULL) { OCIHandleFree(arg->stmtp, OCI_HTYPE_STMT); } return Qnil; }
void qdbl_oracle_session_stop(struct QdblOracleConnection* self) { /* variables */ sword status; status = OCISessionEnd(self->ocicontext, self->ocierr, self->ocisession, OCI_DEFAULT); qdbl_oracle_error(self->ocierr, status, self->logger, "end session"); /* release resources */ OCIHandleFree(self->ocisession, OCI_HTYPE_SESSION); self->ocisession = 0; OCIHandleFree(self->ocicontext, OCI_HTYPE_SVCCTX); self->ocicontext = 0; }
/* in zbxdb.h - #define DBfree_result OCI_DBfree_result */ void OCI_DBfree_result(DB_RESULT result) { if (NULL == result) return; if (NULL != result->values) { int i; for (i = 0; i < result->ncolumn; i++) { zbx_free(result->values[i]); /* deallocate the lob locator variable */ if (NULL != result->clobs[i]) { OCIDescriptorFree((dvoid *)result->clobs[i], OCI_DTYPE_LOB); result->clobs[i] = NULL; } } zbx_free(result->values); zbx_free(result->clobs); zbx_free(result->values_alloc); } if (result->stmthp) OCIHandleFree((dvoid *)result->stmthp, OCI_HTYPE_STMT); zbx_free(result); }
void Statement::Cleanup() { if(m_stmtHandle != NULL) { OCIHandleFree(m_stmtHandle, OCI_HTYPE_STMT); m_stmtHandle = NULL; } }
/* * This private function is responsible for freeing * globally allocated OCI handles. */ static void free_global_handles() { if(hp_env) OCIHandleFree(hp_env, OCI_HTYPE_ENV); if(hp_server) OCIHandleFree(hp_server, OCI_HTYPE_SERVER); if(hp_session) OCIHandleFree(hp_session, OCI_HTYPE_SESSION); if(hp_service) OCIHandleFree(hp_service, OCI_HTYPE_SVCCTX); /* keep it clean */ hp_env = NULL; hp_server = NULL; hp_session = NULL; hp_service = NULL; }
void OraclePreparedStatement_free(T *P) { assert(P && *P); OCIHandleFree((*P)->stmt, OCI_HTYPE_STMT); if ((*P)->params) { // (*P)->params[i].bind is freed implicitly when the statement handle is deallocated FREE((*P)->params); } FREE(*P); }
ocisession::ocisession(const char * connect_str, const int connect_str_len, const char * user_name, const int user_name_len, const char * password, const int password_len) { intf_ret r; OCIAuthInfo *authp = NULL; init(); r.handle = envhp; // allocate error handle checkenv(&r, OCIHandleAlloc((OCIEnv*)envhp, /* environment handle */ (void **) &_errhp, /* returned err handle */ OCI_HTYPE_ERROR, /* typ of handle to allocate */ (size_t) 0, /* optional extra memory size */ (void **) NULL)); /* returned extra memeory */ if(r.fn_ret != SUCCESS) { REMOTE_LOG("failed OCISessionGet %s\n", r.gerrbuf); throw r; } // allocate auth handle checkenv(&r, OCIHandleAlloc((OCIEnv*)envhp, (void**)&authp, OCI_HTYPE_AUTHINFO, (size_t)0, (void **) NULL)); r.handle = _errhp; // usrname and password checkerr(&r, OCIAttrSet(authp, OCI_HTYPE_AUTHINFO, (void*) user_name, user_name_len, OCI_ATTR_USERNAME, (OCIError *)_errhp)); checkerr(&r, OCIAttrSet(authp, OCI_HTYPE_AUTHINFO, (void*) password, password_len, OCI_ATTR_PASSWORD, (OCIError *)_errhp)); /* get the database connection */ checkerr(&r, OCISessionGet((OCIEnv*)envhp, (OCIError *)_errhp, (OCISvcCtx**)&_svchp, /* returned database connection */ authp, /* initialized authentication handle */ (OraText *) connect_str, connect_str_len,/* connect string */ NULL, 0, NULL, NULL, NULL, /* session tagging parameters: optional */ OCI_SESSGET_STMTCACHE)); /* modes */ if(r.fn_ret != SUCCESS) { REMOTE_LOG("failed OCISessionGet %s\n", r.gerrbuf); throw r; } (void) OCIHandleFree(authp, OCI_HTYPE_AUTHINFO); REMOTE_LOG("got session %p\n", _svchp); _sessions.push_back(this); }
void EnvImpl::cleanup() { if (envh_) { OCIHandleFree(envh_, OCI_HTYPE_ENV); envh_ = NULL; // reproducible seg-faults in case someone uses // a deleted Env } }
/* ODCIIndexClose function */ OCINumber *qxiqtbspc( OCIExtProcContext *ctx, qxiqtim *self, qxiqtin *self_ind, ODCIEnv *env, ODCIEnv_ind *env_ind) { sword status; OCIEnv *envhp = (OCIEnv *) 0; /* env. handle */ OCISvcCtx *svchp = (OCISvcCtx *) 0; /* service handle */ OCIError *errhp = (OCIError *) 0; /* error handle */ OCISession *usrhp = (OCISession *) 0; /* user handle */ qxiqtcx *icx = (qxiqtcx *) 0; /* state to be saved for later calls */ int retval = (int) ODCI_SUCCESS; OCINumber *rval = (OCINumber *)0; ub1 *key; /* key to retrieve context */ ub4 keylen; /* length of key */ if (qxiqtce(ctx, errhp, OCIExtProcGetEnv(ctx, &envhp, &svchp, &errhp))) return(rval); /* set up return code */ rval = (OCINumber *)OCIExtProcAllocCallMemory(ctx, sizeof(OCINumber)); if (qxiqtce(ctx, errhp, OCINumberFromInt(errhp, (dvoid *)&retval, sizeof(retval), OCI_NUMBER_SIGNED, rval))) return(rval); /* get the user handle */ if (qxiqtce(ctx, errhp, OCIAttrGet((dvoid *)svchp, (ub4)OCI_HTYPE_SVCCTX, (dvoid *)&usrhp, (ub4 *)0, (ub4)OCI_ATTR_SESSION, errhp))) return(rval); /********************************/ /* Retrieve context using key */ /********************************/ key = OCIRawPtr(envhp, self->sctx_qxiqtim); keylen = OCIRawSize(envhp, self->sctx_qxiqtim); if (qxiqtce(ctx, errhp, OCIContextGetValue((dvoid *)usrhp, errhp, key, (ub1)keylen, (dvoid **)&(icx)))) return(rval); /* Free handles and memory */ if (qxiqtce(ctx, errhp, OCIHandleFree((dvoid *)icx->stmthp, (ub4)OCI_HTYPE_STMT))) return(rval); if (qxiqtce(ctx, errhp, OCIMemoryFree((dvoid *)usrhp, errhp, (dvoid *)icx))) return(rval); return(rval); }
/* * Close the connection and release memory */ void db_oracle_free_connection(ora_con_t* con) { if (!con) return; if (con->connected) db_oracle_disconnect(con); if (con->svchp) OCIHandleFree(con->svchp, OCI_HTYPE_SVCCTX); if (con->authp) OCIHandleFree(con->authp, OCI_HTYPE_SESSION); if (con->srvhp) OCIHandleFree(con->srvhp, OCI_HTYPE_SERVER); if (con->errhp) OCIHandleFree(con->errhp, OCI_HTYPE_ERROR); if (con->envhp) OCIHandleFree(con->envhp, OCI_HTYPE_ENV); pkg_free(con); }
/* ** Close environment object. */ static int env_close (lua_State *L) { env_data *env = (env_data *)luaL_checkudata (L, 1, LUASQL_ENVIRONMENT_OCI8); luaL_argcheck (L, env != NULL, 1, LUASQL_PREFIX"environment expected"); if (env->closed) { lua_pushboolean (L, 0); return 1; } if (env->conn_counter > 0) return luaL_error (L, LUASQL_PREFIX"there are open connections"); env->closed = 1; /* desalocar: env->errhp e env->envhp */ if (env->envhp) OCIHandleFree ((dvoid *)env->envhp, OCI_HTYPE_ENV); if (env->errhp) OCIHandleFree ((dvoid *)env->errhp, OCI_HTYPE_ERROR); lua_pushboolean (L, 1); return 1; }