OCI_HashEntry * OCI_API OCI_HashLookup ( OCI_HashTable *table, const mtext *key, boolean create ) { OCI_HashEntry *e = NULL, *e1 = NULL, *e2 = NULL; unsigned int i; OCI_CHECK_PTR(OCI_IPC_HASHTABLE, table, NULL); OCI_CHECK_PTR(OCI_IPC_STRING, key, NULL); i = OCI_HashCompute(table, key); if (i < table->size) { for(e = table->items[i]; e != NULL; e = e->next) { if (mtscasecmp(e->key, key) == 0) { break; } } if ((e == NULL) && (create == TRUE)) { e = (OCI_HashEntry *) OCI_MemAlloc(OCI_IPC_HASHENTRY, sizeof(*e), (size_t) 1, TRUE); if (e != NULL) { e->key = mtsdup(key); e1 = e2 = table->items[i]; while (e1 != NULL) { e2 = e1; e1 = e1->next; } if (e2 != NULL) { e2->next = e; } else { table->items[i] = e; } } } } OCI_RESULT(e != NULL); return e; }
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 {