⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 object.c

📁 oci的源码,可以在任何平台上编译,相当方便实用
💻 C
📖 第 1 页 / 共 4 页
字号:
    {
        const mtext *fmt = OCI_GetDefaultFormatNumeric(obj->con);
        ub4 fmt_size     = (ub4) mtslen(fmt);
        dtext *data      = (dtext *) OCI_ObjectGetString(obj, attr);

        res = OCI_NumberGetFromStr(obj->con, value, size, flag, data,
                                   (int) dtslen(data),  fmt, fmt_size);
    }

    OCI_RESULT(res);

    return FALSE;
}

/* ************************************************************************ *
 *                            PUBLIC FUNCTIONS
 * ************************************************************************ */

/* ------------------------------------------------------------------------ *
 * OCI_ObjectCreate
 * ------------------------------------------------------------------------ */

OCI_Object * OCI_API OCI_ObjectCreate(OCI_Connection *con, OCI_TypeInfo *typinf)
{
    OCI_Object *obj = NULL;

    OCI_CHECK_INITIALIZED(NULL);

    OCI_CHECK_PTR(OCI_IPC_CONNECTION, con, NULL);
    OCI_CHECK_PTR(OCI_IPC_TYPE_INFO, typinf, NULL);

    obj = OCI_ObjectInit(con, &obj, NULL, typinf, NULL, -1, TRUE);

    OCI_RESULT(obj != NULL);

    return obj;
}

/* ------------------------------------------------------------------------ *
 * OCI_ObjectFree
 * ------------------------------------------------------------------------ */

boolean OCI_API OCI_ObjectFree(OCI_Object *obj)
{
    OCI_CHECK_PTR(OCI_IPC_OBJECT, obj, FALSE);

    OCI_CHECK_OBJECT_FETCHED(obj, FALSE);

    /* if the object has sub-objects that have been fetched, we need to free
       these objects */

     OCI_ObjectReset(obj);

    if (obj->objs != NULL)
    {
        OCI_FREE(obj->objs);
    }

    if (obj->hstate == OCI_OBJECT_ALLOCATED)
    {
        OCI_OCIObjectFree(OCILib.env, obj->con->err,  obj->handle,
                          OCI_OBJECTFREE_NONULL);
    }

    OCI_FREE(obj->buf);
    OCI_FREE(obj);

    OCI_RESULT(TRUE);

    return TRUE;
}

/* ------------------------------------------------------------------------ *
 * OCI_ObjectAssign
 * ------------------------------------------------------------------------ */

boolean OCI_API OCI_ObjectAssign(OCI_Object *obj, OCI_Object *obj_src)
{
    boolean res = TRUE;

    OCI_CHECK_PTR(OCI_IPC_OBJECT, obj,     FALSE);
    OCI_CHECK_PTR(OCI_IPC_OBJECT, obj_src, FALSE);

    OCI_CHECK_COMPAT(obj->con, obj->typinf == obj_src->typinf, FALSE);

    OCI_CALL2
    (
        res, obj->con,

        OCIObjectCopy(OCILib.env, obj->con->err, obj->con->cxt,
                      obj_src->handle, (obj_src->tab_ind + obj_src->idx_ind),
                      obj->handle, (obj->tab_ind + obj->idx_ind),
                      obj->typinf->tdo, OCI_DURATION_SESSION, OCI_DEFAULT)
    )

    if (res == TRUE)
    {
        obj->typinf = obj_src->typinf;

        OCI_ObjectReset(obj);
    }


    OCI_RESULT(res);

    return res;
}

/* ------------------------------------------------------------------------ *
 * OCI_ObjectGetInt
 * ------------------------------------------------------------------------ */

short OCI_API OCI_ObjectGetShort(OCI_Object *obj, const mtext *attr)
{
    short value = 0;

    OCI_ObjectGetNumber(obj, attr, &value, sizeof(value), OCI_NUM_SHORT);

    return value;
}

/* ------------------------------------------------------------------------ *
 * OCI_ObjectGetUnsignedInt
 * ------------------------------------------------------------------------ */

