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.

101 lines
2.6 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1998, Microsoft Corp. All rights reserved.
  4. //
  5. // FILE
  6. //
  7. // cmdbase.h
  8. //
  9. // SYNOPSIS
  10. //
  11. // This file declares the class CommandBase.
  12. //
  13. // MODIFICATION HISTORY
  14. //
  15. // 02/20/1998 Original version.
  16. // 02/15/1999 Make commands MT safe.
  17. // 02/19/1999 Move definition of CommandBase::Execute to propcmd.cpp
  18. // 05/30/2000 Add trace support.
  19. //
  20. ///////////////////////////////////////////////////////////////////////////////
  21. #ifndef _CMDBASE_H_
  22. #define _CMDBASE_H_
  23. #include <bind.h>
  24. #include <guard.h>
  25. #include <nocopy.h>
  26. #include <oledb.h>
  27. void CheckOleDBError(PCSTR functionName, HRESULT errorCode);
  28. //////////
  29. // The maximum length of a stringized LONG.
  30. //////////
  31. const size_t SZLONG_LENGTH = 12;
  32. ///////////////////////////////////////////////////////////////////////////////
  33. //
  34. // CLASS
  35. //
  36. // CommandBase
  37. //
  38. // DESCRIPTION
  39. //
  40. // This class provides serves as an abstract base class for paremeterized,
  41. // prepared, text SQL commands.
  42. //
  43. ///////////////////////////////////////////////////////////////////////////////
  44. class CommandBase : NonCopyable, protected Guardable
  45. {
  46. public:
  47. CommandBase() throw ();
  48. virtual ~CommandBase() throw ();
  49. void initialize(IUnknown* session);
  50. void finalize() throw ();
  51. protected:
  52. // Executes the command.
  53. void execute(REFIID refiid = IID_NULL, IUnknown** result = NULL);
  54. // Releases an accessor associated with this command.
  55. void releaseAccessor(HACCESSOR h) throw ()
  56. {
  57. Bind::releaseAccessor(command, h);
  58. }
  59. // Sets and prepares the command text.
  60. void setCommandText(PCWSTR commandText);
  61. // Sets the parameter data buffer.
  62. void setParameterData(PVOID data) throw ()
  63. {
  64. dbParams.pData = data;
  65. }
  66. // Sets the parameter accessor for the command.
  67. void setParamIO(HACCESSOR accessor) throw ()
  68. {
  69. dbParams.cParamSets = 1;
  70. dbParams.hAccessor = accessor;
  71. }
  72. // Associates a session with the command. This triggers the actual creation
  73. // of the underlying OLE-DB command object.
  74. void setSession(IUnknown* session);
  75. // Defined in the sub-class to create a parameter accessor.
  76. virtual HACCESSOR createParamIO(IUnknown* session) const = 0;
  77. // Defined in the sub-class to return the SQL text.
  78. virtual PCWSTR getCommandText() const throw () = 0;
  79. CComPtr<ICommandText> command; // The OLE-DB command object.
  80. DBPARAMS dbParams; // Parameter data.
  81. };
  82. #endif // _CMDBASE_H_