The information in this article applies to:
SUMMARY
The AOTBLOB sample demonstrates reading and writing long binary data (BLOB)
fields using the ATL OLE DB Consumer Template classes. The sample contains
code to load and save a bitmap file and to load and save the bitmap image
into a database table.
Microsoft Jet 3.51 OLE DB Provider (Msjtor35.dll 3.52.1527.4)The sample was also tested with the following ODBC drivers accessed via the Microsoft OLE DB Provider for ODBC Drivers: Microsoft SQL Server ODBC Driver (Sqlsrv32.dll 3.60.0319). MORE INFORMATIONThe following files are available for download from the Microsoft
Download Center. Click the file names below to download the files: http://www.microsoft.com/downloads/search.aspand then click How to use the Microsoft Download Center. Reading BLOB Data Using the ATL OLE DB Consumer TemplatesThe ATL OLE DB Consumer Template Wizard creates a fully functional read- only class that reads a long binary (BLOB) database field. If you want to write to the long binary field, you must make modifications to the wizard- generated class.In a wizard-generated OLE DB consumer class, the provider automatically populates any BLOB field member variables with a ISequentialStream pointer for the current row. To read data from the BLOB field, you call the Read method of the ISequentialStream interface in a loop until no more data is sent by the OLE DB provider. Note that most providers don't provide you with the total length of the data prior to reading the data, so you must build a buffer dynamically to hold the data as you read it. Writing BLOB Data Using the ATL OLE DB Consumer TemplatesTo write to a BLOB field, you must release the ISequentialStream pointer provided to you by the OLE DB provider and replace it with an ISequentialStream pointer that you implement. The provider then calls ISequentialStream::Read on your interface pointer until no more bytes are returned. This in a way reverses the role of the consumer and provider. The consumer provides the ISequentialStream pointer, and the provider calls ISequentialStream::Read. Note that certain OLE DB providers require that you indicate up front how many bytes are in the BLOB field when you write the BLOB data. To work with as many providers as possible, the sample provides the length information to the provider in every case.To simplify the reading and writing of BLOB data with OLE DB, the AOTBLOB sample has a helper class called CISSHelper. The CISSHelper class implements the entire ISequentialStream interface. The class also has a built-in buffer, which is used to store and extract the BLOB data. Note that the CISSHelper does not destroy itself when its release count drops to zero, similar to a typical COM interface. The AddRef and Release are left in so the provider can call them, but this sample uses a stack allocated object and relies on the C++ destructor to clean up the object. To allow writing to a BLOB field, you must modify the ATL OLE DB Consumer wizard-generated binding macro and add support for a field length and status indicator as below:
The length indicator is needed to provide the length of the BLOB data to
the OLE DB provider when you write to the BLOB. Note that the definition of
the BLOB_ENTRY_LENGTH_STATUS macro is included in the AOTBLOB sample
project--it is not included in the ATL header files for the ATL OLE DB
consumer classes.
No additional modifications to the wizard-generated templates are needed. To read from the BLOB field using a modified (length and status added) consumer template class, follow this basic formula:
Additional query words:
Keywords : kbfile kbADO200 kbDatabase kbDriver kbODBC kbOracle kbProvider kbVC600 kbGrpMDAC |
Last Reviewed: December 10, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |