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.

183 lines
5.3 KiB

  1. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Microsoft WMIOLE DB Provider
  4. // (C) Copyright 1999 Microsoft Corporation. All Rights Reserved.
  5. //
  6. // colinfo.cpp | IColumnsInfo interface implementation
  7. //
  8. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  9. #include "headers.h"
  10. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  11. //
  12. // IColumnsInfo specific methods
  13. //
  14. // Returns the column metadata needed by most consumers.
  15. //
  16. // HRESULT
  17. // S_OK The method succeeded
  18. // E_OUTOFMEMORY Out of memory
  19. // E_INVALIDARG pcColumns or prginfo or ppStringsbuffer was NULL
  20. //
  21. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  22. STDMETHODIMP CImpIColumnsInfo::GetColumnInfo( DBORDINAL* pcColumns, //OUT Number of columns in rowset
  23. DBCOLUMNINFO** prgInfo, //OUT Array of DBCOLUMNINFO Structures
  24. OLECHAR** ppStringsBuffer //OUT Storage for all string values
  25. )
  26. {
  27. ULONG icol = 0;
  28. DBCOLUMNINFO* rgdbcolinfo = NULL;
  29. WCHAR* pstrBuffer = NULL;
  30. WCHAR* pstrBufferForColInfo = NULL;
  31. HRESULT hr = S_OK;
  32. CSetStructuredExceptionHandler seh;
  33. TRY_BLOCK;
  34. //==============================================
  35. // Initialize
  36. //==============================================
  37. if ( pcColumns ){
  38. *pcColumns = 0;
  39. }
  40. if ( prgInfo ){
  41. *prgInfo = NULL;
  42. }
  43. if ( ppStringsBuffer ){
  44. *ppStringsBuffer = NULL;
  45. }
  46. // Serialize access to this object.
  47. CAutoBlock cab(BASEROW->GetCriticalSection());
  48. g_pCError->ClearErrorInfo();
  49. //==============================================
  50. // Usual argument checking
  51. //==============================================
  52. if(m_pObj->IsZoombie())
  53. {
  54. hr = E_UNEXPECTED;
  55. }
  56. if ( pcColumns == NULL || prgInfo == NULL || ppStringsBuffer == NULL ){
  57. hr = E_INVALIDARG;
  58. }
  59. else{
  60. hr = BASEROW->GetColumnInfo(pcColumns,prgInfo , ppStringsBuffer);
  61. }
  62. hr = hr == S_OK ? hr : g_pCError->PostHResult(hr,&IID_IColumnsInfo);
  63. CATCH_BLOCK_HRESULT(hr,L"IColumnInfo::GetColumnInfo");
  64. return hr;
  65. }
  66. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  67. //
  68. // Returns an array of ordinals of the columns in a rowset that are identified by the specified column IDs.
  69. //
  70. // HRESULT
  71. // S_OK The method succeeded
  72. // E_INVALIDARG cColumnIDs was not 0 and rgColumnIDs was NULL,rgColumns was NULL
  73. // DB_E_COLUMNUNAVAILABLE An element of rgColumnIDs was invalid
  74. //
  75. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  76. STDMETHODIMP CImpIColumnsInfo::MapColumnIDs ( DBORDINAL cColumnIDs, //IN Number of Column IDs to map
  77. const DBID rgColumnIDs[], //IN Column IDs to map
  78. DBORDINAL rgColumns[] //OUT Ordinal values
  79. )
  80. {
  81. ULONG ulError = 0;
  82. ULONG i = 0;
  83. HRESULT hr = S_OK;
  84. CSetStructuredExceptionHandler seh;
  85. TRY_BLOCK;
  86. //========================================
  87. // Serialize access to this object.
  88. //========================================
  89. CAutoBlock cab(BASEROW->GetCriticalSection());
  90. g_pCError->ClearErrorInfo();
  91. if(m_pObj->IsZoombie())
  92. {
  93. hr = E_UNEXPECTED;
  94. }
  95. else
  96. //==========================================================
  97. // If cColumnIDs is 0 return
  98. //==========================================================
  99. if ( cColumnIDs != 0 ){
  100. //======================================================
  101. // Check arguments
  102. //======================================================
  103. if ( rgColumnIDs == NULL ){
  104. hr = E_INVALIDARG;
  105. }
  106. else{
  107. if ( rgColumns == NULL ){
  108. hr = E_INVALIDARG ;
  109. }
  110. else{
  111. //===============================================
  112. // Walk the Column ID structs and determine
  113. // the ordinal value
  114. //===============================================
  115. for ( i=0; i < cColumnIDs; i++ ){
  116. if ( ( rgColumnIDs[i].eKind == DBKIND_PROPID &&
  117. rgColumnIDs[i].uName.ulPropid < 1 &&
  118. rgColumnIDs[i].uName.ulPropid > BASEROW->m_cTotalCols ) ||
  119. ( rgColumnIDs[i].eKind == DBKIND_NAME &&
  120. rgColumnIDs[i].uName.pwszName == NULL ) ||
  121. ( rgColumnIDs[i].eKind == DBKIND_GUID_PROPID ) )
  122. {
  123. /* if ( ( rgColumnIDs[i].uName.ulPropid < 1 ) ||
  124. ( rgColumnIDs[i].uName.ulPropid > BASEROW->m_cTotalCols ) ||
  125. ( rgColumnIDs[i].eKind != DBKIND_GUID_PROPID ) ||
  126. ( rgColumnIDs[i].uGuid.guid != GUID_NULL ) )
  127. */
  128. rgColumns[i] = DB_INVALIDCOLUMN;
  129. ulError++;
  130. }
  131. else
  132. {
  133. if(rgColumnIDs[i].eKind == DBKIND_PROPID)
  134. {
  135. rgColumns[i] = rgColumnIDs[i].uName.ulPropid;
  136. }
  137. else
  138. {
  139. rgColumns[i] = BASEROW->GetOrdinalFromColName(rgColumnIDs[i].uName.pwszName);
  140. }
  141. }
  142. }
  143. if ( !ulError ){
  144. hr = S_OK;
  145. }
  146. else if ( ulError < cColumnIDs ){
  147. hr = DB_S_ERRORSOCCURRED;
  148. }
  149. else{
  150. hr = DB_E_ERRORSOCCURRED;
  151. }
  152. }
  153. }
  154. }
  155. hr = hr == S_OK ? hr : g_pCError->PostHResult(hr,&IID_IColumnsInfo);
  156. CATCH_BLOCK_HRESULT(hr,L"IColumnInfo::MapColumnIDs");
  157. return hr;
  158. }