コード例 #1
0
ファイル: dequeue.c プロジェクト: bookiant/ocilib
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()
}
コード例 #2
0
ファイル: transaction.c プロジェクト: bookiant/ocilib
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)
            )
        }
    }
コード例 #3
0
ファイル: memory.c プロジェクト: Wushaowei001/ocilib
boolean OCI_DescriptorAlloc
(
    CONST dvoid *parenth,
    dvoid      **descpp,
    CONST ub4    type
 )
{
    sword ret = OCIDescriptorAlloc(parenth, descpp, type, 0, NULL);

    if (OCI_SUCCESSFUL(ret))
    {
        OCI_MUTEXED_CALL(OCILib.nb_descp++)
    }

    return OCI_SUCCESSFUL(ret);
}
コード例 #4
0
ファイル: memory.c プロジェクト: Wushaowei001/ocilib
boolean OCI_HandleAlloc
(
    CONST dvoid *parenth,
    dvoid      **hndlpp,
    CONST ub4    type
 )
{
    sword ret = OCIHandleAlloc(parenth, hndlpp, type, 0, NULL);

    if (OCI_SUCCESSFUL(ret))
    {
        OCI_MUTEXED_CALL(OCILib.nb_hndlp++)
    }

    return OCI_SUCCESSFUL(ret);
}
コード例 #5
0
ファイル: memory.c プロジェクト: Wushaowei001/ocilib
boolean OCI_DescriptorFree
(
    dvoid    *descp,
    CONST ub4 type
)
{
    sword ret = OCI_SUCCESS;

    if (descp)
    {
        OCI_MUTEXED_CALL(OCILib.nb_descp--)

        ret = OCIDescriptorFree(descp, type);
    }

    return OCI_SUCCESSFUL(ret);
}
コード例 #6
0
ファイル: memory.c プロジェクト: Wushaowei001/ocilib
boolean OCI_HandleFree
(
    dvoid    *hndlp,
    CONST ub4 type
)
{
    sword ret = OCI_SUCCESS;

    if (hndlp)
    {
        OCI_MUTEXED_CALL(OCILib.nb_hndlp--)

        ret = OCIHandleFree(hndlp, type);
    }

    return OCI_SUCCESSFUL(ret);
}
コード例 #7
0
ファイル: mutex.c プロジェクト: 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;
}
コード例 #8
0
ファイル: memory.c プロジェクト: Wushaowei001/ocilib
boolean OCI_DescriptorArrayFree
(
    dvoid   **descp,
    CONST ub4 type,
    ub4       nb_elem
)
{
    sword ret = OCI_SUCCESS;

    if (descp)
    {

    #if OCI_VERSION_COMPILE >= OCI_11_1

        if (OCILib.version_runtime >= OCI_11_1)
        {
            ret = OCIArrayDescriptorFree(descp, type);

        }
        else

    #endif

        {
            ub4 i;

            for (i = 0; (i < nb_elem) && (OCI_SUCCESS == ret); i++)
            {
                ret = OCIDescriptorFree(descp[i], type);
            }
        }

        OCI_MUTEXED_CALL(OCILib.nb_descp -= nb_elem)
    }

    return OCI_SUCCESSFUL(ret);
}
コード例 #9
0
ファイル: memory.c プロジェクト: Wushaowei001/ocilib
boolean OCI_DescriptorArrayAlloc
(
    CONST dvoid *parenth,
    dvoid      **descpp,
    CONST ub4    type,
    ub4          nb_elem
)
{
    sword ret = OCI_SUCCESS;

#if OCI_VERSION_COMPILE >= OCI_11_1

    if (OCILib.version_runtime >= OCI_11_1)
    {
        ret = OCIArrayDescriptorAlloc(parenth, descpp, type, nb_elem, 0, NULL);

    }
    else

#endif

    {
        ub4 i;

        for (i = 0; (i < nb_elem) && (OCI_SUCCESS == ret); i++)
        {
            ret = OCIDescriptorAlloc(parenth, &descpp[i], type, 0, NULL);
        }
    }

    if (OCI_SUCCESSFUL(ret))
    {
        OCI_MUTEXED_CALL(OCILib.nb_descp += nb_elem)
    }

    return OCI_SUCCESSFUL(ret);
}
コード例 #10
0
ファイル: define.c プロジェクト: ashumeow/ocilib
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)
                    )
                }
            }
        }
    }
コード例 #11
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)
    }