OCI 8.x example

The example below retrieves an OCI 8.x connection, executes a statement using the connection, then returns the connection to the cache.

#include <jagpublic.h> 
#include <oci.h> #define   USERID            "system" 
#define   PASSWD          "manager" 
#define   DATASOURCE "OCITEST" 

 JagCmCache  cache; 
 OCIEnv *envhp; 
 OCISvcCtx **svcpp, *svchp; 
 OCIError *errhp; 
 OCIStmt *stmthp; 
 sword ociret;      /* Connect to ORACLE. */ 
    cache = NULL; 
    ociret = JagCmGetConnection(&cache, 
                                USERID, PASSWD, DATASOURCE, 
                                "OCI_8", 
                                (void*)&svchp, 
                                JAG_CM_FORCE); 
   ... 
     /* Initialize an Env, to allocate stmt and error handles */ 
   OCIEnvInit( &envhp, OCI_DEFAULT, (size_t) 0, (dvoid **)0 ); 
   OCIHandleAlloc( (dvoid *) envhp, (dvoid **) &errhp,
                   OCI_HTYPE_ERROR, (size_t) 0, (dvoid **) 0); 
   OCIHandleAlloc( (dvoid *) envhp, (dvoid **) &stmthp,
                   OCI_HTYPE_STMT, (size_t) 0, (dvoid **) 0)); 
   checkerr(errhp, OCIStmtPrepare(stmthp, errhp, sql_statement, 
                                  (ub4) strlen((char *) sql_statement), 
                                  (ub4) OCI_NTV_SYNTAX, (ub4) OCI_DEFAULT)); 

     /* execute using the service context */ 
    checkerr(errhp, OCIStmtExecute(svchp, stmthp, errhp, (ub4) 1, (ub4) 0, 
                                   (CONST OCISnapshot *) NULL, 
                                   (OCISnapshot *) NULL, OCI_DEFAULT)); 
   ..... 

     /* free handles */ 
    OCIHandleFree(stmthp, OCI_HTYPE_STMT); 
    OCIHandleFree(errhp, OCI_HTYPE_ERROR); 

     /* release connection */ 
     ret = JagCmReleaseConnection(&cache, 
                                  USERID, PASSWD, DATASOURCE, 
                                  "OCI_8", 
                                  svchp, 
                                   JAG_CM_UNUSED);