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.

236 lines
7.7 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1998-2000.
  5. //
  6. // File: BmkAcc.cxx
  7. //
  8. // Contents: Distributed Bookmark accessor class
  9. //
  10. // Classes: CDistributedBookmarkAccessor
  11. //
  12. // History: 25-Sep-98 VikasMan Created
  13. //
  14. //----------------------------------------------------------------------------
  15. #include <pch.cxx>
  16. #pragma hdrstop
  17. #include "bmkacc.hxx"
  18. //+---------------------------------------------------------------------------
  19. //
  20. // Member: CDistributedBookmarkAccessor::CDistributedBookmarkAccessor, public
  21. //
  22. // Synopsis: Builds the bookmark accessors
  23. //
  24. // Arguments: [aCursor] -- Child rowsets.
  25. // [cCursor] -- Count of [aCursor].
  26. // [dwAccessorFlags] -- Binding type.
  27. // [pStatus] -- Status reported here. May be null.
  28. // [iBookmark] -- Ordinal of bookmark column.
  29. // [cbBookmark] -- Size of bookmark.
  30. //
  31. // History: 28-Sep-98 VikasMan Created.
  32. // 06-Jan-2000 KLam Fixed bindings
  33. //
  34. //----------------------------------------------------------------------------
  35. CDistributedBookmarkAccessor::CDistributedBookmarkAccessor(
  36. IRowset ** const aCursor,
  37. unsigned cCursor,
  38. DBACCESSORFLAGS dwAccessorFlags,
  39. DBBINDSTATUS* pStatus,
  40. DBORDINAL iBookmark,
  41. DBBKMARK cbBookmark )
  42. {
  43. Win4Assert( aCursor && cCursor > 0 );
  44. DBBINDING bindBmk;
  45. DBBINDSTATUS bmkBindStatus;
  46. unsigned iChild;
  47. SCODE sc = S_OK;
  48. SCODE scLast = S_OK;
  49. TRY
  50. {
  51. _xIacc.Init( cCursor );
  52. for ( iChild = 0; iChild < cCursor; iChild++ )
  53. {
  54. sc = aCursor[iChild]->QueryInterface( IID_IAccessor,
  55. _xIacc[iChild].GetQIPointer() );
  56. if ( FAILED(sc) )
  57. {
  58. scLast = sc;
  59. vqDebugOut(( DEB_ERROR,
  60. "CDistributedBookmarkAccessor: CreateAccessor(child %d) returned 0x%x\n",
  61. iChild, sc ));
  62. // Don't throw here. We want to continue on and catch all possible errors
  63. }
  64. }
  65. if (FAILED(scLast))
  66. {
  67. THROW( CException(scLast) );
  68. }
  69. // Binding structure for child bookmarks
  70. //----------------------------------//
  71. // Cursor# | Value1 | Value2 | ... // // The first 4 bytes are shared by cursor #
  72. // Status // // and status
  73. //----------------------------------//
  74. _xhaccBookmark.Init( cCursor );
  75. RtlZeroMemory( &bindBmk, sizeof bindBmk );
  76. bindBmk.iOrdinal = iBookmark;
  77. bindBmk.wType = DBTYPE_BYTES;
  78. bindBmk.dwPart = DBPART_VALUE | DBPART_STATUS;
  79. bindBmk.cbMaxLen = ( cbBookmark - sizeof(DBROWSTATUS) ) / cCursor;
  80. bindBmk.obValue = sizeof( DBROWSTATUS );
  81. bindBmk.obStatus = 0;
  82. for ( iChild = 0 ; iChild < cCursor; iChild++ )
  83. {
  84. sc = _xIacc[iChild]->CreateAccessor( dwAccessorFlags,
  85. 1,
  86. &bindBmk,
  87. 0,
  88. &(_xhaccBookmark[iChild]),
  89. &bmkBindStatus );
  90. if ( FAILED(sc) )
  91. {
  92. // remember that at least one child failed to create accessor
  93. scLast = sc;
  94. if ( pStatus && S_OK != scLast )
  95. {
  96. // set Status to reflect the failure in binding the bookmark column
  97. *pStatus = bmkBindStatus;
  98. }
  99. vqDebugOut(( DEB_ERROR,
  100. "CDistributedAccessor: CreateAccessor for bookmark(child %d) returned 0x%x\n",
  101. iChild, sc ));
  102. // Don't throw here. We want to continue on and find all failures
  103. continue;
  104. }
  105. bindBmk.obValue += bindBmk.cbMaxLen;
  106. }
  107. if (FAILED(scLast))
  108. {
  109. THROW( CException(scLast) );
  110. }
  111. }
  112. CATCH( CException, e )
  113. {
  114. _ReleaseAccessors();
  115. RETHROW();
  116. }
  117. END_CATCH
  118. Win4Assert( SUCCEEDED(sc) );
  119. }
  120. //+---------------------------------------------------------------------------
  121. //
  122. // Member: CDistributedBookmarkAccessor::ReleaseAccessors, private
  123. //
  124. // Synopsis: Release all the bookmark accessors
  125. //
  126. // Arguments: none
  127. //
  128. // History: 28-Sep-98 VikasMan Created.
  129. //
  130. //----------------------------------------------------------------------------
  131. void CDistributedBookmarkAccessor::_ReleaseAccessors()
  132. {
  133. unsigned iChild;
  134. for ( iChild = 0; iChild < _xIacc.Count(); iChild++ )
  135. {
  136. if ( _xIacc[iChild].GetPointer() && _xhaccBookmark[iChild] )
  137. {
  138. _xIacc[iChild]->ReleaseAccessor( _xhaccBookmark[iChild], 0 );
  139. }
  140. }
  141. }
  142. //+---------------------------------------------------------------------------
  143. //
  144. // Member: CDistributedBookmarkAccessor::GetData, public
  145. //
  146. // Synopsis: Fetches the bookmark data
  147. //
  148. // Arguments: [iChild] -- Index of child cursor from which base data is
  149. // to be fetched. Indicates 'current' row in [ahrow].
  150. // [ahrow] -- 'Top' HROW for all cursors. Used for bookmark
  151. // hints.
  152. // [pBookmarkData] -- Value returned here, starting at offset 0
  153. // [cbBookmark] -- Length of bookmark
  154. // [aCursor] -- Child Rowsets
  155. // [cCursor] -- Count of child cursors
  156. // [pStatus] -- GetData Status returned here, if pStatus is not null
  157. //
  158. // Returns: SCODE
  159. //
  160. // History: 28-Sep-98 VikasMan Created.
  161. //
  162. //----------------------------------------------------------------------------
  163. SCODE CDistributedBookmarkAccessor::GetData( unsigned iChild, HROW * ahrow, void * pBookmarkData,
  164. DBBKMARK cbBookmark, IRowset * * const aCursor,
  165. ULONG cCursor, SCODE * pStatus )
  166. {
  167. SCODE sc = S_OK;
  168. RtlFillMemory( pBookmarkData, cbBookmark, 0xFF );
  169. if ( pStatus )
  170. {
  171. *pStatus = DBSTATUS_S_OK;
  172. }
  173. for ( unsigned i = 0; i < cCursor; i++ )
  174. {
  175. SCODE sc2 = S_OK;
  176. if ( ahrow[i] != (HROW)0xFFFFFFFF )
  177. {
  178. sc2 = aCursor[i]->GetData( ahrow[i], GetHAccessor(i), pBookmarkData );
  179. if ( SUCCEEDED(sc2) && pStatus && DBSTATUS_S_OK == *pStatus )
  180. {
  181. *pStatus = *( (SCODE*)pBookmarkData );
  182. }
  183. }
  184. if ( FAILED(sc2) )
  185. {
  186. if ( i == iChild )
  187. {
  188. vqDebugOut(( DEB_ERROR, "CDistributedBookmarkAccessor::GetData: Child GetData returned 0x%x\n", sc ));
  189. sc = sc2;
  190. break;
  191. }
  192. else
  193. {
  194. // This can fail as we can have a invalid row handle for hints
  195. vqDebugOut(( DEB_TRACE, "CDistributedBookmarkAccessor::GetData: Child GetData returned 0x%x\n", sc ));
  196. continue;
  197. }
  198. }
  199. }
  200. *(ULONG UNALIGNED *)(pBookmarkData) = iChild;
  201. return sc;
  202. }