Example #1
0
COracleDB::~COracleDB( )
{
	if ( _handle != NULL ) {
		oracle_close();
		_handle = NULL;
	}
}
Example #2
0
void CdbHandler::oracleClose(void)
{
	oracle_close(oracleQuery_);
};
Example #3
0
void* COracleDB::oracle_connect( const char* addr, const unsigned short port, const char *user, const char* pass,
		const char* db_name )
{
	char service[256] = {0};
	sprintf( service, "//%s:%d/%s", addr, port, db_name );

	ORACLE_HANDLE* handle = new ORACLE_HANDLE;

	memset( handle, 0, sizeof(ORACLE_HANDLE) );

	int status = 0;

	OCIEnvCreate( ( OCIEnv ** ) & ( handle->envhp ), ( ub4 ) OCI_THREADED, ( dvoid * ) 0,
			( dvoid * (*)( dvoid *, size_t )) 0, (dvoid * (*)(dvoid *, dvoid *, size_t))0,
			(void (*)(dvoid *, dvoid *)) 0 , (size_t) 0, (dvoid **) 0 );

	( void ) OCIHandleAlloc( ( dvoid * ) ( handle->envhp ), ( dvoid ** ) & ( handle->errhp ), OCI_HTYPE_ERROR,
			( size_t ) 0, ( dvoid ** ) 0 );

	/* server contexts */
	( void ) OCIHandleAlloc( ( dvoid * ) ( handle->envhp ), ( dvoid ** ) & ( handle->srvhp ), OCI_HTYPE_SERVER,
			( size_t ) 0, ( dvoid ** ) 0 );

	// service context
	( void ) OCIHandleAlloc( ( dvoid * ) ( handle->envhp ), ( dvoid ** ) & ( handle->svchp ), OCI_HTYPE_SVCCTX,
			( size_t ) 0, ( dvoid ** ) 0 );

	status = OCIServerAttach( handle->srvhp, handle->errhp, ( text * ) service, strlen( ( const char * ) service ), 0 );

	status = checkerr( handle->errhp, status, _errinfo );

	if ( status != 0 ) {
		_handle = handle;
		oracle_close();
		_handle = NULL;

		return NULL;
	}

	/* set attribute server context in the service context */
	OCIAttrSet( ( dvoid * ) handle->svchp, OCI_HTYPE_SVCCTX, ( dvoid * ) handle->srvhp, ( ub4 ) 0, OCI_ATTR_SERVER,
			( OCIError * ) handle->errhp );

	OCIHandleAlloc( ( dvoid * ) handle->envhp, ( dvoid ** ) & ( handle->authp ), ( ub4 ) OCI_HTYPE_SESSION,
			( size_t ) 0, ( dvoid ** ) 0 );

	( void ) OCIAttrSet( ( dvoid * ) handle->authp, ( ub4 ) OCI_HTYPE_SESSION, ( dvoid * ) user,
			( ub4 ) strlen( ( char * ) user ), ( ub4 ) OCI_ATTR_USERNAME, handle->errhp );

	OCIAttrSet( ( dvoid * ) handle->authp, ( ub4 ) OCI_HTYPE_SESSION, ( dvoid * ) pass,
			( ub4 ) strlen( ( char * ) pass ), ( ub4 ) OCI_ATTR_PASSWORD, handle->errhp );

	status = OCISessionBegin( handle->svchp, handle->errhp, handle->authp, OCI_CRED_RDBMS, ( ub4 ) OCI_DEFAULT );

	status = checkerr( handle->errhp, status, _errinfo );

	if ( status != 0 ) {
		_handle = handle;
		oracle_close();
		_handle = NULL;

		return NULL;
	}

	status = OCIAttrSet( ( dvoid * ) ( handle->svchp ), ( ub4 ) OCI_HTYPE_SVCCTX, ( dvoid * ) ( handle->authp ),
			( ub4 ) 0, ( ub4 ) OCI_ATTR_SESSION, handle->errhp );

	status = checkerr( handle->errhp, status, _errinfo );

	if ( status ) {
		_handle = handle;
		oracle_close();
		_handle = NULL;

		return NULL;
	}

	status = OCIHandleAlloc( ( dvoid * ) ( handle->envhp ), ( dvoid ** ) & ( handle->stmthp ), OCI_HTYPE_STMT,
			( size_t ) 0, ( dvoid ** ) 0 );

	status = checkerr( handle->errhp, status, _errinfo );

	if ( status ) {
		_handle = handle;
		oracle_close();
		_handle = NULL;

		return NULL;
	}

	/*
	 OCIAttrSet ( handle->srvhp, (ub4) OCI_HTYPE_SERVER,
	 (dvoid *) 0, (ub4) 0,
	 (ub4) OCI_ATTR_NONBLOCKING_MODE, handle->errhp) ;
	 */
	return ( void* ) handle;

}