Extended OLEDB library : Ease of ADO, power of OLEDB

.

Environment:  : VC++6 SP5, MDAC 2.5 and above

Overview

Most of us know that OLEDB is the latest database technology that provides fastest data access on windows platform. However, many C++ programmers tend to avoid using raw OLEDB and prefer ADO in their development process. There are two main reasons for this. First of all, OLEDB interfaces (which are COM interfaces) are extremely complex and sparsely documented. They are neither convenient nor developer-friendly. So, we are left with other choice : use ATL consumer templates for OLEDB. These template classes are very powerful and high performance. However, they lack the flexibility and rich functionality provided by ADO. Many times one has to resort to ADO for some user interface operations such as binding a rowset to datagrid or other controls. This is because there is no direct way to bind an OLEDB rowset to a control.

This article presents a set of classes that are extended from ATL consumer template classes for OLEDB. While these classes provide added flexibility and functionality like ADO, they still retain the power and performance of consumer template classes. Here, in this article, I present only a subset of a complete libray that we have built for commercial product development.

[1] Connection object : CSypODLConnection

In OLEDB consumer templates, you have to deal with two classes for maintaining database connection and transaction purposes : CDataSource and CSession. This is sometimes confusing. Instead, we created a single class called CSypODLConnection that is very much like Connection object in ADO. This class combines the functionality of database connection and transaction maintenance. The use of this class is pretty simple :

// Define connection object
CSypODLConnection m_Cnn; 

// Connnect to database
m_Cnn.Open("CONNECTION STRING", "UID", "PWD"); 

You can also use transactions on this object like ADO connection object

m_Cnn.StartTransaction(); // Connnect to database
-- Code ---
m_Cnn.Commit();

Also, like ADO connection object, we have provided Execute method for executing action queries.

m_Cnn.Execute("DELETE FROM Customer WHERE CustomerID = 5");

[1] RecordBase, Exception, and Error classes

Similarly, we have also created a recordset class called CSypODLRecordBase, which wraps up CCommand and CTable comsumer template classes. Those who have worked with these consumer template classes know how tedious it is to check the HRESULT value after each method call. Not only is it time-consuming to check HRESULT value at every point, but also it is extremely difficult to get errors from IErrorInfo interface. In order to solve this problem, we created two classes : an exception class and an error-processing class. So, the code becomes very simple as shown below :

CSypODLRecordBase<CAccessor<CSalesManTableAccessor> > m_Rs;
// Process data now
try
{
  m_Rs.Open("SalesMan", &m_Cnn, 1); // 1 indicates table
  while (!m_Rs.IsEOF())
  {
      AfxMessageBox(m_Rs.GetAccessor()->m_SalesManName);
      m_Rs.MoveNext()
  }
  m_Rs.Close();
}

catch(CSypODLException e)
{
   e.DisplayError();
   return;
}
//

Essentially, if you already know ADO, this library will be easiest to understand and use. So, if you want to give your application a lightening speed and high performance, use these classes.

Actually, there are so many features and so many classes in the library that we can write a complete a book on it. However, due to lack of space and scope, I urge users to go through the code which is self-explanatory. I would also advise you to study the included sample, and see how easy it is to use these classes. If you need a complete documentation, you may contact me directly.

Known drawbacks and limitations

There seems to be bugs in some OLEDB providers that may affect some of the functionality of this library. For some reason, the Update method and bookmarks fail with certain providers.

If you decide to use this code

You are free to use or modify this code subject to the following restrictions:

* You must acknowledge us somewhere in your about box or documentation, simple "Parts of code by..Sypram Technology" will be enough. If you cannot (or don't want to) mention us, contact one of us personally.

* Do not remove copyright notices from the source and header files.

* Do not publish any part of this code or article on other websites.

* We reserve exclusive right to update this page, as well as provided source code. Please publish your modification and additions on adjacent pages. We may add your modifications and/or additions to a future update to the article and source with proper credit for your work.

Downloads

Download demo project - 57 Kb
Download source - 16 Kb


Comments

  • Detected Memory Leak, To improve this problem...

    Posted by Legacy on 11/01/2003 12:00am

    Originally posted by: Jung Hyun-Seung

    CSypODLRecordBase::
    
    void Close()
    {
    if(m_bIsOpen)
    {
    if(m_nRowsetType == 2)
    ((CCommand<TAccessor, TRowset>*)m_pSet)->ReleaseCommand(); // Add this Line
    m_pSet->Close();
    m_bIsOpen = false;
    m_bEOF = false;
    m_bBOF = false;
    }
    }

    Reply
  • VB AND ORACLE DIRECT CONNECTIVITY

    Posted by Legacy on 08/01/2002 12:00am

    Originally posted by: Sanjay

    HI,
    I wanted to connect to remote oracle database thru VB 6 (ADO) without installing the oracle client software on my machine. Is it possible ?

    thnx in advance

    Sanjay

    • hi

      Posted by dhananjaypadalkar on 01/24/2009 04:46am

      i had same requirement , i want connect client with ip address to server just like with "type 4" drivers used in java

      Reply
    Reply
  • Can't write...

    Posted by Legacy on 03/05/2002 12:00am

    Originally posted by: Stanislav P.

    I can't write to Interbase 5.0 or 6.0 table thru ODBC provider...
    Reading is OK.

    Reply
  • Version for VS.Net

    Posted by Legacy on 02/24/2002 12:00am

    Originally posted by: Alex Mitchell

    I am interested in a solution foe VS.Net
    The following does not compile:

    CSypODLRecordBase<CAccessor<CSalesManTableAccessor> > m_Rs;

    Reply
  • Thanks

    Posted by Legacy on 12/04/2001 12:00am

    Originally posted by: Bug Alert

    Maybe someday i will figure it out wats it about...

    Reply
  • What a Cool Way!!!

    Posted by Legacy on 12/04/2001 12:00am

    Originally posted by: Chandresh Patel

    POWERWAY!!! I am very happy to use this code and now my all problem with ado and bind with grid is all clear

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: October 23, 2014 @ 12:00 p.m. ET / 9:00 a.m. PT Despite the current "virtualize everything" mentality, there are advantages to utilizing physical hardware for certain tasks. This is especially true for backups. In many cases, it is clearly in an organization's best interest to make use of physical, purpose-built backup appliances rather than relying on virtual backup software (VBA - Virtual Backup Appliances). Join us for this eSeminar to learn why physical appliances are preferable to …

  • Live Event Date: October 29, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Are you interested in building a cognitive application using the power of IBM Watson? Need a platform that provides speed and ease for rapidly deploying this application? Join Chris Madison, Watson Solution Architect, as he walks through the process of building a Watson powered application on IBM Bluemix. Chris will talk about the new Watson Services just released on IBM bluemix, but more importantly he will do a step by step cognitive …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds