Source code of Windows XP (NT5)
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.

102 lines
2.2 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1998, Microsoft Corp. All rights reserved.
  4. //
  5. // FILE
  6. //
  7. // cmdbase.cpp
  8. //
  9. // SYNOPSIS
  10. //
  11. // This file defines the class CommandBase.
  12. //
  13. // MODIFICATION HISTORY
  14. //
  15. // 02/20/1998 Original version.
  16. // 02/15/1999 Make commands MT safe.
  17. // 05/30/2000 Add trace support.
  18. //
  19. ///////////////////////////////////////////////////////////////////////////////
  20. #include <ias.h>
  21. #include <iasdb.h>
  22. #include <cmdbase.h>
  23. CommandBase::CommandBase() throw ()
  24. {
  25. dbParams.pData = NULL;
  26. dbParams.cParamSets = 0;
  27. dbParams.hAccessor = 0;
  28. }
  29. CommandBase::~CommandBase() throw ()
  30. {
  31. finalize();
  32. }
  33. void CommandBase::initialize(IUnknown* session)
  34. {
  35. setSession(session);
  36. setCommandText(getCommandText());
  37. setParamIO(createParamIO(command));
  38. setParameterData(this);
  39. }
  40. void CommandBase::finalize() throw ()
  41. {
  42. releaseAccessor(dbParams.hAccessor);
  43. command.Release();
  44. }
  45. void CommandBase::setCommandText(PCWSTR commandText)
  46. {
  47. CheckOleDBError(
  48. "ICommandText::SetCommandText",
  49. command->SetCommandText(DBGUID_DBSQL, commandText)
  50. );
  51. CComPtr<ICommandPrepare> prepare;
  52. _com_util::CheckError(
  53. command->QueryInterface(
  54. __uuidof(ICommandPrepare),
  55. (PVOID*)&prepare
  56. )
  57. );
  58. CheckOleDBError(
  59. "ICommandPrepare::Prepare",
  60. prepare->Prepare(0)
  61. );
  62. }
  63. void CommandBase::setSession(IUnknown* session)
  64. {
  65. CComPtr<IDBCreateCommand> creator;
  66. _com_util::CheckError(
  67. session->QueryInterface(
  68. __uuidof(IDBCreateCommand),
  69. (PVOID*)&creator
  70. )
  71. );
  72. CheckOleDBError(
  73. "IDBCreateCommand::CreateCommand",
  74. creator->CreateCommand(
  75. NULL,
  76. __uuidof(ICommandText),
  77. (IUnknown**)&command
  78. )
  79. );
  80. }
  81. void CheckOleDBError(PCSTR functionName, HRESULT errorCode)
  82. {
  83. if (FAILED(errorCode))
  84. {
  85. _com_issue_error(IASTraceJetError(functionName, errorCode));
  86. }
  87. }