/* * Disconnect from the database */ int ODBC_Disconnect (void) { #if (ODBCVER < 0x0300) if (hstmt) SQLFreeStmt (hstmt, SQL_DROP); if (connected) SQLDisconnect (hdbc); if (hdbc) SQLFreeConnect (hdbc); if (henv) SQLFreeEnv (henv); #else if (hstmt) { SQLCloseCursor (hstmt); SQLFreeHandle (SQL_HANDLE_STMT, hstmt); } if (connected) SQLDisconnect (hdbc); if (hdbc) SQLFreeHandle (SQL_HANDLE_DBC, hdbc); if (henv) SQLFreeHandle (SQL_HANDLE_ENV, henv); #endif return 0; }
// Free the statement handle, disconnect, free the connection handle, and // free the environment handle. void direxec::sqldisconn(void) { SQLFreeStmt(hstmt,SQL_DROP); SQLDisconnect(hdbc); SQLFreeConnect(hdbc); SQLFreeEnv(henv); }
// Allocate environment handle, allocate connection handle, // connect to data source, and allocate statement handle. bool direxec::sqlconn(FILE* file) { logFile = file; unsigned int timeout = 10; // seconds SQLAllocEnv(&henv); SQLAllocConnect(henv,&hdbc); SQLSetConnectAttr(hdbc, SQL_LOGIN_TIMEOUT, &timeout, 0); rc=SQLConnect(hdbc,chr_ds_name,SQL_NTS,NULL,0,NULL,0); // Deallocate handles, display error message, and exit. if (!MYSQLSUCCESS(rc)) { SQLCHAR SqlState[6]; SQLINTEGER NativeError; SQLSMALLINT MsgLen; SQLGetDiagRec(SQL_HANDLE_DBC, hdbc, 1, SqlState, &NativeError, (unsigned char *) szData, 2048, &MsgLen); SQLFreeEnv(henv); SQLFreeConnect(hdbc); fprintf(logFile, "! Error while connecting to database: %s\n", szData); errorstate = TRUE; return FALSE; } rc=SQLAllocStmt(hdbc,&hstmt); errorstate = FALSE; return TRUE; }
void DataBase::disconnect() { SQLFreeStmt(_hStmt, SQL_DROP); SQLDisconnect(_hConn); SQLFreeConnect(_hConn); SQLFreeEnv(_hEnv); }
/* Disconnect from the DBMS. */ int cllDisconnect(icatSessionStruct *icss) { RETCODE stat; HDBC myHdbc; int i; myHdbc = icss->connectPtr; i = cllCheckPending("", 1, icss->databaseType); if (i==1) { i = cllExecSqlNoResult(icss, "commit"); /* auto commit any pending SQLs, including the Audit ones */ /* Nothing to do if it fails */ } stat = SQLDisconnect(myHdbc); if (stat != SQL_SUCCESS) { rodsLog(LOG_ERROR, "cllDisconnect: SQLDisconnect failed: %d", stat); return(-1); } stat = SQLFreeConnect(myHdbc); if (stat != SQL_SUCCESS) { rodsLog(LOG_ERROR, "cllDisconnect: SQLFreeConnect failed: %d", stat); return(-2); } icss->connectPtr = myHdbc; return(0); }
TF EXPFUNC p_db_disconnect(ENGid eid) { HDBC hdbc; g_lsRC = lsGetParm(eid, 1, cADDR, &hdbc); if (g_lsRC != OK) goto LS_ERROR; /* set up error handler */ g_hDBC = hdbc; g_hSTMT = SQL_NULL_HSTMT; g_eid = eid; g_RC = SQLDisconnect(hdbc); ERROR_CHK("SQLDisconnect"); g_RC = SQLFreeConnect(hdbc); ERROR_CHK("SQLFreeConnect"); errchk("lsODBC"); return TRUE; LS_ERROR: return(lserror()); ODBC_ERROR: return FALSE; }
void odbc_destroyconn(SQLCONN* conn) { SQLDisconnect(((ODBC_CONN*)conn)->conn); SQLFreeConnect(((ODBC_CONN*)conn)->conn); SQLFreeEnv(((ODBC_CONN*)conn)->henv); }
void close_handles() { if (SQL_NULL_HDBC != H_DBC) { SQLDisconnect(H_DBC); SQLFreeConnect(H_DBC); } if (SQL_NULL_HDBC != H_DBC2) { SQLDisconnect(H_DBC2); SQLFreeConnect(H_DBC2); } if (SQL_NULL_HENV != H_ENV) { SQLFreeEnv(H_ENV); } if (NULL != DB3_UD) { sqlite3_close(DB3_UD); } }
int cezdb::Connect( char *dsn, int mode ) { RETCODE res; if ( flag != CEZDB_MODE_ENVREADY ) return -1; res = SQLAllocConnect( henv, &hdbc ); if ( res != SQL_SUCCESS ) { flag = CEZDB_MODE_ERROR; return -2; } switch( mode ) { case 1: res = SQLDriverConnect( hdbc, 0, (unsigned char *)dsn, SQL_NTS, StringOut, CEZDB_OUTBUFSIZE, NULL, SQL_DRIVER_COMPLETE_REQUIRED ); break; // case 2: // res = SQLBrowseConnect( hdbc,(unsigned char *)dsn, SQL_NTS,StringOut, CEZDB_OUTBUFSIZE, &len ); default: res = SQLDriverConnect( hdbc, 0, (unsigned char *)dsn, SQL_NTS, StringOut, CEZDB_OUTBUFSIZE, NULL, SQL_DRIVER_NOPROMPT ); break; } if ( res != SQL_SUCCESS ) { SQLFreeConnect( hdbc ); flag = CEZDB_MODE_ERROR; return -3; } //MessageBox( NULL, (char *)StringOut, "WOW", 0 ); // DBC Ready // flag = CEZDB_MODE_DBCREADY; return 0; }
static HB_GARBAGE_FUNC( hb_SQLHDBC_Destructor ) { /* Retrieve image pointer holder */ PHB_SQLHDBC pHDbc = ( PHB_SQLHDBC ) Cargo; /* Check if pointer is not NULL to avoid multiple freeing */ if( pHDbc->hDbc ) { #if ODBCVER >= 0x0300 SQLFreeHandle( SQL_HANDLE_DBC, ( SQLHANDLE ) pHDbc->hDbc ); #else SQLFreeConnect( pHDbc->hDbc ); #endif /* set pointer to NULL to avoid multiple freeing */ pHDbc->hDbc = NULL; } if( pHDbc->pHEnvItm ) { /* release reference to parent handler */ hb_itemRelease( pHDbc->pHEnvItm ); /* set pointer to NULL to avoid multiple freeing */ pHDbc->pHEnvItm = NULL; } }
CDBConnection::~CDBConnection() { if (hdbc != SQL_NULL_HDBC) { SQLDisconnect (hdbc); SQLFreeConnect (hdbc); } }
void cezdb::Disconnect( void ) { if ( flag >= CEZDB_MODE_DBCREADY ) { if ( flag == CEZDB_MODE_SQLFETCH ) SQLFreeStmt( hstmt, SQL_DROP ); SQLDisconnect( hdbc ); SQLFreeConnect( hdbc ); flag = CEZDB_MODE_ENVREADY; } }
static SQLRETURN fini(SQLHENV henv, SQLHDBC hdbc) { /* clean up - free the connection and environment handles */ SQLDisconnect(hdbc); SQLFreeConnect(hdbc); SQLFreeEnv(henv); return SQL_SUCCESS; }
static int odbc_dispatch9(void) { unsigned long retval; PWord rval; int rtype; PWord arg1; int type1; PWord arg2; int type2; PWord arg3; int type3; PI_getan(&arg1,&type1,1); if (type1 != PI_INT) if (!CI_get_integer((unsigned long *)&arg1,type1)) PI_FAIL; PI_getan(&arg2,&type2,2); if (type2 != PI_INT) if (!CI_get_integer((unsigned long *)&arg2,type2)) PI_FAIL; PI_getan(&arg3,&type3,3); switch(arg1) { case 0: retval = (unsigned long) SQLMoreResults(((SQLHSTMT ) arg2)); break; case 1: retval = (unsigned long) SQLFreeEnv(((SQLHENV ) arg2)); break; case 2: retval = (unsigned long) SQLFreeConnect(((SQLHDBC ) arg2)); break; case 3: retval = (unsigned long) SQLFetch(((SQLHSTMT ) arg2)); break; case 4: retval = (unsigned long) SQLExecute(((SQLHSTMT ) arg2)); break; case 5: retval = (unsigned long) SQLDisconnect(((SQLHDBC ) arg2)); break; case 6: retval = (unsigned long) SQLCloseCursor(((SQLHSTMT ) arg2)); break; case 7: retval = (unsigned long) SQLCancel(((SQLHSTMT ) arg2)); break; case 8: retval = (unsigned long) SQLAllocEnv(((SQLHENV * ) arg2)); break; default: PI_FAIL; } PI_makedouble(&rval,&rtype,(double) retval); if (PI_unify(arg3,type3,rval,rtype)) PI_SUCCEED; PI_FAIL; }
/************************************************************************* * * Function: sql_close * * Purpose: database specific close. Closes an open database * connection and cleans up any open handles. * *************************************************************************/ static int sql_close(rlm_sql_handle_t *handle, UNUSED rlm_sql_config_t *config) { rlm_sql_unixodbc_sock *unixodbc_sock = handle->conn; SQLFreeStmt(unixodbc_sock->stmt_handle, SQL_DROP); SQLDisconnect(unixodbc_sock->dbc_handle); SQLFreeConnect(unixodbc_sock->dbc_handle); SQLFreeEnv(unixodbc_sock->env_handle); return 0; }
static BOOL test_driver_connect (TDSNCHOOSER *choose_t, char *connstr) { HENV henv; HDBC hdbc; #if (ODBCVER < 0x300) if (SQLAllocEnv (&henv) != SQL_SUCCESS) #else if (SQLAllocHandle (SQL_HANDLE_ENV, NULL, &henv) != SQL_SUCCESS) #endif { _iodbcdm_nativeerrorbox (choose_t->mainwnd, henv, SQL_NULL_HDBC, SQL_NULL_HSTMT); return FALSE; } #if (ODBCVER < 0x300) if (SQLAllocConnect (henv, &hdbc) != SQL_SUCCESS) #else SQLSetEnvAttr (henv, SQL_ATTR_ODBC_VERSION, (SQLPOINTER) SQL_OV_ODBC3, SQL_IS_UINTEGER); if (SQLAllocHandle (SQL_HANDLE_DBC, henv, &hdbc) != SQL_SUCCESS) #endif { _iodbcdm_nativeerrorbox (choose_t->mainwnd, henv, hdbc, SQL_NULL_HSTMT); SQLFreeEnv (henv); return FALSE; } SQLSetConfigMode (ODBC_BOTH_DSN); if (SQLDriverConnect (hdbc, choose_t->mainwnd, connstr, SQL_NTS, NULL, 0, NULL, SQL_DRIVER_PROMPT) != SQL_SUCCESS) { _iodbcdm_nativeerrorbox (choose_t->mainwnd, henv, hdbc, SQL_NULL_HSTMT); SQLFreeEnv (henv); return FALSE; } else { SQLDisconnect (hdbc); } #if (ODBCVER < 0x300) SQLFreeConnect (hdbc); SQLFreeEnv (henv); #else SQLFreeHandle (SQL_HANDLE_DBC, hdbc); SQLFreeHandle (SQL_HANDLE_ENV, henv); #endif return TRUE; }
TODBCConn::~TODBCConn () { if (m_hStmt != SQL_NULL_HSTMT) SQLFreeStmt (m_hStmt, SQL_DROP); if (m_hDbc != SQL_NULL_HDBC) { SQLDisconnect (m_hDbc); SQLFreeConnect (m_hDbc); } if (m_hEnv) SQLFreeEnv (m_hEnv); }
bool CMssqlConnection::Close() { if(m_hEnv) { SQLDisconnect(m_hDbc); SQLFreeConnect(m_hDbc); SQLFreeEnv(m_hEnv); } m_hEnv = NULL; m_hDbc = NULL; m_lastrsError=L""; return true; }
/*-----------------------------------------------------------------------------*/ void ODBCDisconnect() { struct Cursor *cur = FCursor; struct Cursor *tcur; struct NumberofCursors *numi = FCurNum, *numj = FCurNum; HDBC hdbc = (HDBC)ptoc_int(2); if (!serverConnected) return; if (hdbc == NULL) { /* close entire connection*/ if (FCursor != NULL) xsb_abort("Must close all connections before shutting down"); SQLFreeEnv(henv); serverConnected = 0; return; } /* only free cursors associated with this connection (hdbc)*/ while((numj != NULL) && (numj->hdbc != hdbc)){ if(numj != FCurNum) numi=numi->NCurNum; numj=numj->NCurNum; } if(numj != NULL){ if(numj == FCurNum) FCurNum=numj->NCurNum; else numi->NCurNum=numj->NCurNum; free(numj); } while (cur != NULL) { if (cur->hdbc == hdbc) { tcur = cur->NCursor; if (cur->Status != 0) SetCursorClose(cur); SQLFreeStmt(cur->hstmt,SQL_DROP); if (cur->PCursor) (cur->PCursor)->NCursor = cur->NCursor; else FCursor = cur->NCursor; if (cur->NCursor) (cur->NCursor)->PCursor = cur->PCursor; else LCursor = cur->PCursor; free(cur); /* (num->CursorCount)-- */ cur = tcur; } else cur = cur->NCursor; } SQLDisconnect(hdbc); SQLFreeConnect(hdbc); /* SQLFreeEnv(henv);*/ serverConnected = 0; }
static int _sql_socket_destructor(rlm_sql_unixodbc_conn_t *conn) { DEBUG2("rlm_sql_unixodbc: Socket destructor called, closing socket"); if (conn->stmt) SQLFreeStmt(conn->stmt, SQL_DROP); if (conn->dbc) { SQLDisconnect(conn->dbc); SQLFreeConnect(conn->dbc); } if (conn->env) SQLFreeEnv(conn->env); return 0; }
static HB_ERRCODE odbcDisconnect( SQLDDCONNECTION * pConnection ) { SDDCONN * pSDDConn = ( SDDCONN * ) pConnection->pSDDConn; SQLDisconnect( pSDDConn->hConn ); #if ODBCVER >= 0x0300 SQLFreeHandle( SQL_HANDLE_DBC, pSDDConn->hConn ); SQLFreeHandle( SQL_HANDLE_ENV, pSDDConn->hEnv ); #else SQLFreeConnect( pSDDConn->hConn ); SQLFreeEnv( pSDDConn->hEnv ); #endif hb_xfree( pSDDConn ); return HB_SUCCESS; }
/**************************** * CloseDatabase - cleanup in prep for exiting the program ***************************/ static int CloseDatabase( SQLHENV hEnv, SQLHDBC hDbc ) { SQLDisconnect( hDbc ); if ( version3 ) { SQLFreeHandle( SQL_HANDLE_DBC, hDbc ); SQLFreeHandle( SQL_HANDLE_ENV, hEnv ); } else { SQLFreeConnect( hDbc ); SQLFreeEnv( hEnv ); } return 1; }
static void gsql_close (Database *db) { if (db->connected == 1) { if (db->hdbc) SQLDisconnect (db->hdbc); if (db->hdbc) SQLFreeConnect (db->hdbc); if (db->henv) SQLFreeEnv (db->henv); xfree (db->dsn); } }
void free_handle(SQLHENV &env, SQLHDBC &dbc, int &conn_flag) { if ( conn_flag == 1 ) { /* close connection */ SQLDisconnect( dbc ); } /* free connection handle */ if ( dbc != NULL ) { SQLFreeConnect( dbc ); } if ( env != NULL ) { SQLFreeEnv( env ); } }
static int backsql_close_db_conn( backsql_db_conn *conn ) { Debug( LDAP_DEBUG_TRACE, "==>backsql_close_db_conn()\n", 0, 0, 0 ); /* * Default transact is SQL_ROLLBACK; commit is required only * by write operations, and it is explicitly performed after * each atomic operation succeeds. */ /* TimesTen */ SQLTransact( SQL_NULL_HENV, conn->dbh, SQL_ROLLBACK ); SQLDisconnect( conn->dbh ); SQLFreeConnect( conn->dbh ); Debug( LDAP_DEBUG_TRACE, "<==backsql_close_db_conn()\n", 0, 0, 0 ); return 1; }
CSQLDirect::~CSQLDirect() { SAFE_DELETE(m_psvErrorMsg);///modified by xizheng SAFE_DELETE(m_psvSQL);///modified by xizheng if( m_hStmt!=NULL ) SQLFreeStmt( m_hStmt, SQL_DROP ); if( m_hDBC!=NULL ) { SQLDisconnect( m_hDBC ); SQLFreeConnect( m_hDBC ); } if( m_hEnv!=NULL ) SQLFreeEnv( m_hEnv ); KillCols(); }
static int _sql_socket_destructor(rlm_sql_iodbc_conn_t *conn) { DEBUG2("rlm_sql_iodbc: Socket destructor called, closing socket"); if (conn->stmt_handle) { SQLFreeStmt(conn->stmt_handle, SQL_DROP); } if (conn->dbc_handle) { SQLDisconnect(conn->dbc_handle); SQLFreeConnect(conn->dbc_handle); } if (conn->env_handle) { SQLFreeEnv(conn->env_handle); } return 0; }
CDBConnection::CDBConnection() { RETCODE rc; hdbc = SQL_NULL_HDBC; rc = SQLAllocConnect (henv, &hdbc); if (rc != SQL_SUCCESS) { ReportODBCError (SQL_NULL_HSTMT, "SQLAllocConnect error"); throw rc; } rc = SQLConnect (hdbc, (SQLCHAR *)szDSN, SQL_NTS, (SQLCHAR *)szUID, SQL_NTS, (SQLCHAR *)szPWD, SQL_NTS); if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) { ReportODBCError (SQL_NULL_HSTMT, "SQLConnect error"); SQLFreeConnect (hdbc); hdbc = SQL_NULL_HDBC; throw rc; } }
int odbc_disconnect(void) { if (odbc_stmt) { SQLFreeStmt(odbc_stmt, SQL_DROP); odbc_stmt = SQL_NULL_HSTMT; } if (odbc_conn) { SQLDisconnect(odbc_conn); SQLFreeConnect(odbc_conn); odbc_conn = SQL_NULL_HDBC; } if (odbc_env) { SQLFreeEnv(odbc_env); odbc_env = SQL_NULL_HENV; } return 0; }
static int sql_socket_destructor(void *c) { rlm_sql_unixodbc_conn_t *conn = c; DEBUG2("rlm_sql_sybase: Socket destructor called, closing socket"); if (conn->statement) { SQLFreeStmt(conn->statement, SQL_DROP); } if (conn->dbc) { SQLDisconnect(conn->dbc); SQLFreeConnect(conn->dbc); } if (conn->env) { SQLFreeEnv(conn->env); } return 0; }