Exemplo n.º 1
0
OCI_Item * OCI_ListCreateItem
(
    int type,
    int size
)
{
    OCI_Item *item = NULL;

    /* allocate list item entry */

    item = (OCI_Item *) OCI_MemAlloc(OCI_IPC_LIST_ITEM, sizeof(*item), (size_t) 1, TRUE);

    if (item != NULL)
    {
        /* allocate item data buffer */

        item->data = (void *) OCI_MemAlloc(type, (size_t) size, (size_t) 1, TRUE);

        if (item->data == NULL)
        {
            OCI_FREE(item);
        }
    }

    return item;
}
Exemplo n.º 2
0
OCI_Mutex * OCI_MutexCreateInternal
(
    void
)
{
    OCI_CALL_DECLARE_CONTEXT(TRUE)
        
    OCI_Mutex *mutex = NULL;

    /* allocate mutex structure */

    mutex = (OCI_Mutex *) OCI_MemAlloc(OCI_IPC_MUTEX, sizeof(*mutex), (size_t) 1, TRUE);
    OCI_STATUS = (NULL != mutex);

    if (OCI_STATUS)
    {
        /* allocate error handle */

        OCI_STATUS = OCI_HandleAlloc(OCILib.env, (dvoid **)(void *)&mutex->err, OCI_HTYPE_ERROR);

        /* allocate mutex handle */

        OCI_EXEC(OCIThreadMutexInit(OCILib.env, mutex->err, &mutex->handle))
    }

    if (!OCI_STATUS && mutex)
    {
        OCI_MutexFree(mutex);
        mutex = NULL;
    }

    return mutex;
}
Exemplo n.º 3
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;
}
Exemplo n.º 4
0
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()
}
Exemplo n.º 5
0
OCI_List * OCI_ListCreate
(
    int type
)
{
    OCI_List *list = NULL;

    /* allocate list */

    list = (OCI_List *) OCI_MemAlloc(OCI_IPC_LIST, sizeof(*list), (size_t) 1, TRUE);

    /* create a mutex on multithreaded environments */

    if (list != NULL)
    {
        list->type = type;

        if (OCI_LIB_THREADED)
        {
            list->mutex = OCI_MutexCreateInternal();

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

    return list;
}
Exemplo n.º 6
0
OCI_ThreadKey * OCI_ThreadKeyCreateInternal
(
    POCI_THREADKEYDEST destfunc
)
{
    boolean res        = TRUE;
    OCI_ThreadKey *key = NULL;

    /* allocate key structure */

    key = (OCI_ThreadKey *) OCI_MemAlloc(OCI_IPC_THREADKEY, sizeof(*key), (size_t) 1, TRUE);

    if (key != NULL)
    {
        /* allocate error handle */

        res = (OCI_SUCCESS == OCI_HandleAlloc(OCILib.env,
                                              (dvoid **) (void *) &key->err,
                                              OCI_HTYPE_ERROR, (size_t) 0,
                                              (dvoid **) NULL));

        /* key initialization */

        OCI_CALL3
        (
            res, key->err,

            OCIThreadKeyInit(OCILib.env, key->err, &key->handle, destfunc)
        )
    }
Exemplo n.º 7
0
OCI_HashTable * OCI_API OCI_HashCreate
(
    unsigned int size,
    unsigned int type
)
{
    OCI_HashTable *table = NULL;

    OCI_LIB_CALL_ENTER(OCI_HashTable*, table)

    OCI_CHECK_ENUM_VALUE(NULL, NULL, type, HashTypeValues, OTEXT("Hash type"));

    /* allocate table structure */

    table = (OCI_HashTable *) OCI_MemAlloc(OCI_IPC_HASHTABLE, sizeof(*table), (size_t) 1, TRUE);

    /* set up attributes and allocate internal array of hash entry pointers */

    if (table)
    {
        table->type  = type;
        table->size  = 0;
        table->count = 0;

        table->items = (OCI_HashEntry **) OCI_MemAlloc(OCI_IPC_HASHENTRY_ARRAY,
                                                       sizeof(*table->items),
                                                       (size_t) size, TRUE);
        if (table->items)
        {
            table->size = size;           
            
            call_status = TRUE;
        }
    }

    if (call_status)
    {
        call_retval = table;
    }
    else if (table)
    {
        OCI_HashFree(table);
    }

    OCI_LIB_CALL_EXIT()
}
Exemplo n.º 8
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);
        }
    }
