Pobieranie danych duże
Ogólnie rzecz biorąc, konsumentów należy oddzielać kod, który tworzy SQL Server Macierzysty obiekt magazynu dostawca klient OLE DB z innego kodu, który obsługuje dane, nie jest wywoływany przez ISequentialStream wskaźnika interfejs.
W tym temacie odnosi się do funkcji dostępnych za pomocą następujących funkcji:
IRowset:GetData
IRow::GetColumns
ICommand::wykonać
Jeśli właściwość DBPROP_ACCESSORDER (w wierszu zestaw właściwości grupy) jest zestaw do jednej z wartości DBPROPVAL_AO_SEQUENTIAL lub DBPROPVAL_AO_SEQUENTIALSTORAGEOBJECTS konsumenta należy pobierać tylko jeden wiersz danych w wywołaniu GetNextRows metoda uwagi BLOB danych nie jest buforowana.Jeśli ustawiono wartość DBPROP_ACCESSORDER DBPROPVAL_AO_RANDOM, konsument może pobrać wiele wierszy zawierających dane w GetNextRows.
The SQL Server Native klient OLE DB dostawca does not retrieve large data from SQL Server until requested to do so by the consumer. Konsument należy powiązać wszystkie dane krótkie w jeden metoda dostępu, a następnie użyj jednego lub kilku Akcesory tymczasowych do pobierania danych dużej wartości zgodnie z wymaganiami.
Przykład
W tym przykładzie pobiera dużą wartość z pojedynczej kolumna:
HRESULT GetUnboundData
(
IRowset* pIRowset,
HROW hRow,
ULONG nCol,
BYTE* pUnboundData
)
{
UINT cbRow = sizeof(IUnknown*) + sizeof(ULONG);
BYTE* pRow = new BYTE[cbRow];
DBOBJECT dbobject;
IAccessor* pIAccessor = NULL;
HACCESSOR haccessor;
DBBINDING dbbinding;
ULONG ulbindstatus;
ULONG dwStatus;
ISequentialStream* pISequentialStream;
ULONG cbRead;
HRESULT hr;
// Set up the DBOBJECT structure.
dbobject.dwFlags = STGM_READ;
dbobject.iid = IID_ISequentialStream;
// Create the DBBINDING, requesting a storage-object pointer from
// The SQL Server Native Client OLE DB provider.
dbbinding.iOrdinal = nCol;
dbbinding.obValue = 0;
dbbinding.obStatus = sizeof(IUnknown*);
dbbinding.obLength = 0;
dbbinding.pTypeInfo = NULL;
dbbinding.pObject = &dbobject;
dbbinding.pBindExt = NULL;
dbbinding.dwPart = DBPART_VALUE | DBPART_STATUS;
dbbinding.dwMemOwner = DBMEMOWNER_CLIENTOWNED;
dbbinding.eParamIO = DBPARAMIO_NOTPARAM;
dbbinding.cbMaxLen = 0;
dbbinding.dwFlags = 0;
dbbinding.wType = DBTYPE_IUNKNOWN;
dbbinding.bPrecision = 0;
dbbinding.bScale = 0;
if (FAILED(hr = pIRowset->
QueryInterface(IID_IAccessor, (void**) &pIAccessor)))
{
// Process QueryInterface failure.
return (hr);
}
// Create the accessor.
if (FAILED(hr = pIAccessor->CreateAccessor(DBACCESSOR_ROWDATA, 1,
&dbbinding, 0, &haccessor, &ulbindstatus)))
{
// Process error from CreateAccessor.
pIAccessor->Release();
return (hr);
}
// Read and process BLOCK_SIZE bytes at a time.
if (SUCCEEDED(hr = pIRowset->GetData(hRow, haccessor, pRow)))
{
dwStatus = *((ULONG*) (pRow + dbbinding.obStatus));
if (dwStatus == DBSTATUS_S_ISNULL)
{
// Process NULL data
}
else if (dwStatus == DBSTATUS_S_OK)
{
pISequentialStream = *((ISequentialStream**)
(pRow + dbbinding.obValue));
do
{
if (SUCCEEDED(hr =
pISequentialStream->Read(pUnboundData,
BLOCK_SIZE, &cbRead)))
{
pUnboundData += cbRead;
}
}
while (SUCCEEDED(hr) && cbRead >= BLOCK_SIZE);
pISequentialStream->Release();
}
}
else
{
// Process error from GetData.
}
pIAccessor->ReleaseAccessor(haccessor, NULL);
pIAccessor->Release();
delete [] pRow;
return (hr);
}