Beispiel #1
0
void * OCI_DefineGetData
(
    OCI_Define *def
)
{
    OCI_CHECK(NULL == def, NULL);
    OCI_CHECK(NULL == def->rs, NULL);
    OCI_CHECK(def->rs->row_cur < 1, NULL);

    switch (def->col.datatype)
    {
        case OCI_CDT_LONG:
        case OCI_CDT_CURSOR:
        case OCI_CDT_TIMESTAMP:
        case OCI_CDT_INTERVAL:
        case OCI_CDT_LOB:
        case OCI_CDT_FILE:
        case OCI_CDT_OBJECT:
        case OCI_CDT_COLLECTION:
        case OCI_CDT_REF:
        {
            /* handle based types */

            return def->buf.data[def->rs->row_cur-1];
        }
        default:
        {
            /* scalar types */

            return (((ub1 *) (def->buf.data)) + (size_t) (def->col.bufsize * (def->rs->row_cur-1)));
        }
    }
}
Beispiel #2
0
boolean OCI_HashAdd
(
    OCI_HashTable *table,
    const otext   *key,
    OCI_Variant    value,
    unsigned int   type
)
{
    OCI_HashEntry * e = NULL;
    OCI_HashValue * v = NULL, *v1 = NULL, *v2 = NULL;
    boolean res = FALSE;

    OCI_CHECK(NULL == table, FALSE)
    OCI_CHECK(NULL == key, FALSE)
    OCI_CHECK(table->type != type, FALSE)

    e = OCI_HashLookup(table, key, TRUE);

    if (e)
    {
        v = (OCI_HashValue *)OCI_MemAlloc(OCI_IPC_HASHVALUE, sizeof(*v), (size_t)1, TRUE);

        if (v)
        {
            if (OCI_HASH_STRING == table->type && value.p_text)
            {
                v->value.p_text = ostrdup(value.p_text);
            }
            else if (OCI_HASH_INTEGER == table->type)
            {
                v->value.num = value.num;
            }
            else
            {
                v->value.p_void = value.p_void;
            }

            v1 = v2 = e->values;

            while (v1)
            {
                v2 = v1;
                v1 = v1->next;
            }

            if (v2)
            {
                v2->next = v;
            }
            else
            {
                e->values = v;
            }

            res = TRUE;
        }
    }

    return res;
}
Beispiel #3
0
boolean OCI_HashAdd
(
    OCI_HashTable *table,
    const mtext   *key,
    OCI_Variant    value,
    unsigned int   type
)
{
    OCI_HashEntry * e = NULL;
    OCI_HashValue * v = NULL, *v1 = NULL, *v2 = NULL;

    OCI_CHECK(table == NULL, FALSE);
    OCI_CHECK(key   == NULL, FALSE);
    OCI_CHECK(table->type != type, FALSE);

    e = OCI_HashLookup(table, key, TRUE);

    if (e != NULL)
    {
        v = (OCI_HashValue *) OCI_MemAlloc(OCI_IPC_HASHVALUE, sizeof(*v), (size_t) 1, TRUE);

        if (v != NULL)
        {
            if (table->type == OCI_HASH_STRING && value.p_mtext != NULL)
            {
                v->value.p_mtext = mtsdup(value.p_mtext);
            }
            else if (table->type == OCI_HASH_INTEGER)
            {
                v->value.num = value.num;
            }
            else
            {
                v->value.p_void = value.p_void;
            }

            v1 = v2 = e->values;

            while (v1 != NULL)
            {
                v2 = v1;
                v1 = v1->next;
            }

            if (v2 != NULL)
            {
                v2->next = v;
            }
            else
            {
                e->values = v;
            }
        }
    }

    return (v != NULL);
}
Beispiel #4
0
boolean OCI_ListRemove
(
    OCI_List *list,
    void     *data
)
{
    OCI_Item *item = NULL;
    OCI_Item *temp = NULL;

    OCI_CHECK(list == NULL, FALSE);
    OCI_CHECK(data == NULL, FALSE);

    if (list->mutex != NULL)
    {
        OCI_MutexAcquire(list->mutex);
    }

    item = list->head;

    while (item != NULL)
    {
        if (item->data == data)
        {
            if (temp)
            {
                temp->next = item->next;
            }

            /* if item was the first entry, readjust the first list
               entry to next element */

            if (item == list->head)
            {
                list->head = item->next;
            }

            OCI_FREE(item);

            break;
        }

        temp = item;
        item = item->next;
    }

    list->count--;

    if (list->mutex != NULL)
    {
        OCI_MutexRelease(list->mutex);
    }

    return TRUE;
}
Beispiel #5
0
boolean OCI_EventReset
(
    OCI_Event *event
)
{
    OCI_CHECK(NULL == event, FALSE)

    event->op   = OCI_UNKNOWN;
    event->type = OCI_UNKNOWN;

    if (event->dbname)
    {
        event->dbname[0] = 0;
    }

    if (event->objname)
    {
        event->objname[0] = 0;
    }

    if (event->rowid)
    {
        event->rowid[0] = 0;
    }

    return TRUE;
}
Beispiel #6
0
boolean OCI_ListForEach
(
    OCI_List          *list,
    POCI_LIST_FOR_EACH proc
)
{
    OCI_Item *item = NULL;

    OCI_CHECK(list == NULL, FALSE);

    if (list->mutex != NULL)
    {
        OCI_MutexAcquire(list->mutex);
    }

    item = list->head;

    /* for each item in the list, execute the given callback */

    while (item != NULL)
    {
        proc(item->data);
        item = item->next;
    }

    if (list->mutex != NULL)
    {
        OCI_MutexRelease(list->mutex);
    }

    return TRUE;
}
Beispiel #7
0
OCI_Item * OCI_ListAppend
(
    OCI_List *list,
    int       size
)
{
    OCI_Item *item = NULL;
    OCI_Item *temp = NULL;

    OCI_CHECK(list == NULL, NULL);

    item = OCI_ListCreateItem(list->type, size);

    OCI_CHECK(item == NULL, FALSE);

    if (list->mutex != NULL)
    {
        OCI_MutexAcquire(list->mutex);
    }

    temp = list->head;

    while (temp != NULL && temp->next)
    {
        temp = temp->next;
    }

    if (temp != NULL)
    {
        temp->next = item;
    }
    else
    {
        list->head = item;
    }

    list->count++;

    if (list->mutex != NULL)
    {
        OCI_MutexRelease(list->mutex);
    }

    return item;
}
Beispiel #8
0
int OCI_API OCI_ErrorGetOCICode
(
    OCI_Error *err
)
{
    OCI_CHECK(NULL == err, OCI_UNKNOWN);

    return (int) err->sqlcode;
}
Beispiel #9
0
const otext * OCI_API OCI_ErrorGetString
(
    OCI_Error *err
)
{
    OCI_CHECK(NULL == err, NULL);

    return err->str;
}
Beispiel #10
0
int OCI_API OCI_ErrorGetOCICode
(
    OCI_Error *err
)
{
    OCI_CHECK(err == NULL, OCI_UNKNOWN);

    return (int) err->ocode;
}
Beispiel #11
0
OCI_Connection * OCI_API OCI_ErrorGetConnection
(
    OCI_Error *err
)
{
    OCI_CHECK(err == NULL, NULL);

    return err->con;
}
Beispiel #12
0
OCI_Statement * OCI_API OCI_ErrorGetStatement
(
    OCI_Error *err
)
{
    OCI_CHECK(err == NULL, NULL);

    return err->stmt;
}
Beispiel #13
0
unsigned int OCI_API OCI_ErrorGetRow
(
    OCI_Error *err
)
{
    OCI_CHECK(err == NULL, 0);

    return err->row;
}
Beispiel #14
0
int OCI_API OCI_ErrorGetInternalCode
(
    OCI_Error *err
)
{
    OCI_CHECK(NULL == err, 0);

    return err->libcode;
}
Beispiel #15
0
const mtext * OCI_API OCI_ErrorGetString
(
    OCI_Error *err
)
{
    OCI_CHECK(err == NULL, NULL);

    return err->str;
}
Beispiel #16
0
unsigned int OCI_API OCI_ErrorGetType
(
    OCI_Error *err
)
{
    OCI_CHECK(err == NULL, OCI_UNKNOWN);

    return err->type;
}
Beispiel #17
0
OCI_Ref * OCI_RefInit
(
    OCI_Connection *con,
    OCI_TypeInfo  **typinf,
    OCI_Ref       **pref,
    void           *handle
)
{
    boolean  res = FALSE;
    OCI_Ref *ref = NULL;

    OCI_CHECK(NULL == pref, NULL);

    if (!*pref)
    {
        *pref = (OCI_Ref *) OCI_MemAlloc(OCI_IPC_REF, sizeof(*ref), (size_t) 1, TRUE);
    }

    if (*pref)
    {
        res = TRUE;

        ref = *pref;

        ref->handle = handle;
        ref->con    = con;
        ref->typinf = typinf ? *typinf : NULL;

        if (!ref->handle || (OCI_OBJECT_ALLOCATED_ARRAY == ref->hstate))
        {
            /* allocates handle for non fetched object */

            if (OCI_OBJECT_ALLOCATED_ARRAY != ref->hstate)
            {
                ref->hstate = OCI_OBJECT_ALLOCATED;
            }

            OCI_CALL2
            (
                res, ref->con,

                OCI_ObjectNew(ref->con->env, ref->con->err, ref->con->cxt,
                              (OCITypeCode) SQLT_REF,
                              (OCIType*) NULL,
                              (dvoid *) NULL,
                              (OCIDuration) OCI_DURATION_SESSION,
                              (boolean) FALSE,
                              (dvoid **) &ref->handle)
            )
        }
        else
        {
            ref->hstate = OCI_OBJECT_FETCHED_CLEAN;

            OCI_RefUnpin(ref);
        }
    }
Beispiel #18
0
unsigned int OCI_HashCompute
(
    OCI_HashTable *table,
    const otext   *str
)
{
    unsigned int h;
    otext *p;

    OCI_CHECK(NULL == table, 0);
    OCI_CHECK(NULL == str, 0);

    for(h = 0, p = (otext *) str; (*p) != 0; p++)
    {
        otext c = *p;

        h = 31 * h + otoupper(c);
    }

    return (h % table->size);
}
Beispiel #19
0
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;
}
Beispiel #20
0
unsigned int OCI_HashCompute
(
    OCI_HashTable *table,
    const mtext   *str
)
{
    unsigned int h;
    mtext *p;
    mtext c;

    OCI_CHECK(table == NULL, 0);
    OCI_CHECK(str   == NULL, 0);

    for(h = 0, p = (mtext *) str; (*p) != 0; p++)
    {
        c = *p;

        h = 31 * h + mttoupper(c);
    }

    return (h % table->size);
}
Beispiel #21
0
boolean OCI_TypeInfoClose(OCI_TypeInfo *typinf)
{
    ub2 i;

    OCI_CHECK(typinf == NULL, FALSE);

    for (i=0; i < typinf->nb_cols; i++)
    {
        OCI_FREE(typinf->cols[i].name);
    }

    OCI_FREE(typinf->cols);
    OCI_FREE(typinf->name);
    OCI_FREE(typinf->schema);
    OCI_FREE(typinf->offsets);

    return TRUE;
}
Beispiel #22
0
boolean OCI_ListFree
(
    OCI_List *list
)
{
    boolean res = TRUE;

    OCI_CHECK(list == NULL, FALSE);

    OCI_ListClear(list);

    if (list->mutex != NULL)
    {
        res = OCI_MutexFree(list->mutex);
    }

    OCI_FREE(list);

    return res;
}
Beispiel #23
0
boolean OCI_ListClear
(
    OCI_List *list
)
{
    OCI_Item *item = NULL;
    OCI_Item *temp = NULL;

    OCI_CHECK(list == NULL, FALSE);

    if (list->mutex != NULL)
    {
        OCI_MutexAcquire(list->mutex);
    }

    /* walk along the list to free item's buffer */

    item = list->head;

    while (item != NULL)
    {
        temp = item;
        item = item->next;

        /* free data */

        OCI_FREE(temp->data);
        OCI_FREE(temp);
    }

    list->head  = NULL;
    list->count = 0;

    if (list->mutex != NULL)
    {
        OCI_MutexRelease(list->mutex);
    }

    return TRUE;
}
Beispiel #24
0
const mtext * OCI_API OCI_HashGetString
(
    OCI_HashTable *table,
    const mtext   *key
)
{
    OCI_HashValue *v   = NULL;
    const mtext *value = NULL;

    OCI_CHECK_PTR(OCI_IPC_HASHTABLE, table, NULL);
    OCI_CHECK(table->type != OCI_HASH_STRING, NULL);

    v = OCI_HashGetValue(table, key);

    if (v != NULL)
    {
        value = v->value.p_mtext;
    }

    OCI_RESULT(v != NULL);

    return value;
}
Beispiel #25
0
size_t OCI_StringLength
(
    void  *ptr,
    size_t size_elem
)
{
    int size = 0;

    OCI_CHECK(NULL == ptr, 0);

    if (OCILib.nls_utf8)
    {
        const char *s = (char *) ptr;
        while (*s)
        {
            if ((*s & 0xc0) != 0x80) size++;
            s++;
        }
    }
    else if (sizeof(char) == size_elem)
    {
        COMPUTE_LENTGH(char, ptr, size)
    }
Beispiel #26
0
int OCI_API OCI_HashGetInt
(
    OCI_HashTable *table,
    const mtext   *key
)
{
    OCI_HashValue *v = NULL;
    int value        = 0;

    OCI_CHECK_PTR(OCI_IPC_HASHTABLE, table, 0);
    OCI_CHECK(table->type != OCI_HASH_INTEGER, 0);

    v = OCI_HashGetValue(table, key);

    if (v != NULL)
    {
        value = v->value.num;
    }

    OCI_RESULT(v != NULL);

    return value;
}
Beispiel #27
0
void * OCI_API OCI_HashGetPointer
(
    OCI_HashTable *table,
    const mtext   *key
)
{
    OCI_HashValue *v = NULL;
    void *value      = NULL;

    OCI_CHECK_PTR(OCI_IPC_HASHTABLE, table, NULL);
    OCI_CHECK(table->type != OCI_HASH_POINTER, NULL);

    v = OCI_HashGetValue(table, key);

    if (v != NULL)
    {
        value = v->value.p_void;
    }

    OCI_RESULT(v != NULL);

    return value;
}
Beispiel #28
0
OCI_Date * OCI_DateInit2(OCI_Library *pOCILib, OCI_Connection *con, OCI_Date **pdate, OCIDate *buffer,
                        boolean allocate, boolean ansi)
{
    OCI_Date *date = NULL;
    boolean res    = TRUE;

    OCI_CHECK(pdate == NULL, NULL);

    if (*pdate == NULL)
        *pdate = (OCI_Date *) OCI_MemAlloc2(pOCILib, OCI_IPC_DATE, sizeof(*date),
                                           (size_t) 1, TRUE);

    if (*pdate != NULL)
    {
        date = *pdate;

        date->con = con;

        /* get the right error handle */

        if (con != NULL)
            date->err = con->err;
        else
            date->err = pOCILib->err;

        /* allocate buffer if needed */

        if ((date->handle == NULL) && ((allocate == TRUE) || (ansi == TRUE)))
        {
            date->allocated = TRUE;

            if (allocate == TRUE)
                date->hstate = OCI_OBJECT_ALLOCATED;

            date->handle = (OCIDate *) OCI_MemAlloc2(pOCILib, OCI_IPC_OCIDATE,
                                                    sizeof(*date->handle),
                                                    (size_t) 1, TRUE);

            res = (date->handle != NULL);
        }
        else
        {
            if (date->hstate != OCI_OBJECT_ALLOCATED_ARRAY)
            {
                date->hstate = OCI_OBJECT_FETCHED_CLEAN;
            }

            date->handle = buffer;
        }

        /* if the input buffer is an SQLT_DAT buffer, we need to convert it */

        if ((ansi == TRUE) && (buffer != NULL))
        {
            unsigned char *d = (unsigned char *) buffer;

            date->handle->OCIDateYYYY = (sb2) (((d[0] - 100) * 100) + (d[1] - 100));
            date->handle->OCIDateMM   = (ub1) d[2];
            date->handle->OCIDateDD   = (ub1) d[3];

            date->handle->OCIDateTime.OCITimeHH = (ub1) (d[4] - 1);
            date->handle->OCIDateTime.OCITimeMI = (ub1) (d[5] - 1);
            date->handle->OCIDateTime.OCITimeSS = (ub1) (d[6] - 1);
        }
    }
    else
        res = FALSE;

   /* check for failure */

    if (res == FALSE)
    {
       OCI_DateFree(pOCILib, date);
        date = NULL;
    }

    return date;
}
Beispiel #29
0
boolean OCI_NumberGet
(
    OCI_Connection *con,
    void           *number,
    uword           size,
    uword           type,
    int             sqlcode,
    void           *out_value
)
{
    boolean res = TRUE;

    OCI_CHECK(con       == NULL, FALSE);
    OCI_CHECK(number    == NULL, FALSE);
    OCI_CHECK(out_value == NULL, FALSE);

#if OCI_VERSION_COMPILE < OCI_10_1

    OCI_NOT_USED(sqlcode);

#endif

    if (type == OCI_NUM_NUMBER)
    {
        memcpy(out_value, number, size);
    }
    else if (type & OCI_NUM_DOUBLE || type & OCI_NUM_FLOAT)
    {

    #if OCI_VERSION_COMPILE >= OCI_10_1

        if ((OCILib.version_runtime >= OCI_10_1) && ((sqlcode != SQLT_VNU)))
        {
            if (((type & OCI_NUM_DOUBLE) && (sqlcode == SQLT_BDOUBLE)) ||
                ((type & OCI_NUM_FLOAT ) && (sqlcode == SQLT_BFLOAT )))
            {
                memcpy(out_value, number, size);
            }
            else if (type & OCI_NUM_DOUBLE && sqlcode == SQLT_BFLOAT)
            {
                *((double *) out_value) = (double) *((float *) number);
            }
            else if (type & OCI_NUM_FLOAT && sqlcode == SQLT_BDOUBLE)
            {
                 *((float *) out_value) = (float) *((double *) number);
            }
        }
        else

    #endif

        {
            OCI_CALL2
            (
                res, con,

                OCINumberToReal(con->err, (OCINumber *) number, size, out_value)
            )
        }
    }  
    else
    {
Beispiel #30
0
OCI_Date * OCI_DateInit
(
    OCI_Connection *con,
    OCI_Date      **pdate,
    OCIDate        *buffer,
    boolean         allocate,
    boolean         ansi
)
{
    OCI_Date *date = NULL;
    boolean   res  = FALSE;

    OCI_CHECK(NULL == pdate, NULL);

    if (!*pdate)
    {
        *pdate = (OCI_Date *) OCI_MemAlloc(OCI_IPC_DATE, sizeof(*date), (size_t) 1, TRUE);
    }

    if (*pdate)
    {
        res = TRUE;

        date = *pdate;

        date->con = con;

        /* get the right error handle */

        if (con)
        {
            date->err = con->err;
            date->env = con->env;
        }
        else
        {
            date->err = OCILib.err;
            date->env = OCILib.env;
        }

        /* allocate buffer if needed */

        if (!date->handle && (allocate || ansi))
        {
            date->allocated = TRUE;

            if (allocate)
            {
                date->hstate = OCI_OBJECT_ALLOCATED;
            }

            date->handle = (OCIDate *) OCI_MemAlloc(OCI_IPC_OCIDATE, sizeof(*date->handle),
                                                    (size_t) 1, TRUE);

            res = (NULL != date->handle);
        }
        else
        {
            if (OCI_OBJECT_ALLOCATED_ARRAY != date->hstate)
            {
                date->hstate = OCI_OBJECT_FETCHED_CLEAN;
            }

            date->handle = buffer;
        }

        /* if the input buffer is an SQLT_DAT buffer, we need to convert it */

        if (ansi && buffer)
        {
            unsigned char *d = (unsigned char *) buffer;

            date->handle->OCIDateYYYY = (sb2) (((d[0] - 100) * 100) + (d[1] - 100));
            date->handle->OCIDateMM   = (ub1) d[2];
            date->handle->OCIDateDD   = (ub1) d[3];

            date->handle->OCIDateTime.OCITimeHH = (ub1) (d[4] - 1);
            date->handle->OCIDateTime.OCITimeMI = (ub1) (d[5] - 1);
            date->handle->OCIDateTime.OCITimeSS = (ub1) (d[6] - 1);
        }
    }

    /* check for failure */

    if (!res && date)
    {
        OCI_DateFree(date);
        *pdate = date = NULL;
    }

    return date;
}