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.

136 lines
2.9 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) Microsoft Corp. All rights reserved.
  4. //
  5. // FILE
  6. //
  7. // oledbstore.cpp
  8. //
  9. // SYNOPSIS
  10. //
  11. // This file defines the class OleDBDataStore.
  12. //
  13. ///////////////////////////////////////////////////////////////////////////////
  14. #include <ias.h>
  15. #include <iasdb.h>
  16. #include <iasutil.h>
  17. #include <dsobject.h>
  18. #include <oledbstore.h>
  19. #include <propset.h>
  20. #include <msjetoledb.h>
  21. #include <oledberr.h>
  22. //////////
  23. // Current versions supported.
  24. //////////
  25. const LONG MIN_VERSION = IAS_WIN2K_VERSION;
  26. const LONG MAX_VERSION = IAS_CURRENT_VERSION;
  27. STDMETHODIMP OleDBDataStore::get_Root(IDataStoreObject** ppObject)
  28. {
  29. if (ppObject == NULL) { return E_INVALIDARG; }
  30. if (*ppObject = root) { (*ppObject)->AddRef(); }
  31. return S_OK;
  32. }
  33. STDMETHODIMP OleDBDataStore::Initialize(BSTR bstrDSName,
  34. BSTR bstrUserName,
  35. BSTR bstrPassword)
  36. {
  37. // Are we already initialized?
  38. if (root != NULL) { HRESULT_FROM_WIN32(ERROR_ALREADY_INITIALIZED); }
  39. // Open the database.
  40. HRESULT hr = IASOpenJetDatabase(bstrDSName, FALSE, &session);
  41. if (FAILED(hr)) { return hr; }
  42. //////////
  43. // Check the version.
  44. //////////
  45. LONG version;
  46. hr = IASExecuteSQLFunction(
  47. session,
  48. L"SELECT Version FROM Version",
  49. &version
  50. );
  51. // If the table doesn't exist, then version is zero.
  52. if (hr == DB_E_NOTABLE)
  53. {
  54. version = 0;
  55. }
  56. else if (FAILED(hr))
  57. {
  58. return hr;
  59. }
  60. // Is it out of bounds?
  61. if (version < MIN_VERSION || version > MAX_VERSION)
  62. {
  63. return HRESULT_FROM_WIN32(ERROR_REVISION_MISMATCH);
  64. }
  65. try
  66. {
  67. //////////
  68. // Initialize all the command objects.
  69. //////////
  70. members.initialize(session);
  71. create.initialize(session);
  72. destroy.initialize(session);
  73. find.initialize(session);
  74. update.initialize(session);
  75. erase.initialize(session);
  76. get.initialize(session);
  77. set.initialize(session);
  78. // Create the root object.
  79. root = DBObject::createInstance(this, NULL, 1, L"top");
  80. }
  81. CATCH_AND_RETURN()
  82. return S_OK;
  83. }
  84. STDMETHODIMP OleDBDataStore::OpenObject(BSTR bstrPath,
  85. IDataStoreObject** ppObject)
  86. {
  87. return E_NOTIMPL;
  88. }
  89. STDMETHODIMP OleDBDataStore::Shutdown()
  90. {
  91. //////////
  92. // Release the root.
  93. //////////
  94. root.Release();
  95. //////////
  96. // Finalize the commands.
  97. //////////
  98. set.finalize();
  99. get.finalize();
  100. erase.finalize();
  101. update.finalize();
  102. find.finalize();
  103. destroy.finalize();
  104. create.finalize();
  105. members.finalize();
  106. //////////
  107. // Release the data source connection.
  108. //////////
  109. session.Release();
  110. return S_OK;
  111. }