• 读写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);
    }

  • 相关阅读:
    和为S的两个数字
    数字在排序数组中出现的次数
    连续子数组的最大和
    包含min函数的栈
    二进制中1的个数
    变态跳台阶
    android里R.layout.的问题
    eclipse里面设置JVM参数的问题
    perl小记
    机器寻径引导算法(最短路径表)__深搜、栈
  • 原文地址:https://www.cnblogs.com/shenchao/p/3270515.html
Copyright © 2020-2023  润新知