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

📄 resultset.c

📁 oci的源码,可以在任何平台上编译,相当方便实用
💻 C
📖 第 1 页 / 共 5 页
字号:

/* ------------------------------------------------------------------------ *
 * OCI_GetUnsignedInt
 * ------------------------------------------------------------------------ */

unsigned int OCI_API OCI_GetUnsignedInt(OCI_Resultset *rs, unsigned int index)
{
    unsigned int value = 0;

    OCI_DefineGetNumber(rs, index, &value, OCI_NUM_UINT, sizeof(value));

    return value;
}

/* ------------------------------------------------------------------------ *
 * OCI_GetUnsignedInt2
 * ------------------------------------------------------------------------ */

unsigned int OCI_API OCI_GetUnsignedInt2(OCI_Resultset *rs, const mtext *name)
{
    return OCI_GetUnsignedInt(rs, OCI_GetDefineIndex(rs, name));
}

/* ------------------------------------------------------------------------ *
 * OCI_GetBigInt
 * ------------------------------------------------------------------------ */

big_int OCI_API OCI_GetBigInt(OCI_Resultset *rs, unsigned int index)
{
    big_int value = 0;

    OCI_DefineGetNumber(rs, index, &value, OCI_NUM_BIGINT, sizeof(value));

    return value;
}

/* ------------------------------------------------------------------------ *
 * OCI_GetBigInt2
 * ------------------------------------------------------------------------ */

big_int OCI_API OCI_GetBigInt2(OCI_Resultset *rs, const mtext *name)
{
    return OCI_GetBigInt(rs, OCI_GetDefineIndex(rs, name));
}

/* ------------------------------------------------------------------------ *
 * OCI_GetUnsignedBigInt
 * ------------------------------------------------------------------------ */

big_uint OCI_API OCI_GetUnsignedBigInt(OCI_Resultset *rs, unsigned int index)
{
    big_uint value = 0;

    OCI_DefineGetNumber(rs, index, &value, OCI_NUM_BIGUINT, sizeof(value));

    return value;
}

/* ------------------------------------------------------------------------ *
 * OCI_GetUnsignedInt2
 * ------------------------------------------------------------------------ */

big_uint OCI_API OCI_GetUnsignedBigInt2(OCI_Resultset *rs, const mtext *name)
{
    return OCI_GetUnsignedBigInt(rs, OCI_GetDefineIndex(rs, name));
}

/* ------------------------------------------------------------------------ *
 * OCI_GetString
 * ------------------------------------------------------------------------ */

