OLE DB Consumer Templates: A Programmer's Guide
Authors: Pierre Nallet
Venue:  (2000)

From the Book: OLE DB, OLE DB consumer templates? Why should you care? At first, when a new technology emerges, the first reaction is confusion: Why do we need something new? What does it do? How does it work? Is it worth my time? OLE DB is one of many data access technologies. The field of data access technology is very crowded, one example being Microsoft's ODBC. Usually when there are many competing technologies, it is a sign of tradeoffs. One technology might be easy to use but slow; another might be fast but not portable; another might be portable but difficult to use; and so forth. OLE DB does better than any of the other technologies in many areas: It is based on COM, it is very modular and efficient, it covers many aspects of data access, and it is supported by many data vendors. In fact, this explains why Microsoft uses OLE DB inside its SQL Server and for distributed queries. However, OLE DB has one drawback: complexity. Writing a simple program or component with OLE DB is similar to writing a graphical user interface (GUI) application using the Windows API: It takes lots of (not so simple) code to perform a simple task. This is where the OLE DB consumer templates come in: They are a high-level, high-performance C++ library on top of OLE DB. In short, the OLE DB consumer templates are to database programming what ATL is to GUI programming. One of the greatbenefits of this approach is that you can choose the level you are working at. You can use the template library and stay at a high level of abstraction, but you also have access to all the lower-level details. There are two ways to look at what OLE DB can offer: If you are a database programmer, you probably know first-hand the drawbacks of letting people access the database directly. You need some kind of intermediate protective layer. A set of COM components is a good choice for accomplishing this, and the OLE DB consumer templates are a good tool for gluing the components and the database together. If you are a C++ developer, you might need persistence support. Databases are one of many choices. One of the traditional drawbacks of storing data in a database is that the database is complicated for the programmer to manage. The OLE DB consumer templates, however, provide a straightforward approach for C++ programmers. At first, I was happy being a simple OLE DB consumer templates programmer. As time passed, however, I realized that there was no in-depth documentation of this library and no book devoted to it. I had to explore this library by myself. Furthermore, I realized that the OLE DB consumer templates did not cover all facets of OLE DB, so I started writing small extensions that would cover additional aspects of OLE DB or offer different options. I grouped them together in one library that I called the OLE DB extensions. When I thought about releasing the code, it became obvious that the OLE DB extensions were bigger than the OLE DB consumer templates and hence needed some documentation. As a result, I decided to write this book to explain both the OLE DB consumer templates and the OLE DB extensions. When starting with OLE DB, you have two options: One, you can start at the lower level with Microsoft's OLE DB SDK and then go up a more abstract level. Two, you can start at the C++ level with the OLE DB consumer templates and go down to the SDK level when needed. This book presents OLE DB programming using the templates, not the SDK. Microsoft provides detailed documentation of OLE DB, so there is no point in replicating that effort here. However, this book is designed to be more or less self-contained. If there is a concept of the SDK that needs to be understood, I'll spend some time on it. In other words, you won't have to turn to the SDK documentation too frequently. This does not mean that you should not refer to the OLE DB SDK; the SDK remains the best the reference to use. Dealing with OLE DB is a little bit like using COM. At first, you wonder why you need to deal with this complex technology. But once you have used it for some time, you will wonder how you could have programmed without it. In between, several events need to occur. First, you should understand, through experience, the motives behind the technology; when you understand why something exists, it is easier to understand how it works. Second, you need to think that it is easyeasy to understand and easy to use. The OLE DB consumer templates will facilitate this transition because you can use them progressively. Performing simple tasks is straightforward. Then you can increasingly explore the numerous options that the library offers. In other words, your understanding of the OLE DB consumer templates can grow with your needs. The goal of this book is to take you along this learning path and to help you develop efficient, scalable, manageable database applications. The Future of OLE DB OLE DB is an evolving technology. While this book is based on version 2.5, it is likely that a new version will be released before or right after this book appears on the shelves. Actually, OLE DB 2.6 is already available with SQL Server beta 2. OLE DB 2.6 introduces streams as a result of commands, which is useful for returning an XML stream instead of a rowset. The OLE DB for Data Mining specification is also close to the final stage of development. What is next? OLE DB will continue to follow the needs of the marketplace. Look for complex row support, more XML support, and more command languages. Logistics What do you need to be able to run the OLE DB consumer templates on your computer? First, you need a C++ compilerVisual C++ 6.0 or later. Visual C++ comes with the OLE DB consumer templates files and a default OLE DB setup. It also would be a good idea to download the latest platform SDK from http://msdn.microsoft.com/. Finally, the OLE DB extension files and the examples discussed in this book are available at http://www.com-object.com/oledbtemplates. Note that some examples require the Windows Template Library (WTL), which is part of the SDK platform. The ACM Portal is published by the Association for Computing Machinery. Copyright © 2010 ACM, Inc. Terms of Usage Privacy Policy Code of Ethics Contact Us Useful downloads: Adobe Acrobat QuickTime Windows Media Player Real Player