OLE DB User Records

To use a static accessor, your consumer must have a user record. The user record is a C++ class that contains data elements to handle input or output. The ATL Object Wizard generates a user record for your consumer. You can add methods to the user record for optional tasks like handling commands.

The following code shows a sample record that handles commands. In the user record, BEGIN_OLUMN_MAP represents a data rowset passed to the consumer from a provider. BEGIN_PARAM_MAP represents a set of command parameters. This example uses a CCommand class to handle the command parameters. The data members in the map entries represent offsets into one contiguous block of memory for each instance of the class. The COLUMN_ENTRY macros correspond to the PROVIDER_COLUMN_ENTRY macros on the provider side.

For more information on the COLUMN_MAP and PARAM_MAP macros, see Macros for OLE DB Consumer Templates.

class CArtists
{
public:
// Data Elements
   CHAR m_szFirstName[20];
   CHAR m_szLastName[30];
   short m_nAge;
 
// output binding map
BEGIN_COLUMN_MAP(CArtists)
   COLUMN_ENTRY(1, m_szFirstName)
   COLUMN_ENTRY(2, m_szLastName)
   COLUMN_ENTRY(3, m_nAge)
END_COLUMN_MAP()
 
// parameter binding map
BEGIN_PARAM_MAP(CArtists)
   COLUMN_ENTRY(1, m_nAge)
END_PARAM_MAP
};

The following example shows the user record modified to support multiple accessors on the rowset. Instead of BEGIN_COLUMN_MAP and END_COLUMN_MAP, it uses BEGIN_ACCESSOR_MAP and BEGIN_ACCESSOR for each accessor. The BEGIN_ACCESSOR macro specifies the accessor number (offset from zero) and whether the accessor is an autoaccessor. Autoaccessors call GetData to retrieve data automatically on a call to MoveNext. Non-automatic accessors require you to explicitly retrieve the data. Use a non-automatic accessor if you are binding to a large data field (like a bitmap image) that you may not want to retrieve for every record.

class CMultiArtists
{
public:
// Data Elements
   CHAR m_szFirstName[20];
   CHAR m_szLastName[30];
   short m_nAge;
 
// output binding map
BEGIN_ACCESSOR_MAP(CMultiArtists, 2)
   BEGIN_ACCESSOR(0, true)
    COLUMN_ENTRY(1, m_szFirstName)
    COLUMN_ENTRY(2, m_szLastName)
   END_ACCESSOR()
   BEGIN_ACCESSOR(1, false) // not an auto accessor
    COLUMN_ENTRY(3, m_nAge)
   END_ACCESSOR()
END_ACCESSOR_MAP()
};

Back to the OLE DB Consumer Template Architecture