const dtext * OCI_API OCI_GetString(OCI_Resultset *rs, unsigned int index)
{
    OCI_Define *def  = OCI_GetDefine(rs, index);
    dtext *str       = NULL;
    boolean res      = TRUE;

    res = (def != NULL);

    if ((res == TRUE) && (OCI_NOT_NULL(def) == TRUE))
    {
        void *data   = OCI_DefineGetData(def);

        if (def->col.type == OCI_CDT_TEXT)
        {
            str = (dtext *) data;

            /* for long mapped to string, the zero terminal character is not
               always added by Oracle ? or OCILIB issue ? Anyway we check the
               length returned by Oracle and set it properly */

            if (def->col.subtype == OCI_CLONG)
            {
                ub2* lens = (ub2 *) def->buf.lens;

                str[lens[rs->row_cur-1]] = 0;
            }
        }
        else
        {
            /* tries an implicit conversion if possible */

            if (def->buf.temp == NULL)
            {
                def->buf.temp = (dtext *) OCI_MemAlloc(OCI_IPC_STRING,
                                                       sizeof(dtext),
                                                       (OCI_SIZE_BUFFER+1),
                                                       FALSE);

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

            if (res == TRUE)
            {
                def->buf.temp[0] = 0;

                switch (def->col.type)
                {
                    case OCI_CDT_NUMERIC:
                    {
                        void *ostr1 = NULL;
                        void *ostr2 = NULL;
                        int  osize1 = OCI_SIZE_FORMAT_NUML * sizeof(mtext);
                        int  osize2 = OCI_SIZE_BUFFER      * sizeof(dtext);
                        const mtext *fmt;
                        int pos;

#ifdef OCI_CHARSET_MIXED

                        mtext temp[OCI_SIZE_BUFFER+1];

                        temp[0] = 0;

#else
                        def->buf.temp[0] = 0;
#endif

                        /* init output buffer in case of OCI failure */

                        fmt   = OCI_GetDefaultFormatNumeric(rs->stmt->con);
                        ostr1 = OCI_GetInputMetaString(fmt, &osize1);

#ifdef OCI_CHARSET_MIXED

                        ostr2 = OCI_GetInputDataString(temp, &osize2);

#else
 
                        ostr2 = OCI_GetInputDataString(def->buf.temp, &osize2);

#endif
                        /* check for decimal character */

                        OCI_CALL1
                        (
                            res, rs->stmt->con, rs->stmt,

                                OCINumberToText(rs->stmt->con->err,
                                                (OCINumber *) data,
                                                (oratext *) ostr1,
                                                (ub4) osize1,
                                                (oratext *) NULL,
                                                (ub4) 0,
                                                (ub4 *) &osize2,
                                                (oratext *) ostr2)
                        )



#ifdef OCI_CHARSET_MIXED

                        OCI_GetOutputDataString(ostr2, temp, &osize2);

                        mbstowcs(def->buf.temp, temp, strlen(temp) + OCI_CVT_CHAR);

                        osize2 = osize2 * sizeof(dtext);
#else

                        OCI_GetOutputDataString(ostr2, def->buf.temp, &osize2);

#endif

                        /* do we need to suppress last '.' or ',' from integers */

                        pos = (osize2 / sizeof(dtext)) -1;

                        if (pos >= 0)
                        {
                            if ((def->buf.temp[pos] == DT('.')) ||
                                (def->buf.temp[pos] == DT(',')))
                            {
                                def->buf.temp[pos] = 0;
                            }
                        }

                        OCI_ReleaseMetaString(ostr1);
                        OCI_ReleaseDataString(ostr2);

                        if (res == TRUE)
                            str = def->buf.temp;

                        break;
                    }
                    case OCI_CDT_DATETIME:
                    {
                        OCI_Date *date   = OCI_GetDate(rs, index);
                        const mtext *fmt = OCI_GetDefaultFormatDate(rs->stmt->con);

                        if (date != NULL)
                        {
#ifndef OCI_CHARSET_MIXED
                             res = OCI_DateToText(date, fmt, OCI_SIZE_BUFFER,
                                                  (mtext *) def->buf.temp);
#else

                            /* mixed mode... conversion needed ! */

                            mtext temp[OCI_SIZE_BUFFER+1];

                            temp[0] = 0;

                            res = OCI_DateToText(date, fmt, OCI_SIZE_BUFFER, temp);

                            mbstowcs(def->buf.temp, temp, strlen(temp) + OCI_CVT_CHAR);
 #endif

                            str = def->buf.temp;
                        }

                        break;
                    }
                    case OCI_CDT_TIMESTAMP:
                    {
                        OCI_Timestamp *tmsp = OCI_GetTimestamp(rs, index);
                        const mtext *fmt    = OCI_GetDefaultFormatDate(rs->stmt->con);

                        if (tmsp != NULL)
                        {
#ifndef OCI_CHARSET_MIXED

                            OCI_TimestampToText(tmsp, fmt, OCI_SIZE_BUFFER,
                                                (mtext *) def->buf.temp,  0);
#else

                            /* mixed mode... conversion needed ! */

                            mtext temp[OCI_SIZE_BUFFER+1];

                            temp[0] = 0;

                            OCI_TimestampToText(tmsp, fmt, OCI_SIZE_BUFFER,
                                                (mtext *) temp, 0);

                            mbstowcs(def->buf.temp, temp, strlen(temp) + OCI_CVT_CHAR);
         #endif
                            str = def->buf.temp;
                        }

                        break;
                    }
                    case OCI_CDT_INTERVAL:
                    {
                         OCI_Interval *itv = OCI_GetInterval(rs, index);

                         if (itv != NULL)
                         {
#ifndef OCI_CHARSET_MIXED
                             OCI_IntervalToText(OCI_GetInterval(rs, index),
                                                OCI_STRING_DEFAULT_PREC,
                                                OCI_STRING_DEFAULT_PREC,
                                                OCI_SIZE_BUFFER,
                                                (mtext *) def->buf.temp);
#else

                            /* mixed mode... conversion needed ! */

                            mtext temp[OCI_SIZE_BUFFER+1];

                            temp[0] = 0;

                            OCI_IntervalToText(OCI_GetInterval(rs, index),
                                               OCI_STRING_DEFAULT_PREC,
                                               OCI_STRING_DEFAULT_PREC,
                                               OCI_SIZE_BUFFER, (mtext *) temp);

                            mbstowcs(def->buf.temp, temp, strlen(temp) + OCI_CVT_CHAR);
 #endif
                           str = def->buf.temp;
                        }

                        break;
                    }
                    case OCI_CDT_LONG:
                    {
                        OCI_Long *lg = OCI_GetLong(rs, index);

                        if (lg != NULL)
                            str = OCI_LongGetBuffer(lg);

                        break;

                    }
                    case OCI_CDT_RAW:
                    {
                        str = (dtext *) data;

                        break;

                    }
                    case OCI_CDT_LOB:
                    {
                        OCI_Lob *lob = OCI_GetLob(rs, index);
                        unsigned int len = 0;

                        len = OCI_LobRead(lob, def->buf.temp, OCI_SIZE_BUFFER);

                        def->buf.temp[len] = 0;

                        OCI_LobSeek(lob, 0, OCI_SEEK_SET);

                        str = def->buf.temp;

                        break;

                    }
                    case OCI_CDT_FILE:
                    {
                        OCI_File *file = OCI_GetFile(rs, index);
                        unsigned int len = 0;

                        len = OCI_FileRead(file, def->buf.temp, OCI_SIZE_BUFFER);

                        def->buf.temp[len] = 0;

                        OCI_FileSeek(file, 0, OCI_SEEK_SET);

                        str = def->buf.temp;

                        break;

                    }
                    case OCI_CDT_REF:
                    {
                        OCI_Ref *ref = OCI_GetRef(rs, index);

                        if (ref != NULL)
                        {

#ifndef OCI_CHARSET_MIXED

                        OCI_RefToText(ref, OCI_SIZE_BUFFER, (mtext *) def->buf.temp);

#else
                            /* mixed mode... conversion needed ! */

                            mtext temp[OCI_SIZE_BUFFER+1];

                            temp[0] = 0;

                            OCI_RefToText(ref, OCI_SIZE_BUFFER, (mtext *) temp);

                            mbstowcs(def->buf.temp, temp, strlen(temp) + OCI_CVT_CHAR);
 #endif

                           str = def->buf.temp;
                        }

                        break;
                    }
                    default:
                    {
                        res = FALSE;
                    }
                }
            }
        }
    }

    OCI_RESULT(res);

    return str;
}

/* ------------------------------------------------------------------------ *
 * OCI_GetString2
 * ------------------------------------------------------------------------ */

const dtext * OCI_API OCI_GetString2(OCI_Resultset *rs, const mtext *name)
{
    return OCI_GetString(rs, OCI_GetDefineIndex(rs, name));
}

/* ------------------------------------------------------------------------ *
 * OCI_GetRaw
 * ------------------------------------------------------------------------ */

unsigned int OCI_API OCI_GetRaw(OCI_Resultset *rs, unsigned int index,
                                void *buffer, unsigned int len)
{
    OCI_Define *def = OCI_GetDefine(rs, index);
    boolean res     = TRUE;
    ub2 count       = (ub2) len;

    OCI_CHECK_PTR(OCI_IPC_VOID, buffer, 0);

    res = (def != NULL);

    if ((OCI_NOT_NULL(def) == TRUE) && (def->col.type == OCI_CDT_RAW))
    {
        ub2 size = ((ub2*)def->buf.lens)[def->rs->row_cur-1];

        if (count > size)
            count = size;

        /* for RAWs, we copy the data in the destination buffer instead of

⌨️ 快捷键说明

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