zoukankan      html  css  js  c++  java
  • 读写SQLServer数据库中的image类型数据(简单)

    1、将double类型的数据存储于image类型的变量中:

    (1)、   
    char *CManualForecastResultBll::DoubleArray2Binary(std::vector<double> &doubleArray)
    {
        int len = doubleArray.size();
        char *bin = new char[len * sizeof(double)];
        unsigned __int64 *p = (unsigned __int64*)bin;
        for (int i = 0; i < len; i++)
        {
            *p = DOUBLE2UINT64(doubleArray.at(i));
            p++;
        }
        return bin;
    }

    unsigned __int64 CManualForecastResultBll::DOUBLE2UINT64(double v)
    {
        unsigned __int64 *pu64n = NULL;
        pu64n = reinterpret_cast<unsigned __int64*>(&v);
        return *pu64n;
    }

            (2)、

             VARIANT            varBLOB;
                            SAFEARRAY        *psa;
                            SAFEARRAYBOUND    rgsabound[1];

                            rgsabound[0].lLbound = 0;
                            rgsabound[0].cElements = (ULONG)(pData->qLen);
                            psa = SafeArrayCreate(VT_UI1, 1, rgsabound);
                            byte * pQt = pData->QTLINE;                                //自己的数据byte类型
                            for (long i = 0; i < pData->qLen; i++)
                                SafeArrayPutElement (psa, &i, pQt++);
                            varBLOB.vt = VT_ARRAY | VT_UI1;
                            varBLOB.parray = psa;
                            pRecordset->GetFields()->GetItem(SimulateResultDataFeilds[i])->AppendChunk(varBLOB);

    2、根据已知image类型中存储的数据类型(例如:double、float等)取数据:

    case VT_ARRAY | VT_UI1:

                 Binary2DoubleArray(vtFld);
                      break;

    //////////////////////////////////////////////////////////////////////////
    void DBRecordset::Binary2DoubleArray(_variant_t vtFld)
    {
        int len =  vtFld.parray->rgsabound->cElements / sizeof(double);
        double *pdata = new double[len];

        /*int len =  vtFld.parray->rgsabound->cElements / sizeof(float);
        float *pdata = new float[len];*/

        SafeArrayAccessData(vtFld.parray, (void**)&pdata);

        /*unsigned __int64 *pu64n = new unsigned __int64[len];
        SafeArrayAccessData(vtFld.parray, (void**)&pu64n);*/

        ofstream writetofile("image.txt");
        for (int i = 0; i < len; i++)
        {
            if (i % 30 == 0 && i != 0)
            {
                writetofile<<endl;
            }
            writetofile<<pdata[i]<<" ";
            //writetofile<<*(reinterpret_cast<double*>(&pu64n[i]))<<" ";
            writetofile.flush();
        }
        writetofile<<endl;
        writetofile.close();
        SafeArrayUnaccessData(vtFld.parray);
    }

  • 相关阅读:
    elementUI table中的button 操作
    数组
    数组,字符串,数字之间的相互转换
    Element upload
    Vue中涉及到的三目运算与v-if结合
    ElementUI的input用法
    javascript的正则表达式
    Vue表单+Vue全局指令 v-focus 的引用
    ztree 异步加载大数据(一)
    vue mixins 混入项目实例
  • 原文地址:https://www.cnblogs.com/shenchao/p/3270515.html
Copyright © 2011-2022 走看看