unsigned short OCI_API OCI_ObjectGetUnsignedShort(OCI_Object *obj,
                                                  const mtext *attr)
{
    unsigned short value = 0;

    OCI_ObjectGetNumber(obj, attr, &value, sizeof(value), OCI_NUM_USHORT);

    return value;
}

/* ------------------------------------------------------------------------ *
 * OCI_ObjectGetInt
 * ------------------------------------------------------------------------ */

int OCI_API OCI_ObjectGetInt(OCI_Object *obj, const mtext *attr)
{
    int value = 0;

    OCI_ObjectGetNumber(obj, attr, &value, sizeof(value), OCI_NUM_INT);

    return value;
}

/* ------------------------------------------------------------------------ *
 * OCI_ObjectGetUnsignedInt
 * ------------------------------------------------------------------------ */

unsigned int OCI_API OCI_ObjectGetUnsignedInt(OCI_Object *obj, const mtext *attr)
{
    unsigned int value = 0;

    OCI_ObjectGetNumber(obj, attr, &value, sizeof(value), OCI_NUM_UINT);

    return value;
}

/* ------------------------------------------------------------------------ *
 * OCI_ObjectGetBigInt
 * ------------------------------------------------------------------------ */

big_int OCI_API OCI_ObjectGetBigInt(OCI_Object *obj, const mtext *attr)
{
    big_int value = 0;

    OCI_ObjectGetNumber(obj, attr, &value, sizeof(value), OCI_NUM_BIGINT);

    return value;
}

/* ------------------------------------------------------------------------ *
 * OCI_ObjectGetUnsignedBigInt
 * ------------------------------------------------------------------------ */

big_uint OCI_API OCI_ObjectGetUnsignedBigInt(OCI_Object *obj, const mtext *attr)
{
    big_uint value = 0;

    OCI_ObjectGetNumber(obj, attr, &value, sizeof(value), OCI_NUM_BIGUINT);

    return value;
}

/* ------------------------------------------------------------------------ *
 * OCI_ObjectGetDouble
 * ------------------------------------------------------------------------ */

double OCI_API OCI_ObjectGetDouble(OCI_Object *obj, const mtext *attr)
{
    double value = 0.0;

    OCI_ObjectGetNumber(obj, attr, &value, sizeof(value), OCI_NUM_DOUBLE);

    return value;
}

/* ------------------------------------------------------------------------ *
 * OCI_ObjectGetString
 * ------------------------------------------------------------------------ */

const dtext * OCI_API OCI_ObjectGetString(OCI_Object *obj, const mtext *attr)
{
    const dtext *str  = NULL;
    boolean res       = FALSE;
    int index         = OCI_ObjectGetIndex(obj, attr, OCI_CDT_TEXT);

    if (index >= 0)
    {
        OCIInd ind        = 0;
        OCIType *tdo      = NULL;
        OCIString **value = NULL;

        res = OCI_ObjectGetAttr(obj, attr, (dvoid **) (dvoid *) &value, &ind, &tdo);

        if ((res == TRUE) && (value != NULL) && (ind == OCI_IND_NOTNULL))
        {
            str = (dtext *) OCI_StringFromStringPtr(*value, &obj->buf, &obj->buflen);
        }
    }

    OCI_RESULT(res);

    return str;
}

/* ------------------------------------------------------------------------ *
 * OCI_ObjectGetRaw
 * ------------------------------------------------------------------------ */

int OCI_API OCI_ObjectGetRaw(OCI_Object *obj, const mtext *attr, void *buffer,
                             unsigned int len)
{
    boolean res = FALSE;
    int index   = OCI_ObjectGetIndex(obj, attr, OCI_CDT_RAW);
    ub4 raw_len = 0;

    if (index >= 0)
    {
        OCIInd ind     = 0;
        OCIType *tdo   = NULL;
        OCIRaw **value = NULL;

        res = OCI_ObjectGetAttr(obj, attr, (dvoid **) (dvoid *) &value, &ind, &tdo);

        if ((res == TRUE) && (value != NULL) && (ind == OCI_IND_NOTNULL))
        {
            OCI_CALL2
            (
                res, obj->con,

                OCIRawAllocSize(OCILib.env, obj->con->err, *value, (ub4*) &raw_len)
            )

            if (res == TRUE)
            {
                if (len > raw_len)
                    len = raw_len;

                memcpy(buffer, OCIRawPtr(OCILib.env, *value), len);
            }
        }
    }

    OCI_RESULT(res);

    return len;
}

