home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / common / msdev98 / template / atl / consumer.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-06-16  |  2.5 KB  |  106 lines

  1. // [!HeaderName] : Declaration of the [!ClassName] class
  2. [!crlf]
  3. [!if=(FileExists, "FALSE")]
  4. #ifndef __[!UpperShortName]_H_
  5. #define __[!UpperShortName]_H_
  6. [!endif]
  7. [!crlf]
  8. class [!Accessor]
  9. {
  10. public:
  11. [!DTLVariables]
  12. [!crlf]
  13. [!if=(DTLProcedure, "TRUE")]
  14. BEGIN_PARAM_MAP([!Accessor])
  15. [!DTLParameterAccessor]
  16. END_PARAM_MAP()
  17. [!crlf]
  18. [!endif]
  19. [!if=(DTLColumnMap, "TRUE")]
  20. BEGIN_COLUMN_MAP([!Accessor])
  21. [!DTLAccessor]
  22. END_COLUMN_MAP()
  23. [!crlf]
  24. [!endif]
  25. [!if=(DTLType, "Command")]
  26. DEFINE_COMMAND([!Accessor], _T("[!DTLCommand]"))
  27. [!endif]
  28. [!crlf]
  29.     // You may wish to call this function if you are inserting a record and wish to
  30.     // initialize all the fields, if you are not going to explicitly set all of them.
  31.     void ClearRecord()
  32.     {
  33.         memset(this, 0, sizeof(*this));
  34.     }
  35. };
  36. [!crlf]
  37. [!if=(DTLType, "Command")]
  38. class [!ClassName] : public CCommand<CAccessor<[!Accessor]> >
  39. [!else]
  40. class [!ClassName] : public CTable<CAccessor<[!Accessor]> >
  41. [!endif]
  42. {
  43. public:
  44.     HRESULT Open()
  45.     {
  46.         HRESULT        hr;
  47. [!crlf]
  48.         hr = OpenDataSource();
  49.         if (FAILED(hr))
  50.             return hr;
  51. [!crlf]
  52.         return OpenRowset();
  53.     }
  54.     HRESULT OpenDataSource()
  55.     {
  56.         HRESULT        hr;
  57.         CDataSource db;
  58.         CDBPropSet    dbinit(DBPROPSET_DBINIT);
  59. [!crlf]
  60. [!DTLOpen]
  61. [!if!=(DTLService,"")]
  62. [!crlf]
  63.         // The provider does not support updatability natively, 
  64.         // but does support SQL. The OLE DB service components 
  65.         // will be invoked to provide updatability via SQL.
  66. [!endif]
  67.         hr = db.Open[!DTLService](_T("[!DTLProgID]"), &dbinit);
  68.         if (FAILED(hr))
  69.             return hr;
  70. [!crlf]
  71.         return m_session.Open(db);
  72.     }
  73.     HRESULT OpenRowset()
  74.     {
  75. [!if!=(DTLUpdate, "")]
  76.         // Set properties for open
  77.         CDBPropSet    propset(DBPROPSET_ROWSET);
  78.         propset.AddProperty(DBPROP_IRowsetChange, true);
  79.         propset.AddProperty(DBPROP_UPDATABILITY, [!DTLUpdate]);
  80. [!crlf]
  81. [!endif]
  82. [!if=(DTLNoService, "TRUE")]
  83.         // The provider is read only so the property change code has
  84.         // not been generated.
  85. [!endif]
  86. [!if=(DTLType, "Command")]
  87. [!if!=(DTLUpdate,"")]
  88.         return CCommand<CAccessor<[!Accessor]> >::Open(m_session, NULL, &propset);
  89. [!else]
  90.         return CCommand<CAccessor<[!Accessor]> >::Open(m_session);
  91. [!endif]
  92. [!else]
  93. [!if!=(DTLUpdate,"")]
  94.         return CTable<CAccessor<[!Accessor]> >::Open(m_session, _T("[!DTLCommand]"), &propset);
  95. [!else]
  96.         return CTable<CAccessor<[!Accessor]> >::Open(m_session, _T("[!DTLCommand]"));
  97. [!endif]
  98. [!endif]
  99.     }
  100.     CSession    m_session;
  101. };
  102. [!crlf]
  103. [!if=(FileExists, "FALSE")]
  104. #endif // __[!UpperShortName]_H_
  105. [!endif]
  106.