This documentation is archived and is not being maintained.

Retrieving a BLOB

You can retrieve a binary large object (BLOB) in various ways. You can use DBTYPE_BYTES to retrieve the BLOB as a sequence of bytes, or you can use an interface like ISequentialStream. For more information, see BLOBS and OLE Objects in the OLE DB Programmer's Reference.

The following code shows how to retrieve a BLOB using ISequentialStream. The macro BLOB_ENTRY allows you to specify the interface and the flags used for the interface. After opening the table, the code calls Read repeatedly on ISequentialStream to read bytes from the BLOB. The code calls Release to dispose of the interface pointer before calling MoveNext to obtain the next record.

class CCategories
   ISequentialStream*   pPicture;

   BLOB_ENTRY(4, IID_ISequentialStream, STGM_READ, pPicture)

CTable<CAccessor<CCategories> > categories;
ULONG          cb;
BYTE            myBuffer[65536];

categories.Open(session, "Categories");
while (categories.MoveNext() == S_OK)
      categories.pPicture->Read(myBuffer, 65536, &cb);
      // Do something with the buffer
   } while (cb > 0);

For more information on macros that handle BLOB data, see "Column Map Macros" in Macros and Global Functions for OLE DB Consumer Templates.

See Also

Using Accessors | Macros and Global Functions for OLE DB Consumer Templates