boolean OCI_API OCI_EnqueuePut ( OCI_Library *pOCILib, OCI_Enqueue *enqueue, OCI_Msg *msg, ExceptionSink *xsink ) { boolean res = TRUE; void *ostr = NULL; int osize = -1; void *payload = NULL; void *ind = NULL; OCI_CHECK_PTR(pOCILib, OCI_IPC_ENQUEUE, enqueue, FALSE); OCI_CHECK_PTR(pOCILib, OCI_IPC_MSG, msg, FALSE); OCI_CHECK_COMPAT(pOCILib, enqueue->typinf->con, enqueue->typinf->tdo == msg->typinf->tdo, FALSE); ostr = OCI_GetInputMetaString(pOCILib, enqueue->name, &osize); /* get payload */ if (enqueue->typinf->tcode != OCI_UNKNOWN) { if (msg->ind != OCI_IND_NULL) { payload = msg->obj->handle; ind = msg->obj->tab_ind; } } else { payload = msg->payload; ind = &msg->ind; } /* enqueue message */ OCI_CALL2Q ( pOCILib, res, enqueue->typinf->con, OCIAQEnq(enqueue->typinf->con->cxt, pOCILib->err, (OraText*)ostr, enqueue->opth, msg->proph, enqueue->typinf->tdo, &payload, &ind, NULL, OCI_DEFAULT), xsink ) OCI_ReleaseMetaString(ostr); OCI_RESULT(pOCILib, res); return res; }
OCI_EXPORT boolean OCI_API OCI_DequeueSubscribe ( OCI_Dequeue *dequeue, unsigned int port, unsigned int timeout, POCI_NOTIFY_AQ callback ) { boolean res = TRUE; ub4 oci_namespace = OCI_SUBSCR_NAMESPACE_AQ; #if OCI_VERSION_COMPILE >= OCI_10_2 ub4 oci_port = (ub4) port; ub4 oci_timeout = (ub4) timeout; ub4 oci_protocol = OCI_SUBSCR_PROTO_OCI; ub4 oci_msgpres = OCI_SUBSCR_PRES_DEFAULT; #endif OCI_Connection *con = NULL; OCI_CHECK_INITIALIZED(FALSE); OCI_CHECK_DATABASE_NOTIFY_ENABLED(FALSE); OCI_CHECK_PTR(OCI_IPC_DEQUEUE, dequeue, FALSE); con = dequeue->typinf->con; /* clear any previous subscription */ OCI_DequeueUnsubscribe(dequeue); /* allocate subcription handle */ res = (OCI_SUCCESS == OCI_HandleAlloc(con->env, (dvoid **) (void *) &dequeue->subhp, OCI_HTYPE_SUBSCRIPTION, (size_t) 0, (dvoid **) NULL)); #if OCI_VERSION_COMPILE >= OCI_10_2 /* set port number */ if (oci_port > 0) { OCI_CALL3 ( res, con->err, OCIAttrSet((dvoid *) dequeue->subhp, (ub4) OCI_HTYPE_SUBSCRIPTION, (dvoid *) &oci_port, (ub4) sizeof (oci_port), (ub4) OCI_ATTR_SUBSCR_PORTNO, con->err) ) } /* set timeout */ if (oci_timeout > 0) { OCI_CALL3 ( res, con->err, OCIAttrSet((dvoid *) dequeue->subhp, (ub4) OCI_HTYPE_SUBSCRIPTION, (dvoid *) &oci_timeout, (ub4) sizeof (oci_timeout), (ub4) OCI_ATTR_SUBSCR_TIMEOUT, con->err) ) } /* set protocol */ OCI_CALL3 ( res, con->err, OCIAttrSet((dvoid *) dequeue->subhp, (ub4) OCI_HTYPE_SUBSCRIPTION, (dvoid *) &oci_protocol, (ub4) sizeof(oci_protocol), (ub4) OCI_ATTR_SUBSCR_RECPTPROTO, con->err) ) /* set presentation */ OCI_CALL3 ( res, con->err, OCIAttrSet((dvoid *) dequeue->subhp, (ub4) OCI_HTYPE_SUBSCRIPTION, (dvoid *) &oci_msgpres, (ub4) sizeof(oci_msgpres), (ub4) OCI_ATTR_SUBSCR_RECPTPRES, con->err) ) #else OCI_NOT_USED(port); OCI_NOT_USED(timeout); #endif /* set name */ if (dequeue->name != NULL) { /* for AQ subscription, the name should be "[shema.]queue[:consumer]" */ mtext buffer[(OCI_SIZE_OBJ_NAME*2) + 2] = MT(""); mtext *str = NULL; size_t size = sizeof(buffer)/sizeof(mtext); void *ostr = NULL; int osize = -1; mtsncat(buffer, dequeue->name, size); if (dequeue->consumer != NULL) { size -= mtslen(dequeue->name); mtsncat(buffer, MT(":"), size); size -= (size_t) 1; mtsncat(buffer, dequeue->consumer, size); } /* queue name must be uppercase */ for (str = buffer; *str != 0; str++) { *str = (mtext) mttoupper(*str); } ostr = OCI_GetInputMetaString(buffer, &osize); OCI_CALL3 ( res, con->err, OCIAttrSet((dvoid *) dequeue->subhp, (ub4) OCI_HTYPE_SUBSCRIPTION, (dvoid *) ostr, (ub4) osize, (ub4) OCI_ATTR_SUBSCR_NAME, con->err) ) OCI_ReleaseMetaString(ostr); } /* set namespace */ OCI_CALL3 ( res, con->err, OCIAttrSet((dvoid *) dequeue->subhp, (ub4) OCI_HTYPE_SUBSCRIPTION, (dvoid *) &oci_namespace, (ub4) sizeof(oci_namespace), (ub4) OCI_ATTR_SUBSCR_NAMESPACE, con->err) ) /* set context pointer to dequeue structure */ OCI_CALL3 ( res, con->err, OCIAttrSet((dvoid *) dequeue->subhp, (ub4) OCI_HTYPE_SUBSCRIPTION, (dvoid *) dequeue, (ub4) 0, (ub4) OCI_ATTR_SUBSCR_CTX, con->err) ) /* internal callback handler */ OCI_CALL3 ( res, con->err, OCIAttrSet((dvoid *) dequeue->subhp, (ub4) OCI_HTYPE_SUBSCRIPTION, (dvoid *) OCI_ProcNotifyMessages, (ub4) 0, (ub4) OCI_ATTR_SUBSCR_CALLBACK, con->err) ) /* all attributes set, let's register the subscription ! */ OCI_CALL3 ( res, con->err, OCISubscriptionRegister(con->cxt, &dequeue->subhp, (ub2) 1, con->err,(ub4) OCI_DEFAULT) ) /* set callback on success */ if (res) { dequeue->callback = callback; } else { /* clear subscription on failure */ OCI_DequeueUnsubscribe(dequeue); } OCI_RESULT(res); return res; }
OCI_Msg * OCI_API OCI_DequeueGet ( OCI_Dequeue *dequeue ) { boolean res = TRUE; sword ret = OCI_SUCCESS; OCI_Msg *msg = NULL; void *p_ind = NULL; OCI_CHECK_PTR(OCI_IPC_DEQUEUE, dequeue, NULL); /* reset message */ res = OCI_MsgReset(dequeue->msg); if (res == TRUE) { void *ostr = NULL; int osize = -1; ostr = OCI_GetInputMetaString(dequeue->name, &osize); if (dequeue->typinf->tcode == OCI_UNKNOWN) { p_ind = &dequeue->msg->ind; } /* dequeue message */ ret = OCIAQDeq(dequeue->typinf->con->cxt, dequeue->typinf->con->err, ostr, dequeue->opth, dequeue->msg->proph, dequeue->typinf->tdo, &dequeue->msg->payload, (void **) &p_ind, &dequeue->msg->id, OCI_DEFAULT); OCI_ReleaseMetaString(ostr); /* check returned error code */ if (ret == OCI_ERROR) { sb4 code = 0; OCIErrorGet((dvoid *) dequeue->typinf->con->err, (ub4) 1, (OraText *) NULL, &code, (OraText *) NULL, (ub4) 0, (ub4) OCI_HTYPE_ERROR); /* raise error only if the call has not been timed out */ if (code != OCI_ERR_AQ_DEQUEUE_TIMEOUT) { OCI_ExceptionOCI(dequeue->typinf->con->err, dequeue->typinf->con, NULL, FALSE); res = FALSE; } } } /* reset message */ if ((res == TRUE) && (ret == OCI_SUCCESS)) { /* get payload */ if (dequeue->typinf->tcode != OCI_UNKNOWN) { if ((p_ind != NULL) && ((*(OCIInd *) p_ind) != OCI_IND_NULL)) { dequeue->msg->ind = *(OCIInd *) p_ind; dequeue->msg->obj = OCI_ObjectInit(dequeue->typinf->con, (OCI_Object **) &dequeue->msg->obj, dequeue->msg->payload, dequeue->typinf, NULL, -1, TRUE); res = dequeue->msg->obj != NULL; } } } /* on success return internla message handle */ if ((res == TRUE) && (ret == OCI_SUCCESS)) { msg = dequeue->msg; } OCI_RESULT(res); return msg; }
OCI_DirPath * OCI_API OCI_DirPathCreate ( OCI_TypeInfo *typinf, const mtext *partition, unsigned int nb_cols, unsigned int nb_rows ) { OCI_DirPath *dp = NULL; void *ostr = NULL; int osize = -1; boolean res = TRUE; OCI_CHECK_PTR(OCI_IPC_TYPE_INFO, typinf, NULL); OCI_CHECK_COMPAT(typinf->con, typinf->type != OCI_TIF_TYPE, NULL); OCI_CHECK_BOUND(typinf->con, nb_cols, 1, typinf->nb_cols, NULL); /* allocate direct path structure */ dp = (OCI_DirPath *) OCI_MemAlloc(OCI_IPC_DIRPATH, sizeof(*dp), (size_t) 1, TRUE); if (dp != NULL) { dp->con = typinf->con; dp->status = OCI_DPS_NOT_PREPARED; dp->typinf = typinf; dp->nb_rows = (ub2) nb_rows; dp->nb_cols = (ub2) nb_cols; dp->nb_cur = (ub2) dp->nb_rows; dp->err_col = 0; dp->err_row = 0; dp->nb_prcsd = 0; /* allocates direct context handle */ if (res == TRUE) { res = (OCI_SUCCESS == OCI_HandleAlloc((dvoid *) dp->con->env, (dvoid **) (void *) &dp->ctx, (ub4) OCI_HTYPE_DIRPATH_CTX, (size_t) 0, (dvoid **) NULL)); } /* set table name attribute */ if (res == TRUE) { osize = -1; ostr = OCI_GetInputMetaString(dp->typinf->name, &osize); OCI_CALL2 ( res, dp->con, OCIAttrSet((dvoid *) dp->ctx, (ub4) OCI_HTYPE_DIRPATH_CTX, (dvoid *) ostr, (ub4) osize, (ub4) OCI_ATTR_NAME, dp->con->err) ) OCI_ReleaseMetaString(ostr); } /* set schema name attribute */ if ((res == TRUE) && (dp->typinf->schema != NULL) && (dp->typinf->schema[0] != 0)) { osize = -1; ostr = OCI_GetInputMetaString(dp->typinf->schema, &osize); OCI_CALL2 ( res, dp->con, OCIAttrSet((dvoid *) dp->ctx, (ub4) OCI_HTYPE_DIRPATH_CTX, (dvoid *) ostr, (ub4) osize, (ub4) OCI_ATTR_SCHEMA_NAME, dp->con->err) ) OCI_ReleaseMetaString(ostr); } /* set partition name attribute */ if ((res == TRUE) && (partition != NULL) && (partition[0] != 0)) { osize = -1; ostr = OCI_GetInputMetaString(partition, &osize); OCI_CALL2 ( res, dp->con, OCIAttrSet((dvoid *) dp->ctx, (ub4) OCI_HTYPE_DIRPATH_CTX, (dvoid *) ostr, (ub4) osize, (ub4) OCI_ATTR_SUB_NAME, dp->con->err) ) OCI_ReleaseMetaString(ostr); } if (OCILib.version_runtime >= OCI_9_0) { ub4 num_rows = dp->nb_rows; /* set array size attribute */ OCI_CALL2 ( res, dp->con, OCIAttrSet((dvoid *) dp->ctx, (ub4) OCI_HTYPE_DIRPATH_CTX, (dvoid *) &num_rows, (ub4) sizeof(num_rows), (ub4) OCI_ATTR_NUM_ROWS, dp->con->err) ) }
OCI_TypeInfo * OCI_API OCI_TypeInfoGet2(OCI_Library *pOCILib, OCI_Connection *con, const mtext *name, unsigned int type, ExceptionSink* xsink) { OCI_TypeInfo *typinf = NULL; OCI_Item *item = NULL; OCIDescribe *dschp = NULL; OCIParam *parmh1 = NULL; OCIParam *parmh2 = NULL; mtext *str = NULL; //int etype = OCI_DESC_COLUMN; int ptype = 0; ub1 item_type = 0; ub4 attr_type = 0; ub4 num_type = 0; boolean res = TRUE; boolean found = FALSE; ub2 i; mtext obj_schema[OCI_SIZE_OBJ_NAME+1]; mtext obj_name[OCI_SIZE_OBJ_NAME+1]; OCI_CHECK_INITIALIZED2(pOCILib, NULL); OCI_CHECK_PTRQ(pOCILib, OCI_IPC_CONNECTION, con, NULL, xsink); OCI_CHECK_PTRQ(pOCILib, OCI_IPC_STRING, name, NULL, xsink); if (type == OCI_TIF_TABLE) item_type = OCI_PTYPE_TABLE; else if (type == OCI_TIF_VIEW) item_type = OCI_PTYPE_VIEW; else if (type == OCI_TIF_TYPE) item_type = OCI_PTYPE_TYPE; else return NULL; obj_schema[0] = 0; obj_name[0] = 0; /* is the schema provided in the object name ? */ for (str = (mtext *) name; *str != 0; str++) { if (*str == MT('.')) { mtsncat(obj_schema, name, str-name); mtsncat(obj_name, ++str, (size_t) OCI_SIZE_OBJ_NAME); break; } } /* if the schema is not provided, we just copy the object name */ if (obj_name[0] == 0) { mtsncat(obj_name, name, (size_t) OCI_SIZE_OBJ_NAME); } /* type name must be uppercase */ for (str = obj_name; *str != 0; str++) *str = (mtext) mttoupper(*str); /* schema name must be uppercase */ for (str = obj_schema; *str != 0; str++) *str = (mtext) mttoupper(*str); /* first try to find it in list */ item = con->tinfs->head; /* walk along the list to find the type */ while (item != NULL) { typinf = (OCI_TypeInfo *) item->data; if ((typinf != NULL) && (typinf->type == type)) { if ((mtscasecmp(typinf->name, obj_name ) == 0) && (mtscasecmp(typinf->schema, obj_schema) == 0)) { found = TRUE; break; } } item = item->next; } /* Not found, so create type object */ if (found == FALSE) { item = OCI_ListAppend(pOCILib, con->tinfs, sizeof(OCI_TypeInfo)); res = (item != NULL); if (res == TRUE) { typinf = (OCI_TypeInfo *) item->data; typinf->type = type; typinf->con = con; typinf->name = mtsdup(pOCILib, obj_name); typinf->schema = mtsdup(pOCILib, obj_schema); typinf->struct_size = 0; res = (OCI_SUCCESS == OCI_HandleAlloc2(pOCILib, pOCILib->env, (dvoid **) (void *) &dschp, OCI_HTYPE_DESCRIBE, (size_t) 0, (dvoid **) NULL)); } if (res == TRUE) { if (type == OCI_TIF_TYPE) { void *ostr1 = NULL; void *ostr2 = NULL; int osize1 = -1; int osize2 = -1; attr_type = OCI_ATTR_LIST_TYPE_ATTRS; num_type = OCI_ATTR_NUM_TYPE_ATTRS; ptype = OCI_DESC_TYPE; ostr1 = OCI_GetInputMetaString(pOCILib, typinf->schema, &osize1); ostr2 = OCI_GetInputMetaString(pOCILib, typinf->name, &osize2); OCI_CALL2Q ( pOCILib, res, con, OCITypeByName(pOCILib->env, con->err, con->cxt, (text *) ostr1, (ub4) osize1, (text *) ostr2, (ub4) osize2, (text *) NULL, (ub4) 0, OCI_DURATION_SESSION, OCI_TYPEGET_ALL, &typinf->tdo), xsink ) OCI_CALL2Q ( pOCILib, res, con, OCIDescribeAny(con->cxt, con->err, (void *) typinf->tdo, 0, OCI_OTYPE_PTR, OCI_DEFAULT, OCI_PTYPE_TYPE, dschp), xsink ) OCI_ReleaseMetaString(ostr1); OCI_ReleaseMetaString(ostr2); } else { mtext buffer[(OCI_SIZE_OBJ_NAME*2) + 2]; size_t size = sizeof(buffer)/sizeof(mtext); void *ostr1 = NULL; int osize1 = -1; attr_type = OCI_ATTR_LIST_COLUMNS; num_type = OCI_ATTR_NUM_COLS; ptype = OCI_DESC_TABLE; str = buffer; str[0] = 0; if ((typinf->schema != NULL) && (typinf->schema[0] != 0)) { str = mtsncat(buffer, typinf->schema, size); size -= mtslen(typinf->schema); str = mtsncat(str, MT("."), size); size -= (size_t) 1; } mtsncat(str, typinf->name, size); ostr1 = OCI_GetInputMetaString(pOCILib, str, &osize1); OCI_CALL2Q ( pOCILib, res, con, OCIDescribeAny(con->cxt, con->err, (dvoid *) ostr1, (ub4) osize1, OCI_OTYPE_NAME, OCI_DEFAULT, item_type, dschp), xsink ) OCI_ReleaseMetaString(ostr1); } OCI_CALL2Q ( pOCILib, res, con, OCIAttrGet(dschp, OCI_HTYPE_DESCRIBE, &parmh1, NULL, OCI_ATTR_PARAM, con->err), xsink ) /* do we need get more attributes for collections ? */ if (type == OCI_TIF_TYPE) { OCI_CALL2Q ( pOCILib, res, con, OCIAttrGet(parmh1, OCI_DTYPE_PARAM, &typinf->tcode, NULL, OCI_ATTR_TYPECODE, con->err), xsink ) } if (typinf->tcode == SQLT_NCO) { typinf->nb_cols = 1; ptype = OCI_DESC_COLLECTION; //etype = OCI_DESC_TYPE; parmh2 = parmh1; OCI_CALL2Q ( pOCILib, res, con, OCIAttrGet(parmh1, OCI_DTYPE_PARAM, &typinf->ccode, NULL, OCI_ATTR_COLLECTION_TYPECODE, con->err), xsink ) } else {
boolean OCI_FileGetInfo ( OCI_File *file ) { boolean res = TRUE; OCI_CHECK_PTR(OCI_IPC_FILE, file, FALSE); /* directory name */ if (file->dir == NULL) { if (res == TRUE) { file->dir = (mtext *) OCI_MemAlloc(OCI_IPC_STRING, sizeof(mtext), (size_t) (OCI_SIZE_DIRECTORY + 1), TRUE); res = (file->dir != NULL); } } else { file->dir[0] = 0; } /* file name */ if (file->name == NULL) { if (res == TRUE) { file->name = (mtext *) OCI_MemAlloc(OCI_IPC_STRING, sizeof(mtext), (size_t)( OCI_SIZE_FILENAME + 1), TRUE); res = (file->name != NULL); } } else { file->name[0] = 0; } /* retrieve name */ if (res == TRUE) { void *ostr1 = NULL; void *ostr2 = NULL; int osize1 = 0; int osize2 = 0; ub2 usize1 = 0; ub2 usize2 = 0; osize1 = (int ) OCI_SIZE_DIRECTORY * (int) sizeof(mtext); ostr1 = (void *) OCI_GetInputMetaString(file->dir, &osize1); osize2 = (int ) OCI_SIZE_FILENAME * (int) sizeof(mtext); ostr2 = (void *) OCI_GetInputMetaString(file->name, &osize1); usize1 = (ub2) osize1; usize2 = (ub2) osize2; OCI_CALL2 ( res, file->con, OCILobFileGetName(file->con->env, file->con->err, file->handle, (OraText *) ostr1, (ub2*) &usize1, (OraText *) ostr2, (ub2*) &usize2) ) osize1 = (int) usize1; osize2 = (int) usize2; OCI_GetOutputMetaString(ostr1, file->dir, &osize1); OCI_GetOutputMetaString(ostr2, file->name, &osize2); OCI_ReleaseMetaString(ostr1); OCI_ReleaseMetaString(ostr2); } return res; }
OCI_Pool * OCI_API OCI_PoolCreate ( const mtext *db, const mtext *user, const mtext *pwd, unsigned int type, unsigned int mode, unsigned int min_con, unsigned int max_con, unsigned int incr_con ) { OCI_Pool *pool = NULL; OCI_Item *item = NULL; boolean res = TRUE; OCI_CHECK_MIN(NULL, NULL, max_con, 1, NULL); /* let's be sure OCI_Initialize() has been called */ OCI_CHECK_INITIALIZED(NULL); /* make sure that we do not have a XA session flag */ mode &= ~OCI_SESSION_XA; /* create pool object */ item = OCI_ListAppend(OCILib.pools, sizeof(*pool)); if (item != NULL) { pool = (OCI_Pool *) item->data; /* create internal lists */ pool->cons = OCI_ListCreate(OCI_IPC_CONNECTION); if (OCI_LIB_THREADED) { /* create mutex for OCI_PoolGetConnection() */ pool->mutex = OCI_MutexCreateInternal(); res = (pool->mutex != NULL); } } else { res = FALSE; } /* set attributes */ if (res == TRUE) { pool->mode = mode; pool->min = min_con; pool->max = max_con; pool->incr = incr_con; pool->db = mtsdup(db != NULL ? db : MT("")); pool->user = mtsdup(user != NULL ? user : MT("")); pool->pwd = mtsdup(pwd != NULL ? pwd : MT("")); } #if OCI_VERSION_COMPILE < OCI_9_2 type = OCI_POOL_CONNECTION; #endif #if OCI_VERSION_COMPILE >= OCI_9_0 if (res == TRUE) { if (type == OCI_POOL_CONNECTION) { pool->htype = OCI_HTYPE_CPOOL; } #if OCI_VERSION_COMPILE >= OCI_9_2 else { pool->htype = OCI_HTYPE_SPOOL; } #endif } if (OCILib.version_runtime >= OCI_9_0) { int osize_name = -1; int osize_db = -1; void *ostr_name = NULL; void *ostr_db = NULL; /* allocate error handle */ if (res == TRUE) { res = (OCI_SUCCESS == OCI_HandleAlloc((dvoid *) OCILib.env, (dvoid **) (void *) &pool->err, (ub4) OCI_HTYPE_ERROR, (size_t) 0, (dvoid **) NULL)); } /* allocate pool handle */ if (res == TRUE) { res = (OCI_SUCCESS == OCI_HandleAlloc((dvoid *) OCILib.env, (dvoid **) (void *) &pool->handle, (ub4) pool->htype, (size_t) 0, (dvoid **) NULL)); } /* allocate authentification handle only if needed */ #if OCI_VERSION_COMPILE >= OCI_11_1 if (res == TRUE) { if ((pool->htype == OCI_HTYPE_SPOOL) && (OCILib.version_runtime >= OCI_11_1)) { int osize = -1; void *ostr = OCI_GetInputMetaString(OCILIB_DRIVER_NAME, &osize); /* allocate authentification handle */ res = (OCI_SUCCESS == OCI_HandleAlloc((dvoid *) OCILib.env, (dvoid **) (void *) &pool->authp, (ub4) OCI_HTYPE_AUTHINFO, (size_t) 0, (dvoid **) NULL)); /* set OCILIB's driver layer name attribute only for session pools here For standalone connections and connection pool this attribute is set in OCI_ConnectionLogon() */ OCI_CALL3 ( res, pool->err, OCIAttrSet((dvoid *) pool->authp, (ub4) OCI_HTYPE_AUTHINFO, (dvoid *) ostr, (ub4) osize, (ub4) OCI_ATTR_DRIVER_NAME, pool->err) ) OCI_ReleaseMetaString(ostr); /* set auth handle on the session pool */ OCI_CALL3 ( res, pool->err, OCIAttrSet((dvoid *) pool->handle, (ub4) OCI_HTYPE_SPOOL, (dvoid *) pool->authp, (ub4) sizeof(pool->authp), (ub4) OCI_ATTR_SPOOL_AUTH, pool->err) ) } }