OCI_HashEntry * OCI_API OCI_HashLookup ( OCI_HashTable *table, const otext *key, boolean create ) { OCI_HashEntry *e = NULL, *e1 = NULL, *e2 = NULL; unsigned int i; OCI_LIB_CALL_ENTER(OCI_HashEntry*, NULL) OCI_CHECK_PTR(OCI_IPC_HASHTABLE, table) OCI_CHECK_PTR(OCI_IPC_STRING, key) i = OCI_HashCompute(table, key); if (i < table->size) { for(e = table->items[i]; e; e = e->next) { if (ostrcasecmp(e->key, key) == 0) { break; } } if (!e && create) { e = (OCI_HashEntry *) OCI_MemAlloc(OCI_IPC_HASHENTRY, sizeof(*e), (size_t) 1, TRUE); if (e) { e->key = ostrdup(key); e1 = e2 = table->items[i]; while (e1) { e2 = e1; e1 = e1->next; } if (e2) { e2->next = e; } else { table->items[i] = e; } } } } call_retval = e; call_status = TRUE; OCI_LIB_CALL_EXIT() }
int OCI_GetDefineIndex ( OCI_Resultset *rs, const otext *name ) { OCI_HashEntry *he = NULL; int index = -1; if (!rs->map) { /* create the map at the first call to OCI_Getxxxxx2() to save time and memory when it's not needed */ rs->map = OCI_HashCreate(OCI_HASH_DEFAULT_SIZE, OCI_HASH_INTEGER); if (rs->map) { ub4 i; for (i = 0; i < rs->nb_defs; i++) { OCI_HashAddInt(rs->map, rs->defs[i].col.name, (i+1)); } } } /* check out we got our map object */ OCI_CHECK(NULL == rs->map, -1); he = OCI_HashLookup(rs->map, name, FALSE); while (he) { /* no more entries or key matched => so we got it ! */ if (!he->next || 0 == ostrcasecmp(he->key, name)) { index = he->values->value.num; break; } he = he->next; } if (index < 0) { OCI_ExceptionItemNotFound(rs->stmt->con, rs->stmt, name, OCI_IPC_COLUMN); } return index; }