Exemplo n.º 9
0
boolean OCI_API OCI_MsgSetConsumers
(
    OCI_Msg     *msg,
    OCI_Agent  **consumers,
    unsigned int count
)
{
    boolean res          = TRUE;
    OCIAQAgent **handles = NULL;

    OCI_CHECK_PTR(OCI_IPC_MSG, msg, FALSE);

    /* allocate local array of OCIAQAgent handles if needed */

    if ((consumers != NULL) && (count > 0))
    {
        handles = (OCIAQAgent **) OCI_MemAlloc(OCI_IPC_ARRAY,sizeof(OCIAQAgent *), count, FALSE);

        if (handles != NULL)
        {
            unsigned int i;

            for(i = 0; i < count; i++)
            {
                handles[i] = consumers[i]->handle;
            }
        }
    }
    else
    {
        count = 0;
    }

    OCI_CALL2
    (
        res, msg->typinf->con,

        OCIAttrSet((dvoid *) msg->proph,
                   (ub4    ) OCI_DTYPE_AQMSG_PROPERTIES,
                   (dvoid *) handles,
                   (ub4    ) count,
                   (ub4    ) OCI_ATTR_RECIPIENT_LIST,
                   msg->typinf->con->err)
    )


    /* free local array of OCIAQAgent handles if needed */

    if (handles != NULL)
    {
        OCI_FREE(handles);
    }

    OCI_RESULT(res);

    return res;
}
Exemplo n.º 10
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);
}
Exemplo n.º 11
0
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;
}
Exemplo n.º 12
0
OCI_Msg * OCI_API OCI_MsgCreate
(
    OCI_TypeInfo *typinf
)
{
    OCI_Msg *msg = NULL;
    boolean res  = TRUE;

    OCI_CHECK_INITIALIZED(NULL);

    OCI_CHECK_PTR(OCI_IPC_TYPE_INFO, typinf, NULL);

    /* allocate message structure */

    msg = (OCI_Msg *) OCI_MemAlloc(OCI_IPC_MSG, sizeof(*msg), (size_t) 1, TRUE);

    if (msg != NULL)
    {
        msg->typinf = typinf;
        msg->ind    = OCI_IND_NULL;

        /* allocate message properties descriptor */

        res = (OCI_SUCCESS == OCI_DescriptorAlloc((dvoid * ) msg->typinf->con->env,
                                                  (dvoid **) &msg->proph,
                                                  OCI_DTYPE_AQMSG_PROPERTIES,
                                                  (size_t) 0, (dvoid **) NULL));

        if (res == TRUE)
        {
            /* allocate internal OCI_Object handle if payload is not RAW */

            if (msg->typinf->tcode != OCI_UNKNOWN)
            {
                msg->obj = OCI_ObjectCreate(typinf->con, typinf);

                res = (msg->obj != NULL);
            }
        }
    }
    else
    {
        res = FALSE;
    }

    /* check for failure */

    if (res == FALSE)
    {
        OCI_MsgFree(msg);
        msg = NULL;
    }

    return msg;
}
Exemplo n.º 13
0
OCI_Dequeue * OCI_API OCI_DequeueCreate
(
    OCI_TypeInfo *typinf,
    const mtext  *name
)
{
    OCI_Dequeue *dequeue = NULL;
    boolean res          = TRUE;

    OCI_CHECK_INITIALIZED(NULL);

    OCI_CHECK_PTR(OCI_IPC_TYPE_INFO, typinf, NULL);
    OCI_CHECK_PTR(OCI_IPC_STRING, name, NULL);

    /* allocate dequeue structure */

    dequeue = (OCI_Dequeue *) OCI_MemAlloc(OCI_IPC_DEQUEUE, sizeof(*dequeue), (size_t) 1, TRUE);

    if (dequeue != NULL)
    {
        dequeue->typinf = typinf;
        dequeue->name   = mtsdup(name);

        /* allocate dequeue options descriptor */

        res = (OCI_SUCCESS == OCI_DescriptorAlloc((dvoid * ) dequeue->typinf->con->env,
                                                  (dvoid **) &dequeue->opth,
                                                  OCI_DTYPE_AQDEQ_OPTIONS,
                                                  (size_t) 0, (dvoid **) NULL));

        /* create local message for OCI_DequeueGet() */

        if (res == TRUE)
        {
            dequeue->msg = OCI_MsgCreate(dequeue->typinf);
        }

        res = (dequeue->msg != NULL);
    }
    else
    {
        res = FALSE;
    }

    /* check for failure */

    if (res == FALSE)
    {
        OCI_DequeueFree(dequeue);
        dequeue = NULL;
    }

    return dequeue;
}
Exemplo n.º 14
0
OCI_HashTable * OCI_API OCI_HashCreate
(
    unsigned int size,
    unsigned int type
)
{
    OCI_HashTable *table = NULL;
    boolean res          = TRUE;

    /* allocate table structure */

    table = (OCI_HashTable *) OCI_MemAlloc(OCI_IPC_HASHTABLE, sizeof(*table), (size_t) 1, TRUE);

    /* set up attributes and allocate internal array of hash entry pointers */

    if (table != NULL)
    {
        table->size  = size;
        table->type  = type;
        table->count = 0;

        table->items = (OCI_HashEntry **) OCI_MemAlloc(OCI_IPC_HASHENTRY_ARRAY,
                                                       sizeof(*table->items),
                                                       (size_t) size, TRUE);
        res = (table->items != NULL);
    }
    else
    {
        res = FALSE;
    }

    if (res == FALSE)
    {
        OCI_HashFree(table);
    }

    OCI_RESULT(res);

    return table;
}
Exemplo n.º 15
0
OCI_Msg * OCI_API OCI_MsgCreate
(
    OCI_TypeInfo *typinf
)
{
    OCI_Msg *msg = NULL;

    OCI_CALL_ENTER(OCI_Msg*, NULL)
    OCI_CALL_CHECK_PTR(OCI_IPC_TYPE_INFO, typinf)
    OCI_CALL_CONTEXT_SET_FROM_CONN(typinf->con)

    /* allocate message structure */

    msg = (OCI_Msg *) OCI_MemAlloc(OCI_IPC_MSG, sizeof(*msg), (size_t) 1, TRUE);
    OCI_STATUS = (NULL != msg);

    if (OCI_STATUS)
    {
        msg->typinf = typinf;
        msg->ind    = OCI_IND_NULL;

        /* allocate message properties descriptor */

        OCI_STATUS = OCI_DescriptorAlloc((dvoid *)msg->typinf->con->env, (dvoid **)&msg->proph, OCI_DTYPE_AQMSG_PROPERTIES);

        if (OCI_STATUS)
        {
            /* allocate internal OCI_Object handle if payload is not RAW */

            if (OCI_UNKNOWN != msg->typinf->typecode)
            {
                msg->obj = OCI_ObjectCreate(typinf->con, typinf);

                OCI_STATUS = (NULL != msg->obj);
            }
        }
    }

    /* check for failure */

    if (OCI_STATUS)
    {
        OCI_RETVAL = msg;
    }
    else if (msg)
    {
        OCI_MsgFree(msg);
        msg = NULL;
    }

    OCI_CALL_EXIT()
}
Exemplo n.º 16
0
OCI_Dequeue * OCI_API OCI_DequeueCreate
(
    OCI_TypeInfo *typinf,
    const otext  *name
)
{
    OCI_Dequeue *dequeue = NULL;

    OCI_LIB_CALL_ENTER(OCI_Dequeue*, dequeue)

    OCI_CHECK_PTR(OCI_IPC_TYPE_INFO, typinf)
    OCI_CHECK_PTR(OCI_IPC_STRING, name)

    /* allocate dequeue structure */

    dequeue = (OCI_Dequeue *)OCI_MemAlloc(OCI_IPC_DEQUEUE, sizeof(*dequeue), (size_t)1, TRUE);

    if (dequeue)
    {
        dequeue->typinf = typinf;
        dequeue->name   = ostrdup(name);

        /* allocate dequeue options descriptor */

        call_status = OCI_SUCCESSFUL(OCI_DescriptorAlloc((dvoid *)dequeue->typinf->con->env,
                                                         (dvoid **) &dequeue->opth,
                                                         OCI_DTYPE_AQDEQ_OPTIONS,
                                                         (size_t) 0, (dvoid **) NULL));

        /* create local message for OCI_DequeueGet() */

        if (call_status)
        {
            dequeue->msg = OCI_MsgCreate(dequeue->typinf);
        }

        call_status = (NULL !=  dequeue->msg);
    }

    /* check for failure */

    if (call_status)
    {
        call_retval = dequeue;
    }
    else if (dequeue)
    {
        OCI_DequeueFree(dequeue);
    }

    OCI_LIB_CALL_EXIT()
}
Exemplo n.º 17
0
OCI_Coll * OCI_CollInit
(
    OCI_Connection *con,
    OCI_Coll      **pcoll,
    void           *handle,
    OCI_TypeInfo   *typinf
)
{
    OCI_Coll *coll = NULL;
    boolean   res  = FALSE;

    OCI_CHECK(NULL == pcoll, NULL)

    if (!*pcoll)
    {
        *pcoll = (OCI_Coll *) OCI_MemAlloc(OCI_IPC_COLLECTION, sizeof(*coll), (size_t) 1, TRUE);
    }

    if (*pcoll)
    {
        res = TRUE;

        coll = *pcoll;

        coll->con    = con;
        coll->handle = handle;
        coll->typinf = typinf;

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

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

            OCI_CALL2
            (
                res, con,

                OCI_ObjectNew(coll->con->env, coll->con->err, coll->con->cxt,
                              typinf->colcode, typinf->tdo, (void *) NULL,
                              OCI_DURATION_SESSION, TRUE, (dvoid **) &coll->handle)
            )
        }
        else
        {
            coll->hstate = OCI_OBJECT_FETCHED_CLEAN;
        }
    }
