Include oci.h before jagpublic.h, as in the example below:
#include <oci.h> #include <jagpublic.h>
Most Connection Manager routines require the address of a CM_CACHE handle as a parameter. The cache handle allows your code to refer to a specific cache that is defined in EAServer Manager. The routines JagCmGetCachebyName or JagCmGetCachebyUser retrieve cache handles.
OCI 8.x uses a OCISvcCtx structure to represent a database connection. The JagCmGetConnection routine returns the address of a OCISvcCtx structure.
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);
Copyright © 2005. Sybase Inc. All rights reserved. |