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.

122 lines
3.8 KiB

  1. ////////////////////////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Microsoft WMIOLE DB Provider
  4. // (C) Copyright 1999 Microsoft Corporation. All Rights Reserved.
  5. //
  6. // IAlterTable.cpp - IAlterTable interface implementation
  7. ////////////////////////////////////////////////////////////////////////////////////////////////////
  8. #include "headers.h"
  9. #include "dbsess.h"
  10. ////////////////////////////////////////////////////////////////////////////////////////////////////
  11. //
  12. // Modifies properties of columns
  13. // In WMI terms modifies properties of a class
  14. //
  15. // Returns one of the following values:
  16. // S_OK Altering the column succeeded
  17. // E_FAIL AlterColumn failed due to a WMI error
  18. // DB_E_BADTABLEID The TableID passed is invalid or bad
  19. // DB_E_NOCOLUMN The ColumnID passed is invalid or bad
  20. // E_INVALIDARG One of more arguments passed in not valid
  21. // DB_E_NOTSUPPORTED The requested type of modification of column
  22. // not supported
  23. ////////////////////////////////////////////////////////////////////////////////////////////////////
  24. STDMETHODIMP CImplIAlterTable::AlterColumn(DBID * pTableID,
  25. DBID * pColumnID,
  26. DBCOLUMNDESCFLAGS ColumnDescFlags,
  27. DBCOLUMNDESC * pColumnDesc)
  28. {
  29. HRESULT hr = E_FAIL;
  30. WCHAR *pwcsTableName = NULL;
  31. //===================================================================
  32. // Initialize incoming parameters
  33. //===================================================================
  34. CSetStructuredExceptionHandler seh;
  35. TRY_BLOCK;
  36. // Seriliaze the object
  37. CAutoBlock cab(m_pObj->GetCriticalSection());
  38. // Clear ErrorInfo
  39. g_pCError->ClearErrorInfo();
  40. if(wcslen(pTableID->uName.pwszName) == 0 || pTableID->eKind != DBKIND_NAME)
  41. {
  42. hr = DB_E_BADTABLEID;
  43. }
  44. else
  45. if(wcslen(pColumnID->uName.pwszName) == 0 || pColumnID->eKind != DBKIND_NAME)
  46. {
  47. hr = DB_E_NOCOLUMN;
  48. }
  49. else
  50. if( pColumnDesc == NULL)
  51. {
  52. hr = E_INVALIDARG;
  53. }
  54. else
  55. if( pColumnDesc->dbcid.uName.pwszName == NULL)
  56. {
  57. hr = E_INVALIDARG;
  58. }
  59. else
  60. //===================================================================================
  61. // Check the connection is valid & the alteration flags is supported or not
  62. //===================================================================================
  63. if(S_OK == (hr =CheckIfSupported(ColumnDescFlags)) &&
  64. m_pObj->m_pCDataSource->m_pWbemWrap->ValidConnection() )
  65. {
  66. CWmiOleDBMap Map;
  67. if(SUCCEEDED(hr =Map.FInit(NO_QUALIFIERS,(LPWSTR)pTableID->uName.pwszName,m_pObj->m_pCDataSource->m_pWbemWrap)))
  68. {
  69. hr = Map.SetColumnProperties(pColumnDesc);
  70. }
  71. }
  72. hr = hr == S_OK ? hr :g_pCError->PostHResult(hr,&IID_IAlterTable);
  73. CATCH_BLOCK_HRESULT(hr,L"IAlterTable::AlterColumn");
  74. return hr;
  75. }
  76. ////////////////////////////////////////////////////////////////////////////////////////////////////
  77. //
  78. // Modifies some of the attributes of the class
  79. //
  80. // Returns one of the following values:
  81. // DB_E_NOTSUPPORTED Altering the properties of table not supported
  82. ////////////////////////////////////////////////////////////////////////////////////////////////////
  83. STDMETHODIMP CImplIAlterTable::AlterTable(DBID * pTableID,
  84. DBID * pNewTableID,
  85. ULONG cPropertySets,
  86. DBPROPSET rgPropertySet[])
  87. {
  88. HRESULT hr = DB_E_NOTSUPPORTED;
  89. CSetStructuredExceptionHandler seh;
  90. TRY_BLOCK;
  91. // Clear ErrorInfo
  92. g_pCError->ClearErrorInfo();
  93. hr = hr == S_OK ? hr :g_pCError->PostHResult(hr,&IID_IAlterTable);
  94. // return not supported as no TABLE Properties are supported
  95. CATCH_BLOCK_HRESULT(hr,L"IAlterTable::AlterTable");
  96. return hr;
  97. }
  98. HRESULT CImplIAlterTable::CheckIfSupported(DBCOLUMNDESCFLAGS ColumnDescFlags)
  99. {
  100. if(ColumnDescFlags == DBCOLUMNDESCFLAGS_PROPERTIES)
  101. return S_OK;
  102. else
  103. return DB_E_NOTSUPPORTED;
  104. }