Exemplo n.º 18
0
boolean OCI_API OCI_DequeueSetAgentList
(
    OCI_Dequeue *dequeue,
    OCI_Agent  **consumers,
    unsigned int count
)
{
    boolean res = TRUE;

    OCI_CHECK_PTR(OCI_IPC_ENQUEUE, dequeue, FALSE);

    OCI_FREE(dequeue->agent_list);

    if ((consumers != NULL) && (count > 0))
    {
        dequeue->agent_list = (OCIAQAgent **) OCI_MemAlloc(OCI_IPC_ARRAY,  sizeof(OCIAQAgent *),
                                                           count, FALSE);

        if (dequeue->agent_list != NULL)
        {
            unsigned int i;

            for(i = 0; i < count; i++)
            {
                dequeue->agent_list[i] = consumers[i]->handle;
            }

            dequeue->agent_count = (ub4) count;
        }
        else
        {
            res = FALSE;
        }
    }

    OCI_RESULT(res);

    return res;
}
Exemplo n.º 19
0
Arquivo: mutex.c Projeto: ysmgigi/dbss
OCI_Mutex * OCI_MutexCreateInternal
(
    void
)
{
    OCI_Mutex *mutex = NULL;
    boolean    res   = FALSE;

    /* allocate mutex structure */

    mutex = (OCI_Mutex *) OCI_MemAlloc(OCI_IPC_MUTEX, sizeof(*mutex), (size_t) 1, TRUE);

    if (mutex)
    {
        /* allocate error handle */

        res = OCI_SUCCESSFUL(OCI_HandleAlloc(OCILib.env, (dvoid **) (void *) &mutex->err,
                                             OCI_HTYPE_ERROR, (size_t) 0, (dvoid **) NULL));

        /* allocate mutex handle */

        OCI_CALL3
        (
            res, mutex->err,

            OCIThreadMutexInit(OCILib.env, mutex->err, &mutex->handle)
        )
    }

    if (!res && mutex)
    {
        OCI_MutexFree(mutex);
        mutex = NULL;
    }

    return mutex;
}
Exemplo n.º 20
0
boolean OCI_DefineAlloc
(
    OCI_Define *def
)
{
    boolean res = TRUE;
    ub4 indsize = 0;
    ub4 i;

    /* this function allocates internal buffers, handles, indicators, arrays, ...
       for the given output define handle */

    OCI_CHECK(NULL == def, FALSE)

    /* Allocate null indicators array */

    if (SQLT_NTY == def->col.sqlcode || SQLT_REF == def->col.sqlcode)
    {
        indsize = (ub4) sizeof(void*);
    }
    else
    {
        indsize = (ub4) sizeof(sb2);
    }

    def->buf.inds = (void *) OCI_MemAlloc(OCI_IPC_INDICATOR_ARRAY, (size_t) indsize,
                                          (size_t) def->buf.count, TRUE);
    res = (NULL != def->buf.inds);

    if (OCI_CDT_OBJECT == def->col.datatype)
    {
        def->buf.obj_inds = (void **) OCI_MemAlloc(OCI_IPC_INDICATOR_ARRAY, sizeof(void *),
                                                   (size_t) def->buf.count, TRUE);
        res = (NULL != def->buf.obj_inds);
    }

    /* Allocate row data sizes array */

    if (res)
    {
        def->buf.lens = (void *) OCI_MemAlloc(OCI_IPC_LEN_ARRAY, (size_t) def->buf.sizelen,
                                              (size_t) def->buf.count, TRUE);
        res = (NULL != def->buf.lens);
    }

    /* initialize length array with buffer default size.
       But, Oracle uses different sizes for static fetch and callback fetch....*/

    if (res)
    {
       ub4 bufsize = 0;

        for (i=0; i < def->buf.count; i++)
        {
            if (def->buf.sizelen == (int) sizeof(ub2))
            {
                *(ub2*)(((ub1 *)def->buf.lens) + (size_t) (def->buf.sizelen*i)) = (ub2) def->col.bufsize;
            }
            else if (def->buf.sizelen == (int) sizeof(ub4))
            {
                *(ub4*)(((ub1 *)def->buf.lens) + (size_t) (def->buf.sizelen*i)) = (ub4) def->col.bufsize;
            }
        }

        /* Allocate buffer array */

        if (OCI_CDT_LONG == def->col.datatype)
        {
            bufsize = (ub4) sizeof(OCI_Long *);
        }
        else
        {
            bufsize = def->col.bufsize;
        }

        def->buf.data = (void **) OCI_MemAlloc(OCI_IPC_BUFF_ARRAY, (size_t) bufsize,
                                                (size_t) def->buf.count, TRUE);

        res = (NULL != def->buf.data);
    }

    /* Allocate descriptor for cursor, lob and file, interval and timestamp */

    if (res && OCI_UNKNOWN != def->col.handletype)
    {
        if (OCI_CDT_CURSOR == def->col.datatype)
        {
            for (i = 0; (i < def->buf.count) && res; i++)
            {
                res = OCI_SUCCESSFUL(OCI_HandleAlloc((dvoid  *) def->rs->stmt->con->env,
                                                        (dvoid **) &(def->buf.data[i]),
                                                        (ub4) def->col.handletype,
                                                        (size_t) 0, (dvoid **) NULL));
            }
        }
        else
        {
            res = OCI_SUCCESSFUL(OCI_DescriptorArrayAlloc((dvoid  *) def->rs->stmt->con->env,
                                                            (dvoid **) def->buf.data,
                                                            (ub4) def->col.handletype,
                                                            (ub4) def->buf.count,
                                                            (size_t) 0, (dvoid **) NULL));

            if (res && (OCI_CDT_LOB == def->col.datatype))
            {
                ub4 empty = 0;

                for (i = 0; (i < def->buf.count) && res; i++)
                {
                    OCI_CALL1
                    (
                        res, def->rs->stmt->con, def->rs->stmt,

                        OCIAttrSet((dvoid *) def->buf.data[i],  (ub4) def->col.handletype,
                                   (void *) &empty, (ub4) sizeof(empty),
                                   (ub4) OCI_ATTR_LOBEMPTY, def->rs->stmt->con->err)
                    )
                }
            }
        }
    }
Exemplo n.º 21
0
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;
}
Exemplo n.º 22
0
boolean OCI_ColumnDescribe
(
    OCI_Column     *col,
    OCI_Connection *con,
    OCI_Statement  *stmt,
    void           *handle,
    int             index,
    int             ptype
)
{
    void    *param    = NULL;
    boolean  res      = TRUE;

    /* get descriptor */

    if (ptype == OCI_DESC_COLLECTION)
    {
        OCI_CALL1
        (
            res, con, stmt,

            OCIAttrGet((dvoid *) handle, (ub4) OCI_DTYPE_PARAM, (dvoid *) &param,
                       (ub4 *) NULL, (ub4) OCI_ATTR_COLLECTION_ELEMENT, con->err)
        )
    }
    else
    {
        ub4 htype = 0;

        if (ptype == OCI_DESC_RESULTSET)
        {
            htype = OCI_HTYPE_STMT;
        }
        else
        {
            htype = OCI_DTYPE_PARAM;
        }

        OCI_CALL1
        (
            res, con, stmt,

            OCIParamGet((dvoid *) handle, htype,  con->err, (void**) &param, (ub4) index)
        )
    }

    /* sql code */

    OCI_CALL1
    (
        res, con, stmt,

        OCIAttrGet((dvoid *) param, (ub4) OCI_DTYPE_PARAM, (dvoid *) &col->ocode,
                   (ub4 *) NULL, (ub4) OCI_ATTR_DATA_TYPE, con->err)
    )

    /* size */

    OCI_CALL1
    (
        res, con, stmt,

        OCIAttrGet((dvoid *) param, (ub4)  OCI_DTYPE_PARAM, (dvoid *) &col->size,
                   (ub4 *) NULL, (ub4) OCI_ATTR_DATA_SIZE, con->err)
    )

    /* scale */

    OCI_CALL1
    (
        res, con, stmt,

        OCIAttrGet((dvoid *) param, (ub4) OCI_DTYPE_PARAM, (dvoid *) &col->scale,
                   (ub4 *) NULL, (ub4) OCI_ATTR_SCALE, con->err)
    )

    /* precision */

    if (ptype == OCI_DESC_RESULTSET)
    {
        sb2 prec = 0;

        OCI_CALL1
        (
            res, con, stmt,

            OCIAttrGet((dvoid *) param, (ub4) OCI_DTYPE_PARAM, (dvoid *) &prec,
                       (ub4 *) NULL, (ub4) OCI_ATTR_PRECISION, con->err)
        )

        col->prec = (sb2) prec;
    }
    else
    {
        ub1 prec = 0;

        OCI_CALL1
        (
            res, con, stmt,

            OCIAttrGet((dvoid *) param, (ub4) OCI_DTYPE_PARAM, (dvoid *) &prec,
                       (ub4 *) NULL, (ub4) OCI_ATTR_PRECISION, con->err)
        )

        col->prec = (sb2) prec;
    }

    /* charset form */

    OCI_CALL1
    (
        res, con, stmt,

        OCIAttrGet((dvoid *) param, (ub4) OCI_DTYPE_PARAM, (dvoid *) &col->csfrm,
                   (ub4 *) NULL, (ub4) OCI_ATTR_CHARSET_FORM, con->err)
    )

    /* type of column length for string based column */

#if OCI_VERSION_COMPILE >= OCI_9_2

    if ((OCILib.version_runtime >= OCI_9_2) && (con->ver_num >= OCI_9_2))
    {
        /* char used - no error checking because on Oracle 9.0, querying
                       this param that is not char/varchar based will cause an
                       error */

        OCI_CALL1
        (
            res, con, stmt,

            OCIAttrGet((dvoid *) param, (ub4) OCI_DTYPE_PARAM,
                       (dvoid *) &col->charused, (ub4 *) NULL,
                       (ub4) OCI_ATTR_CHAR_USED, con->err)
        )
    }

    /* char size */

    if (col->charused == TRUE)
    {
        OCI_CALL1
        (
            res, con, stmt,

            OCIAttrGet((dvoid *) param, (ub4) OCI_DTYPE_PARAM,
                       (dvoid *) &col->charsize, (ub4 *) NULL,
                       (ub4) OCI_ATTR_CHAR_SIZE, con->err)
        )
    }

    if ((OCILib.version_runtime >= OCI_9_0) && (con->ver_num >= OCI_9_0))
    {
        /* fractional time precision for timestamps */

        if (col->ocode == SQLT_TIMESTAMP    ||
                col->ocode == SQLT_TIMESTAMP_TZ ||
                col->ocode == SQLT_TIMESTAMP_LTZ)
        {
            OCI_CALL1
            (
                res, con, stmt,

                OCIAttrGet((dvoid *) param, (ub4) OCI_DTYPE_PARAM,
                           (dvoid *) &col->prec, (ub4 *) NULL,
                           (ub4) OCI_ATTR_FSPRECISION, con->err)
            )
        }

        /* leading and fractional precision for interval */

        if (col->ocode == SQLT_INTERVAL_DS || col->ocode == SQLT_INTERVAL_YM)
        {
            OCI_CALL1
            (
                res, con, stmt,

                OCIAttrGet((dvoid *) param, (ub4) OCI_DTYPE_PARAM,
                           (dvoid *) &col->prec, (ub4 *) NULL,
                           (ub4) OCI_ATTR_LFPRECISION, con->err)
            )

            OCI_CALL1
            (
                res, con, stmt,

                OCIAttrGet((dvoid *) param, (ub4) OCI_DTYPE_PARAM,
                           (dvoid *) &col->prec2, (ub4 *) NULL,
                           (ub4) OCI_ATTR_FSPRECISION, con->err)
            )
        }
    }

#endif

    /* check nullable only for table based column */

    if (ptype < OCI_DESC_TYPE)
    {
        OCI_CALL1
        (
            res, con, stmt,

            OCIAttrGet((dvoid *) param, (ub4) OCI_DTYPE_PARAM,
                       (dvoid *) &col->null, (ub4 *) NULL,
                       (ub4) OCI_ATTR_IS_NULL, con->err)
        )
    }
    else
    {
        col->null = TRUE;
    }

    /* name */

    if (res == TRUE)
    {
        void *ostr     = NULL;
        int   osize    = 0;
        ub4   attrname = 0;

        if (ptype == OCI_DESC_COLLECTION)
        {
            attrname = OCI_ATTR_TYPE_NAME;
        }
        else
        {
            attrname = OCI_ATTR_NAME;
        }

        OCI_CALL1
        (
            res, con, stmt,

            OCIAttrGet((dvoid *) param, (ub4) OCI_DTYPE_PARAM, (dvoid *) &ostr,
                       (ub4 *) &osize, (ub4) attrname, con->err)
        )

        if ((res == TRUE) && (ostr != NULL))
        {
            col->name = (mtext *) OCI_MemAlloc(OCI_IPC_STRING, sizeof(mtext),
                                               (size_t) ((osize / (int) sizeof(omtext)) + 1), TRUE);

            if (col->name != NULL)
            {
                OCI_CopyString(ostr, col->name, &osize, sizeof(omtext), sizeof(mtext));
            }
            else
            {
                res = FALSE;
            }
        }
    }
Exemplo n.º 23
0
OCI_File * OCI_FileInit
(
    OCI_Connection *con,
    OCI_File      **pfile,
    OCILobLocator  *handle,
    ub4             type
)
{
    OCI_File *file = NULL;
    boolean res    = TRUE;

    OCI_CHECK(pfile == NULL, NULL);

    if (*pfile == NULL)
    {
        *pfile = (OCI_File *) OCI_MemAlloc(OCI_IPC_FILE, sizeof(*file), (size_t) 1, TRUE);
    }

    if (*pfile != NULL)
    {
        file = *pfile;

        file->type   = type;
        file->con    = con;
        file->handle = handle;
        file->offset = 1;

        /* reset file info */

        if (file->dir != NULL)
        {
            file->dir[0] = 0;
        }

        if (file->name != NULL)
        {
            file->name[0] = 0;
        }

        if (file->handle == NULL)
        {
            /* allocate handle for non fetched file (local file object) */

            file->hstate = OCI_OBJECT_ALLOCATED;

            res = (OCI_SUCCESS == OCI_DescriptorAlloc((dvoid *) file->con->env,
                                                      (dvoid **) (void *) &file->handle,
                                                      (ub4) OCI_DTYPE_LOB,
                                                      (size_t) 0, (dvoid **) NULL));
        }
        else if (file->hstate != OCI_OBJECT_ALLOCATED_ARRAY)
        {
            file->hstate = OCI_OBJECT_FETCHED_CLEAN;
        }
    }
    else
    {
        res = FALSE;
    }

    /* check for failure */

    if (res == FALSE)
    {
        OCI_FileFree(file);
        file = NULL;
    }

    return file;
}
Exemplo n.º 24
0
        /* set columns count attribute */

        OCI_CALL2
        (
            res, dp->con,

            OCIAttrSet((dvoid *) dp->ctx, (ub4) OCI_HTYPE_DIRPATH_CTX,
                       (dvoid *) &dp->nb_cols, (ub4) sizeof(dp->nb_cols),
                       (ub4) OCI_ATTR_NUM_COLS, dp->con->err)
        )

        /* allocating the column array */

        if (res == TRUE)
        {
            dp->cols = (void *) OCI_MemAlloc(OCI_IPC_DP_COL_ARRAY, sizeof(OCI_DirPathColumn),
                                             (size_t) dp->nb_cols, TRUE);

            res = (dp->cols != NULL);
        }
    }
    else
    {
        res = FALSE;
    }

    /* handle errors */

    if (res == FALSE)
    {
        OCI_DirPathFree(dp);
        dp = NULL;
Exemplo n.º 25
0
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)
            )
        }
