Aracılığıyla paylaş


IRow::Open ve ISequentialStream kullanarak blob veri getiriliyor

IRow::Open açılacak nesneleri yalnızca DBGUID_STREAM ve DBGUID_NULL türünü destekler.

Aşağıdaki işlev kullanır IRow::Open ve ISequentialStream büyük veri getirmek için.

void InitializeAndExecuteCommand()
{
    ULONG iidx;
    WCHAR* wCmdString=OLESTR("SELECT * FROM MyTable");
    // Do the initialization, create the session, and set command text.
    hr = pICommandText->Execute(NULL, IID_IRow, NULL, 
                         &cNumRows,(IUnknown **)&pIRow)))
    //Get 1 column at a time.
    for(ULONG i=1; i <= NoOfColumns; i++)
      GetSequentialColumn(pIRow, iidx);
    // Do the clean up.
}
HRESULT GetSequentialColumn(IRow* pUnkRow, ULONG iCol)
{
    HRESULT hr = NOERROR;
    ULONG cbRead = 0;
    ULONG cbTotal = 0;
    ULONG cColumns = 0;
    ULONG cReads = 0;
    ISequentialStream* pIStream = NULL;
    WCHAR* pBuffer[kMaxBuff]; //50 chars read by ISequentialStream::Read()
    DBCOLUMNINFO* prgInfo;
    OLECHAR* pColNames;
    IColumnsInfo* pIColumnsInfo;
    DBID columnid;
    DBCOLUMNACCESS column;

    hr = pUnkRow->QueryInterface(IID_IColumnsInfo, 
                            (void**) &pIColumnsInfo);
    hr = pIColumnsInfo->GetColumnInfo(&cColumns, &prgInfo, &pColNames);
    // Get Column ID.
    columnid = (prgInfo + (iCol - 1))->columnid;
    // Get sequential stream object by calling IRow::Open.
    hr = pUnkRow->Open(NULL, &columnid, DBGUID_STREAM, 0, 
                    IID_ISequentialStream,(LPUNKNOWN *)&pIStream);
    ZeroMemory(pBuffer, kMaxBuff * sizeof(WCHAR));
    // Read 50 chars at a time until no more data.
    do
    {
        hr = pIStream->Read(pBuffer, kMaxBuff, &cbRead);
        cbTotal = cbTotal + cbRead;
        // Process the data.
    } while(cbRead > 0);
// Do the clean up.
    return hr;
}

void InitializeAndExecuteCommand()
{
    ULONG iidx;
    WCHAR* wCmdString=OLESTR("SELECT * FROM MyTable");
    // Do the initialization, create the session, and set command text.
    hr = pICommandText->Execute(NULL, IID_IRow, NULL, 
                         &cNumRows,(IUnknown **)&pIRow)))
    //Get 1 column at a time.
    for(ULONG i=1; i <= NoOfColumns; i++)
      GetSequentialColumn(pIRow, iidx);
    // Do the clean up.
}
HRESULT GetSequentialColumn(IRow* pUnkRow, ULONG iCol)
{
    HRESULT hr = NOERROR;
    ULONG cbRead = 0;
    ULONG cbTotal = 0;
    ULONG cColumns = 0;
    ULONG cReads = 0;
    ISequentialStream* pIStream = NULL;
    WCHAR* pBuffer[kMaxBuff]; //50 chars read by ISequentialStream::Read()
    DBCOLUMNINFO* prgInfo;
    OLECHAR* pColNames;
    IColumnsInfo* pIColumnsInfo;
    DBID columnid;
    DBCOLUMNACCESS column;

    hr = pUnkRow->QueryInterface(IID_IColumnsInfo, 
                            (void**) &pIColumnsInfo);
    hr = pIColumnsInfo->GetColumnInfo(&cColumns, &prgInfo, &pColNames);
    // Get Column ID.
    columnid = (prgInfo + (iCol - 1))->columnid;
    // Get sequential stream object by calling IRow::Open.
    hr = pUnkRow->Open(NULL, &columnid, DBGUID_STREAM, 0, 
                    IID_ISequentialStream,(LPUNKNOWN *)&pIStream);
    ZeroMemory(pBuffer, kMaxBuff * sizeof(WCHAR));
    // Read 50 chars at a time until no more data.
    do
    {
        hr = pIStream->Read(pBuffer, kMaxBuff, &cbRead);
        cbTotal = cbTotal + cbRead;
        // Process the data.
    } while(cbRead > 0);
// Do the clean up.
    return hr;
}

Büyük veri bağlı ya da kullanarak alınan ISequentialStream arabirimi. Ilişkili sütunlar için veri dbstatus_s_truncated ayarlayarak kesilir durum bayrağı belirtir.

Ayrıca bkz.

Kavramlar

IRow kullanma blob veri getiriliyor