OCILIB (C Driver for Oracle) 3.12.1
Functions
Aborting long operations

Detailed Description

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 "windows.h"
#include "process.h"
#include "ocilib.h"

/* Example on Microsoft platform */

static HANDLE evt;

void long_oracle_call(void *data)
{
    OCI_Statement *st  = OCI_StatementCreate((OCI_Connection *) data); 
    OCI_Resultset *rs;

    /* execute a query that takes a long time to process */

    OCI_ExecuteStmt(st, "select code, content from huge_table");

    rs = OCI_GetResultset(st);

    while (OCI_FetchNext(rs))
    {
        printf("%i - %s", OCI_GetInt(rs, 1), OCI_GetString(rs, 2));
    }

    SetEvent(evt);
}


int main(void)
{
   OCI_Connection *cn;

   if (!OCI_Initialize(NULL, NULL, OCI_ENV_DEFAULT))
        return EXIT_FAILURE;

    cn = OCI_ConnectionCreate("db", "usr", "pwd", OCI_SESSION_DEFAULT);
    evt = CreateEvent(0, TRUE, FALSE, 0);

    _beginthread(long_oracle_call, 0, cn);

    if (WaitForSingleObject(evt, 10000) != WAIT_OBJECT_0)
    {
        OCI_Break(cn);
        Sleep(2000);
    }

    OCI_Cleanup();

 
    return EXIT_SUCCESS;
}

Functions

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

Function Documentation

OCI_EXPORT boolean OCI_API OCI_Break ( OCI_Connection con)

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

Definition at line 1722 of file connection.c.