/* ------------------------------------------------------------------------ *
 * OCI_ObjectGetDate
 * ------------------------------------------------------------------------ */

OCI_Date * OCI_API OCI_ObjectGetDate(OCI_Object *obj, const mtext *attr)
{
    OCI_Date * date = NULL;
    boolean res     = FALSE;
    int index       = OCI_ObjectGetIndex(obj, attr, OCI_CDT_DATETIME);

    if (index >= 0)
    {
        OCIInd ind     = 0;
        OCIType *tdo   = NULL;
        OCIDate *value = NULL;

        res = OCI_ObjectGetAttr(obj, attr, (dvoid **) (dvoid *) &value, &ind, &tdo);

        if ((res == TRUE) && (value != NULL) && (ind == OCI_IND_NOTNULL))
        {
            date = OCI_DateInit(obj->con, (OCI_Date **) &obj->objs[index],
                                NULL, FALSE, FALSE);

            if (date != NULL)
            {
                date->handle = value;

                res = TRUE;
            }
            else
                res = FALSE;
        }
    }

    OCI_RESULT(res);

    return date;
}

/* ------------------------------------------------------------------------ *
 * OCI_ObjectGetTimeStamp
 * ------------------------------------------------------------------------ */

OCI_Timestamp * OCI_API OCI_ObjectGetTimeStamp(OCI_Object *obj,
                                               const mtext *attr)
{
    OCI_Timestamp *tmsp = NULL;
    boolean res         = FALSE;

    int index           = OCI_ObjectGetIndex(obj, attr, OCI_CDT_TIMESTAMP);
    if (index >= 0)
    {
        OCIInd ind          = 0;
        OCIType *tdo        = NULL;
        OCIDateTime **value = NULL;

        res = OCI_ObjectGetAttr(obj, attr, (dvoid **) (dvoid *) &value, &ind, &tdo);

        if ((res == TRUE) && (value != NULL) && (ind == OCI_IND_NOTNULL))
        {
           tmsp = OCI_TimestampInit(obj->con,
                                    (OCI_Timestamp **) &obj->objs[index],
                                    (OCIDateTime *) *value,
                                    obj->typinf->cols[index].subtype);

           res = (tmsp != NULL);
        }
    }

    OCI_RESULT(res);

    return tmsp;
}

/* ------------------------------------------------------------------------ *
 * OCI_ObjectGetInterval
 * ------------------------------------------------------------------------ */

OCI_Interval * OCI_API OCI_ObjectGetInterval(OCI_Object *obj, const mtext *attr)
{
    OCI_Interval *itv = NULL;
    boolean res       = FALSE;
    int index         = OCI_ObjectGetIndex(obj, attr, OCI_CDT_INTERVAL);

    if (index >= 0)
    {
        OCIInd ind          = 0;
        OCIType *tdo        = NULL;
        OCIInterval **value = NULL;

        res = OCI_ObjectGetAttr(obj, attr, (dvoid **) (dvoid *) &value, &ind, &tdo);

        if ((res == TRUE) && (value != NULL) && (ind == OCI_IND_NOTNULL))
        {
            itv = OCI_IntervalInit(obj->con,
                                   (OCI_Interval **) &obj->objs[index],
                                   (OCIInterval *) *value,
                                   obj->typinf->cols[index].subtype);

            res = (itv != NULL);
        }
    }

    OCI_RESULT(res);

    return itv;
}

/* ------------------------------------------------------------------------ *
 * OCI_ObjectGetColl
 * ------------------------------------------------------------------------ */

OCI_Coll * OCI_API OCI_ObjectGetColl(OCI_Object *obj, const mtext *attr)
{
    OCI_Coll *coll = NULL;
    boolean res    = FALSE;
    int index      = OCI_ObjectGetIndex(obj, attr, OCI_CDT_COLLECTION);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -