Article ID: 190958 - Last Review: March 2, 2005 - Revision: 2.4 SAMPLE: AOTBLOB Read/Writes BLOB Using OLE DB Consumer Template
This article was previously published under Q190958 On This PageSUMMARY
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.
The sample also demonstrates how to prompt the user to select a datasource using the Microsoft Data Link dialog box, in the same manner as a browse connect in ODBC. NOTE: The sample automatically creates a table named BLOB1234 on the target datasource for insertion and extraction of the BLOB field. The sample code was tested with the following OLE DB providers:
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 OLE DB Provider for Oracle (Msdaora.dll 02.00.3002.15) Microsoft OLE DB Provider for SQL Server (Sqloledb.dll 07.00.0502) Microsoft OLE DB Provider for ODBC Drivers (Msdasql.dll 02.00.3002.11)
Microsoft SQL Server ODBC Driver (Sqlsrv32.dll 3.60.0319). Microsoft ODBC Driver for Oracle (Msora32.dll 2.573.292700). Microsoft Access Driver (Odbcjt32.dll 3.51.1713) MORE INFORMATIONThe following files are available for download from the Microsoft
Download Center: Aotblob.exe (http://download.microsoft.com/download/vc60ent/sample3/1/win98/en-us/aotblob.exe) For additional information about how to download Microsoft Support files, click the following article number to view the article in the Microsoft Knowledge Base: 119591
(http://support.microsoft.com/kb/119591/EN-US/
)
How to Obtain Microsoft Support Files from Online Services
Microsoft scanned this file for viruses. Microsoft used the most current virus-detection software that was available on the date that the file was posted. The file is stored on security-enhanced servers that help to prevent any unauthorized changes to the file.
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: 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:
| Other Resources Other Support Sites
CommunityArticle Translations |





















Back to the top