OCILIB (C and C++ Driver for Oracle)  4.7.5
Open source and cross platform Oracle Driver delivering efficient access to Oracle databases.
Loading...
Searching...
No Matches
Aborting long operations

Detailed Description

OcilibCApiUserTypes

The Oracle OCI provides the ability to establish a server connection in :

OCILIB implements OCI in blocking mode. The application has to wait for OCI calls to complete to continue.

Some operations can be long to be processed by the server.

In order to cancel the current pending call, OCILIB provides OCI_Break() that cancel the last internal OCI Call and then raise an OCI abortion error code.

Note
Any call to OCI_Break() has to be done from a separate thread because the thread that has executed a long OCI call is waiting for its OCI call to complete.
Example
#include "ocilib.h"
#if defined(_WINDOWS)
#define sleep(x) Sleep(x*1000)
#else
#include <unistd.h>
#endif
void long_oracle_call(OCI_Thread *thread, void *data)
{
clock_t t_start = clock();
int err_code = 0;
if (!OCI_ExecuteStmt((OCI_Statement *)data, "begin dbms_lock.sleep(10); end;"))
{
if (err)
{
err_code = OCI_ErrorGetOCICode(err);
}
}
printf("call duration %d, expected oracle error is 1013, got %d", clock() - t_start, err_code);
}
int main(void)
{
if (!OCI_Initialize(NULL, NULL, OCI_ENV_THREADED | OCI_ENV_CONTEXT))
{
return EXIT_FAILURE;
}
cn = OCI_ConnectionCreate("db", "usr", "pwd", OCI_SESSION_DEFAULT);
OCI_ThreadRun(th, long_oracle_call, st);
sleep(1);
OCI_Break(cn);
return EXIT_SUCCESS;
}
OCI_SYM_PUBLIC boolean OCI_API OCI_Break(OCI_Connection *con)
Perform an immediate abort of any currently Oracle OCI call.
OCI_SYM_PUBLIC boolean OCI_API OCI_ConnectionFree(OCI_Connection *con)
Close a physical connection to an Oracle database server.
OCI_SYM_PUBLIC OCI_Connection *OCI_API OCI_ConnectionCreate(const otext *db, const otext *user, const otext *pwd, unsigned int mode)
Create a physical connection to an Oracle database server.
struct OCI_Thread OCI_Thread
OCILIB encapsulation of OCI Threads.
Definition: types.h:410
struct OCI_Connection OCI_Connection
Oracle physical connection.
Definition: types.h:124
struct OCI_Statement OCI_Statement
Oracle SQL or PL/SQL statement.
Definition: types.h:136
struct OCI_Error OCI_Error
Encapsulates an Oracle or OCILIB exception.
Definition: types.h:390
OCI_SYM_PUBLIC OCI_Error *OCI_API OCI_GetLastError(void)
Retrieve the last error or warning occurred within the last OCILIB call.
OCI_SYM_PUBLIC int OCI_API OCI_ErrorGetOCICode(OCI_Error *err)
Retrieve Oracle Error code from error handle.
OCI_SYM_PUBLIC boolean OCI_API OCI_Cleanup(void)
Clean up all resources allocated by the library.
OCI_SYM_PUBLIC boolean OCI_API OCI_Initialize(POCI_ERROR err_handler, const otext *lib_path, unsigned int mode)
Initialize the library.
OCI_SYM_PUBLIC OCI_Statement *OCI_API OCI_StatementCreate(OCI_Connection *con)
Create a statement object and return its handle.
OCI_SYM_PUBLIC boolean OCI_API OCI_ExecuteStmt(OCI_Statement *stmt, const otext *sql)
Prepare and Execute a SQL statement or PL/SQL block.
OCI_SYM_PUBLIC boolean OCI_API OCI_StatementFree(OCI_Statement *stmt)
Free a statement and all resources associated to it (resultsets ...)
OCI_SYM_PUBLIC boolean OCI_API OCI_ThreadRun(OCI_Thread *thread, POCI_THREAD proc, void *arg)
Execute the given routine within the given thread object.
OCI_SYM_PUBLIC boolean OCI_API OCI_ThreadJoin(OCI_Thread *thread)
Join the given thread.
OCI_SYM_PUBLIC boolean OCI_API OCI_ThreadFree(OCI_Thread *thread)
Destroy a thread object.
OCI_SYM_PUBLIC OCI_Thread *OCI_API OCI_ThreadCreate(void)
Create a Thread object.

Functions

OCI_SYM_PUBLIC boolean OCI_API OCI_Break (OCI_Connection *con)
 Perform an immediate abort of any currently Oracle OCI call.
 

Function Documentation

◆ OCI_Break()

OCI_SYM_PUBLIC boolean OCI_API OCI_Break ( OCI_Connection con)

#include <api.h>

Perform an immediate abort of any currently Oracle OCI call.

Parameters
con- connection handle
Note
The current call will abort and generate an error
Returns
Returns FALSE if connection handle is NULL otherwise TRUE

Referenced by ocilib::Connection::Break().