Exemplo n.º 26
0
OCI_Object * OCI_ObjectInit
(
    OCI_Connection *con,
    OCI_Object    **pobj,
    void           *handle,
    OCI_TypeInfo   *typinf,
    OCI_Object     *parent,
    int             index,
    boolean         reset
)
{
    OCI_Object * obj = NULL;
    boolean res      = TRUE;

    OCI_CHECK(pobj == NULL, NULL);

    if (*pobj == NULL)
    {
        *pobj = (OCI_Object *) OCI_MemAlloc(OCI_IPC_OBJECT, sizeof(*obj), (size_t) 1, TRUE);
    }

    if (*pobj != NULL)
    {
        obj = *pobj;

        obj->con    = con;
        obj->handle = handle;
        obj->typinf = typinf;

        if (obj->objs == NULL)
        {
            obj->objs = (void **) OCI_MemAlloc(OCI_IPC_BUFF_ARRAY, sizeof(void *),
                                               (size_t) typinf->nb_cols, TRUE);
        }
        else
        {
            OCI_ObjectReset(obj);
        }

        res = (obj->objs != NULL);

        if (((res == TRUE)) && ((obj->handle == NULL) || (obj->hstate == OCI_OBJECT_ALLOCATED_ARRAY)))
        {
            /* allocates handle for non fetched object */

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

            OCI_CALL2
            (
                res, obj->con,

                OCI_ObjectNew(obj->con->env,  obj->con->err, obj->con->cxt,
                              (OCITypeCode) SQLT_NTY, obj->typinf->tdo, (dvoid *) NULL,
                              (OCIDuration) OCI_DURATION_SESSION, (boolean) TRUE,
                              (dvoid **) &obj->handle)
            )
        }
        else
        {
Exemplo n.º 27
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;
}
Exemplo n.º 28
0
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)
    }