Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

153 lines
4.5 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright(C) 2000 Microsoft Corporation all rights reserved.
  4. //
  5. // Module: BaseCommand.H
  6. //
  7. // Project: Windows 2000 IAS
  8. //
  9. // Description: Declaration of the CBaseCommand class
  10. //
  11. // Author: tperraut
  12. //
  13. // Revision 02/24/2000 created
  14. //
  15. /////////////////////////////////////////////////////////////////////////////
  16. #ifndef _BASE_COMMAND_H_CC774BB1_DFE3_4730_96B7_7F7764CC54DC
  17. #define _BASE_COMMAND_H_CC774BB1_DFE3_4730_96B7_7F7764CC54DC
  18. #if _MSC_VER > 1000
  19. #pragma once
  20. #endif // _MSC_VER > 1000
  21. ///////////////////////////////////////////////////////////////////////////
  22. // CBaseCommand
  23. template <class TAccessor>
  24. class CBaseCommand : public CCommand<TAccessor>
  25. {
  26. public:
  27. CBaseCommand()
  28. :pPropSet(NULL),
  29. pRowsAffected(NULL),
  30. bBind(TRUE)
  31. {
  32. };
  33. void Init(CSession& Session);
  34. virtual ~CBaseCommand() throw();
  35. HRESULT BaseExecute();
  36. HRESULT BaseExecute(LONG Index);
  37. protected:
  38. DBPARAMS params;
  39. DBPARAMS* pParams;
  40. DBPROPSET* pPropSet;
  41. LONG_PTR* pRowsAffected;
  42. BOOL bBind;
  43. };
  44. //////////////////////////////////////////////////////////////////////////////
  45. // Init
  46. //////////////////////////////////////////////////////////////////////////////
  47. template <class TAccessor> void CBaseCommand<TAccessor>::Init(
  48. CSession& Session
  49. )
  50. {
  51. LPCWSTR szCommand = NULL;
  52. _com_util::CheckError(GetDefaultCommand(&szCommand));
  53. _com_util::CheckError(Create(Session, szCommand));
  54. // Bind the parameters if we have some
  55. if (_ParamClass::HasParameters())
  56. {
  57. // Bind the parameters in the accessor if they haven't already been bound
  58. _com_util::CheckError(BindParameters(
  59. &m_hParameterAccessor,
  60. m_spCommand,
  61. &params.pData
  62. ));
  63. // Setup the DBPARAMS structure
  64. params.cParamSets = 1;
  65. params.hAccessor = m_hParameterAccessor;
  66. pParams = &params;
  67. }
  68. else
  69. {
  70. pParams = NULL;
  71. }
  72. }
  73. //////////////////////////////////////////////////////////////////////////////
  74. // Destructor
  75. //////////////////////////////////////////////////////////////////////////////
  76. template <class TAccessor> CBaseCommand<TAccessor>::~CBaseCommand()
  77. {
  78. Close();
  79. ReleaseCommand();
  80. }
  81. //////////////////////////////////////////////////////////////////////////////
  82. // BaseExecute
  83. //////////////////////////////////////////////////////////////////////////////
  84. template <class TAccessor> HRESULT CBaseCommand<TAccessor>::BaseExecute()
  85. {
  86. HRESULT hr = Execute(GetInterfacePtr(), pParams, pPropSet, pRowsAffected);
  87. if ( SUCCEEDED(hr) )
  88. {
  89. // Only bind if we have been asked to and we have output columns
  90. if (bBind && _OutputColumnsClass::HasOutputColumns())
  91. {
  92. _com_util::CheckError(Bind());
  93. }
  94. hr = MoveNext();
  95. Close();
  96. if ( hr == S_OK )
  97. {
  98. return hr;
  99. }
  100. else if ( SUCCEEDED(hr) )
  101. {
  102. hr = E_FAIL;
  103. }
  104. }
  105. return hr;
  106. }
  107. //////////////////////////////////////////////////////////////////////////////
  108. // BaseExecute overloaded
  109. //////////////////////////////////////////////////////////////////////////////
  110. template <class TAccessor> HRESULT CBaseCommand<TAccessor>::BaseExecute(
  111. LONG Index
  112. )
  113. {
  114. HRESULT hr = Execute(GetInterfacePtr(), pParams, pPropSet, pRowsAffected);
  115. if ( SUCCEEDED(hr) )
  116. {
  117. // Only bind if we have been asked to and we have output columns
  118. if (bBind && _OutputColumnsClass::HasOutputColumns())
  119. {
  120. _com_util::CheckError(Bind());
  121. }
  122. hr = MoveNext(Index, true);
  123. Close();
  124. if ( hr == S_OK )
  125. {
  126. return hr;
  127. }
  128. else if ( SUCCEEDED(hr) )
  129. {
  130. hr = E_FAIL;
  131. }
  132. }
  133. return hr;
  134. }
  135. #endif // _BASE_COMMAND_H_CC774BB1_DFE3_4730_96B7_7F7764CC54DC