Click here to Skip to main content
15,897,371 members
Articles / Desktop Programming / MFC

Exposing tabular data from your COM object - Part 2

Rate me:
Please Sign up or sign in to vote.
5.00/5 (7 votes)
28 Jul 2000CPOL 95.3K   1.1K   33  
The ATL OLE DB Provider templates appear to rely on the fact that your data is kept in a simple array, but that's not really the case at all!
#include "stdafx.h"
#include "DataObjectRowset.h"
#include "MyDataObject.h"


void CDataObjectRowset::GetColumnInformation(
   size_t column, 
   DBTYPE &dbType, 
   ULONG &size, 
   std::string &columnName, 
   DWORD &flags)
{
   ATLASSERT(m_pDataObject);
   
   dbType = DBTYPE_STR;
   size = m_pDataObject->m_columnSize;

   columnName = m_pDataObject->m_columnNames[column];

}

void CDataObjectRowset::GetColumnData(
   size_t row,
   size_t column,
   DBTYPE &dbType, 
   ULONG &size, 
   void *&pData,
   bool &bIsUpdatable)
{
   ATLASSERT(m_pDataObject);

   dbType = DBTYPE_STR;
   size = m_pDataObject->m_columnSize;
   pData = m_pDataObject->GetAt(row+1, column+1);

   bIsUpdatable = false;
}

size_t CDataObjectRowset::GetNumColumns()
{
   ATLASSERT(m_pDataObject);

   return m_pDataObject->m_numCols;
}

size_t CDataObjectRowset::GetNumRows() const
{
   ATLASSERT(m_pDataObject);

   return m_pDataObject->m_numRows;
}

HRESULT CDataObjectRowset::AddRow()
{
   ATLASSERT(m_pDataObject);

   if (SUCCEEDED(m_pDataObject->AddRow()))
   {
      return S_OK;
   }

   return E_FAIL;
}

HRESULT CDataObjectRowset::RemoveRow(int nIndex)
{
   ATLASSERT(m_pDataObject);

   if (SUCCEEDED(m_pDataObject->RemoveRow(nIndex)))
   {
      return DBROWSTATUS_S_OK;
   }

   return E_FAIL;
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) JetByte Limited
United Kingdom United Kingdom
Len has been programming for over 30 years, having first started with a Sinclair ZX-80. Now he runs his own consulting company, JetByte Limited and has a technical blog here.

JetByte provides contract programming and consultancy services. We can provide experience in COM, Corba, C++, Windows NT and UNIX. Our speciality is the design and implementation of systems but we are happy to work with you throughout the entire project life-cycle. We are happy to quote for fixed price work, or, if required, can work for an hourly rate.

We are based in London, England, but, thanks to the Internet, we can work 'virtually' anywhere...

Please note that many of the articles here may have updated code available on Len's blog and that the IOCP socket server framework is also available in a licensed, much improved and fully supported version, see here for details.

Comments and Discussions