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

📄 object.c

📁 ORACLE编程的好东西,纯C写的OCI封装.很好用,支持数据池.
💻 C
📖 第 1 页 / 共 2 页
字号:
        }
    }

    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, (void **) &value, &ind, &tdo);

        if ((res == TRUE) && (value != NULL))
        {     
            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;

        date = OCI_DateInit(obj->con, (OCI_Date **) &obj->objs[index], 
                            NULL, FALSE, FALSE);

        res = (date != NULL);

        if (res == TRUE)
            res = OCI_ObjectGetAttr(obj, attr, (void **) &date->handle, &ind, &tdo);
    }

    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, (void **) &value, &ind, &tdo);

        if ((res == TRUE) && (value != NULL))
        {
           tmsp = OCI_TimestampInit(obj->con, 
                                    (OCI_Timestamp **) &obj->objs[index], 
                                    (OCIDateTime *) *value, 
                                    obj->nty->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, (void **) &value, &ind, &tdo);

        if ((res == TRUE) && (value != NULL))
        {
            itv = OCI_IntervalInit(obj->con, 
                                   (OCI_Interval **) &obj->objs[index], 
                                   (OCIInterval *) *value, 
                                   obj->nty->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);

    if (index >= 0)
    {
        OCIInd ind      = 0;
        OCIType *tdo    = NULL;
        OCIColl **value = NULL;
        
        res = OCI_ObjectGetAttr(obj, attr, (void **) &value, &ind, &tdo);

        if ((res == TRUE) && (value != NULL))
        {
            coll = OCI_CollInit(obj->con, 
                                (OCI_Coll **) &obj->objs[index], 
                                (OCIColl *) value, 
                                obj->nty->cols[index].nty);

            res = (coll != NULL);
        }
    }

    OCI_RESULT(res);

    return coll;
}

/* ------------------------------------------------------------------------ *
 * OCI_ObjectGetObject
 * ------------------------------------------------------------------------ */

OCI_Object * OCI_API OCI_ObjectGetObject(OCI_Object *obj, const mtext *attr)
{
    OCI_Object *obj2 = NULL;
    boolean res      = FALSE;
    int index        = OCI_ObjectGetIndex(obj, attr, OCI_CDT_OBJECT);

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

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

        if ((res == TRUE) && (value != NULL))
        {
            obj2 = OCI_ObjectInit(obj->con, (OCI_Object **) &obj->objs[index], 
                                  value, obj->nty->cols[index].nty);
            
            res = (obj2 != NULL);
       }
    }

    OCI_RESULT(res);

    return obj2;
}

/* ------------------------------------------------------------------------ *
 * OCI_ObjectGetLob
 * ------------------------------------------------------------------------ */

OCI_Lob * OCI_API OCI_ObjectGetLob(OCI_Object *obj, const mtext *attr)
{
    OCI_Lob *lob = NULL;
    boolean res  = FALSE;
    int index    = OCI_ObjectGetIndex(obj, attr, OCI_CDT_LOB);

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

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

        if ((res == TRUE) && (value != NULL))
        {
            lob = OCI_LobInit(obj->con, (OCI_Lob **) &obj->objs[index], 
                              *value, obj->nty->cols[index].subtype);
            
            res = (lob != NULL);
        }
    }

    OCI_RESULT(res);

    return lob;
}

/* ------------------------------------------------------------------------ *
 * OCI_ObjectGetFile
 * ------------------------------------------------------------------------ */

OCI_File * OCI_API OCI_ObjectGetFile(OCI_Object *obj, const mtext *attr)
{
    OCI_File *file = NULL;
    boolean res    = FALSE;
    int index      = OCI_ObjectGetIndex(obj, attr, OCI_CDT_FILE);

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

        res = OCI_ObjectGetAttr(obj, attr, (void **) &value, &ind, &tdo);
        
        if ((res == TRUE) && (value != NULL))
        {
            file = OCI_FileInit(obj->con, (OCI_File **) &obj->objs[index], 
                                *value, obj->nty->cols[index].subtype);

            res = (file != NULL);
        }
    }

    OCI_RESULT(res);

    return file;
}

/* ------------------------------------------------------------------------ *
 * OCI_ObjectSetShort
 * ------------------------------------------------------------------------ */

boolean OCI_API OCI_ObjectSetShort(OCI_Object *obj, const mtext *attr, short value)
{
    return OCI_ObjectSetNumber(obj, attr, &value, sizeof(value), 
                               (uword) OCI_NUM_SHORT);
}

/* ------------------------------------------------------------------------ *
 * OCI_ObjectSetUnsignedShort
 * ------------------------------------------------------------------------ */

boolean OCI_API OCI_ObjectSetUnsignedShort(OCI_Object *obj, const mtext *attr, 
                                           unsigned short value)
{
    return OCI_ObjectSetNumber(obj, attr, &value, sizeof(value), 
                               (uword) OCI_NUM_USHORT);
}

/* ------------------------------------------------------------------------ *
 * OCI_ObjectSetInt
 * ------------------------------------------------------------------------ */

boolean OCI_API OCI_ObjectSetInt(OCI_Object *obj, const mtext *attr, int value)
{
    return OCI_ObjectSetNumber(obj, attr, &value, sizeof(value), 
                               (uword) OCI_NUM_INT);
}

/* ------------------------------------------------------------------------ *
 * OCI_ObjectSetUnsignedInt
 * ------------------------------------------------------------------------ */

boolean OCI_API OCI_ObjectSetUnsignedInt(OCI_Object *obj, const mtext *attr, 
                                        unsigned int value)
{
    return OCI_ObjectSetNumber(obj, attr, &value, sizeof(value), 
                               (uword) OCI_NUM_UINT);
}

/* ------------------------------------------------------------------------ *
 * OCI_ObjectSetBigInt
 * ------------------------------------------------------------------------ */

boolean OCI_API OCI_ObjectSetBigInt(OCI_Object *obj, const mtext *attr,
                                    big_int value)
{
    return OCI_ObjectSetNumber(obj, attr, &value, sizeof(value), 
                               (uword) OCI_NUM_BIGINT);
}


/* ------------------------------------------------------------------------ *
 * OCI_ObjectSetUnsignedBigInt
 * ------------------------------------------------------------------------ */

boolean OCI_API OCI_ObjectSetUnsignedBigInt(OCI_Object *obj, const mtext *attr,
                                            big_uint value)
{
    return OCI_ObjectSetNumber(obj, attr, &value, sizeof(value), 
                               (uword) OCI_NUM_BIGUINT);
}

/* ------------------------------------------------------------------------ *
 * OCI_ObjectSetDouble
 * ------------------------------------------------------------------------ */

boolean OCI_API OCI_ObjectSetDouble(OCI_Object *obj, const mtext *attr, 
                                    double value)
{    
    return OCI_ObjectSetNumber(obj, attr, &value, sizeof(value), 
                               (uword) OCI_NUM_DOUBLE);
}

/* ------------------------------------------------------------------------ *
 * OCI_ObjectSetString
 * ------------------------------------------------------------------------ */

boolean OCI_API OCI_ObjectSetString(OCI_Object *obj, const mtext *attr,
                                    const dtext *value)
{
    boolean res = TRUE;

    if (value == NULL)
    {
        res = OCI_ObjectSetNull(obj, attr);
    }
    else
    {
        if (OCI_ObjectGetIndex(obj, attr, OCI_CDT_TEXT) >= 0)
        {
            OCIString *str = NULL;

            res = OCI_StringToStringPtr(&str, obj->con->err, (void *) value, 
                                        &obj->buf, &obj->buflen);

            if (res == TRUE)
                res = OCI_ObjectSetAttr(obj, attr, (void *) str, 0);
        }
        else
            res = FALSE;
    }

    OCI_RESULT(res);
    
    return res;
}

/* ------------------------------------------------------------------------ *
 * OCI_ObjectSetRaw
 * ------------------------------------------------------------------------ */

boolean OCI_API OCI_ObjectSetRaw(OCI_Object *obj, const mtext *attr, 
                                 void* value, unsigned int len)
{
    boolean res = TRUE;
  
    if (value == NULL)
    {
        res = OCI_ObjectSetNull(obj, attr);
    }
    else
    {     
        OCI_CHECK_MIN(obj->con, NULL, len, 1, FALSE);       

        if (OCI_ObjectGetIndex(obj, attr, OCI_CDT_RAW) >= 0)
        {
            OCIRaw *raw = NULL;
         
            OCI_CALL2
            (
                res, obj->con, 
     
                OCIRawAssignBytes(OCILib.env, obj->con->err, (ub1*) value, len,
                                  &raw)
            )

            if (res == TRUE)
                res = OCI_ObjectSetAttr(obj, attr, (void *) raw, 0);
        }
        else
            res = FALSE;
    }

    OCI_RESULT(res);
    
    return res;
}

/* ------------------------------------------------------------------------ *
 * OCI_ObjectSetNull
 * ------------------------------------------------------------------------ */

boolean OCI_API OCI_ObjectSetNull(OCI_Object *obj, const mtext *attr)
{
    boolean res = TRUE;
    void *ostr  = NULL;
    int osize   = -1;

    OCI_CHECK_PTR(OCI_IPC_OBJECT, obj, FALSE);
    OCI_CHECK_PTR(OCI_IPC_STRING, attr, FALSE);

    ostr = OCI_GetInputMetaString(attr, &osize);
    
    OCI_CALL2
    (
        res, obj->con, 
        
        OCIObjectSetAttr(OCILib.env, obj->con->err, obj->handle, NULL, 
                         obj->nty->tdo, (CONST text**) &ostr, (ub4 *) &osize,
                         (ub4) 1, (ub4 *) NULL, (ub4) 0,  OCI_IND_NULL,
                         (void *)  NULL, (void *) NULL)
    )

    OCI_ReleaseMetaString(ostr);

    OCI_RESULT(res);
    
    return res;
}

⌨️ 快捷键说明

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