OCI_Transaction * OCI_API OCI_TransactionCreate ( OCI_Connection *con, unsigned int timeout, unsigned int mode, OCI_XID *pxid ) { OCI_Item *item = NULL; OCI_Transaction *trans = NULL; boolean res = TRUE; OCI_CHECK_INITIALIZED(NULL); OCI_CHECK_PTR(OCI_IPC_CONNECTION, con, NULL); /* create transaction object */ item = OCI_ListAppend(con->trsns, sizeof(*trans)); if (item != NULL) { trans = (OCI_Transaction *) item->data; trans->con = con; trans->mode = mode; trans->timeout = timeout; trans->local = (pxid == NULL); /* allocate transaction handle */ if (res == TRUE) { res = (OCI_SUCCESS == OCI_HandleAlloc((dvoid *) trans->con->env, (dvoid **) (void *) &trans->htr, (ub4) OCI_HTYPE_TRANS, (size_t) 0, (dvoid **) NULL)); } /* set XID attribute for global transaction */ if (pxid != NULL) { memcpy(&trans->xid, pxid, sizeof(trans->xid)); OCI_CALL2 ( res, con, OCIAttrSet((dvoid *) trans->htr, (ub4) OCI_HTYPE_TRANS, (dvoid *) &trans->xid, (ub4) sizeof(trans->xid), (ub4) OCI_ATTR_XID, trans->con->err) ) }
OCI_Transaction * OCI_API OCI_TransactionCreate ( OCI_Connection *con, unsigned int timeout, unsigned int mode, OCI_XID *pxid ) { OCI_Item *item = NULL; OCI_LIB_CALL_ENTER(OCI_Transaction *, NULL) OCI_CHECK_PTR(OCI_IPC_CONNECTION, con) /* create transaction object */ item = OCI_ListAppend(con->trsns, sizeof(*call_retval)); if (item) { call_retval = (OCI_Transaction *) item->data; call_retval->con = con; call_retval->mode = mode; call_retval->timeout = timeout; call_retval->local = (NULL == pxid); /* allocate transaction handle */ call_status = OCI_SUCCESSFUL(OCI_HandleAlloc((dvoid *) call_retval->con->env, (dvoid **) &call_retval->htr, (ub4) OCI_HTYPE_TRANS, (size_t) 0, (dvoid **) NULL)); /* set XID attribute for global transaction */ if (call_status && pxid) { memcpy(&call_retval->xid, pxid, sizeof(call_retval->xid)); OCI_CALL2 ( call_status, con, OCIAttrSet((dvoid *) call_retval->htr, (ub4) OCI_HTYPE_TRANS, (dvoid *) &call_retval->xid, (ub4) sizeof(call_retval->xid), (ub4) OCI_ATTR_XID, call_retval->con->err) ) } }
OCI_Array * OCI_ArrayCreate ( OCI_Connection *con, unsigned int nb_elem, unsigned int elem_type, unsigned int elem_subtype, unsigned int elem_size, unsigned int struct_size, unsigned int handle_type, OCI_TypeInfo *typinf ) { boolean res = FALSE; OCI_Array *arr = NULL; OCI_Item *item = NULL; /* create array object */ item = OCI_ListAppend(OCILib.arrs, sizeof(*arr)); if (item) { res = TRUE; arr = (OCI_Array *) item->data; arr->con = con; arr->elem_type = elem_type; arr->elem_subtype = elem_subtype; arr->elem_size = elem_size; arr->nb_elem = nb_elem; arr->struct_size = struct_size; arr->handle_type = handle_type; /* allocate OCILIB Object array */ if (res) { if ( (OCI_CDT_NUMERIC != arr->elem_type ) && (OCI_CDT_TEXT != arr->elem_type ) && (OCI_CDT_RAW != arr->elem_type ) ) { arr->tab_obj = (void **) OCI_MemAlloc(OCI_IPC_VOID, sizeof(void *), nb_elem, TRUE); res = (NULL != arr->tab_obj) ; } } /* allocate OCI handle array */ if (res) { if (arr->elem_size > 0) { arr->mem_handle = (void **) OCI_MemAlloc(OCI_IPC_VOID, elem_size, nb_elem, TRUE); res = (NULL != arr->mem_handle); } } /* allocate OCILIB structure array */ if (res) { if (arr->struct_size > 0) { arr->mem_struct = (void **) OCI_MemAlloc(OCI_IPC_VOID, struct_size, nb_elem, TRUE); res = (NULL != arr->mem_struct); } } /* allocate OCI handle descriptors */ if (res) { if (handle_type != 0) { res = OCI_SUCCESSFUL(OCI_DescriptorArrayAlloc((dvoid *) arr->con->env, (dvoid **) arr->mem_handle, (ub4 ) handle_type, (ub4 ) nb_elem, (size_t ) 0, (dvoid **) NULL)); } } if (res && arr->tab_obj && arr->mem_handle) { res = OCI_ArrayInit(arr, typinf); } } /* check for failure */ if (!res) { OCI_ArrayClose(arr); OCI_FREE(arr) }
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 {
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) ) } }