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.

277 lines
7.9 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1995 - 2000.
  5. //
  6. // File: tbrowkey.cxx
  7. //
  8. // Contents:
  9. //
  10. // Classes:
  11. //
  12. // Functions:
  13. //
  14. // History: 2-15-95 srikants Created
  15. //
  16. //----------------------------------------------------------------------------
  17. #include "pch.cxx"
  18. #pragma hdrstop
  19. #include <objcur.hxx>
  20. #include <tableseg.hxx>
  21. CTableRowKey::CTableRowKey( CSortSet const & sortSet )
  22. : _cCols(sortSet.Count()), _sortSet(sortSet),
  23. _acbVariants( _cCols ), _apVariants( _cCols )
  24. {
  25. Win4Assert( sizeof(CInlineVariant) == sizeof(CTableVariant) );
  26. for ( unsigned i = 0; i < _cCols; i++ )
  27. {
  28. _acbVariants[i] = 0;
  29. _apVariants[i] = 0;
  30. }
  31. }
  32. //+---------------------------------------------------------------------------
  33. //
  34. // Method: CTableRowKey ~dtor
  35. //
  36. // Synopsis:
  37. //
  38. // Returns:
  39. //
  40. // Modifies:
  41. //
  42. // History: 2-15-95 srikants Created
  43. //
  44. //----------------------------------------------------------------------------
  45. CTableRowKey::~CTableRowKey()
  46. {
  47. for ( unsigned i = 0; i < _cCols; i++ )
  48. delete [] (BYTE *) _apVariants[i];
  49. }
  50. //+---------------------------------------------------------------------------
  51. //
  52. // Method: CTableRowKey::ReAlloc
  53. //
  54. // Synopsis: Reallocates memory for the indicated column. Note that
  55. // the old contents may be tossed out.
  56. //
  57. // Arguments: [i] - The column for which reallocation is needed.
  58. // [vt] - Variant type of the variant
  59. // [cb] - Number of bytes needed for the variant.
  60. //
  61. // History: 2-15-95 srikants Created
  62. //
  63. //----------------------------------------------------------------------------
  64. void CTableRowKey::ReAlloc( unsigned i, VARTYPE vt, unsigned cb )
  65. {
  66. Win4Assert( i < _cCols );
  67. const ULONG cbHeader = sizeof(CInlineVariant);
  68. ULONG cbTotal = cb;
  69. Win4Assert( cbTotal >= cbHeader );
  70. if ( _acbVariants[i] < cbTotal )
  71. {
  72. delete [] (BYTE *) _apVariants[i];
  73. _apVariants[i] = 0;
  74. _acbVariants[i] = 0;
  75. ULONG cbToAlloc = cbTotal;
  76. _apVariants[i] = (CInlineVariant *) new BYTE [cbToAlloc];
  77. _acbVariants[i] = cbToAlloc;
  78. }
  79. }
  80. //+---------------------------------------------------------------------------
  81. //
  82. // Method: CTableRowKey::Init
  83. //
  84. // Synopsis: Initialized the column "i" with the source variant.
  85. //
  86. // Arguments: [i] - Column to be initialized.
  87. // [src] - Source variant
  88. // [pbSrcBias] - Bais of the data allocation in the source
  89. // variant.
  90. //
  91. // History: 2-15-95 srikants Created
  92. //
  93. //----------------------------------------------------------------------------
  94. void CTableRowKey::Init( unsigned i, CTableVariant & src, BYTE * pbSrcBias )
  95. {
  96. Win4Assert( i < _cCols );
  97. const ULONG cbHeader = sizeof(CInlineVariant);
  98. ULONG cbVarData = src.VarDataSize();
  99. ULONG cbTotal = cbVarData + cbHeader;
  100. if ( _acbVariants[i] < cbTotal )
  101. ReAlloc( i, src.vt, cbTotal );
  102. Win4Assert( _acbVariants[i] >= cbTotal );
  103. Win4Assert( _acbVariants[i]-cbHeader >= cbVarData );
  104. CVarBufferAllocator bufAlloc( _apVariants[i]->GetVarBuffer(), cbVarData );
  105. bufAlloc.SetBase(0);
  106. src.Copy( _apVariants[i], bufAlloc, (USHORT) cbVarData, pbSrcBias );
  107. }
  108. //+---------------------------------------------------------------------------
  109. //
  110. // Function: assignemnt operator
  111. //
  112. // Synopsis: Copies the contents of the source bucket row into this.
  113. //
  114. // Arguments: [src] - The source bucket row.
  115. //
  116. // Returns: A reference to this bucket row.
  117. //
  118. // History: 2-15-95 srikants Created
  119. //
  120. //----------------------------------------------------------------------------
  121. CTableRowKey & CTableRowKey::operator=( CTableRowKey & src )
  122. {
  123. Win4Assert( src._cCols == _cCols );
  124. for ( unsigned i = 0; i < _cCols; i++ )
  125. Init( i, *(src._apVariants[i]) );
  126. return *this;
  127. }
  128. //+---------------------------------------------------------------------------
  129. //
  130. // Method: CTableRowKey::PreSet
  131. //
  132. // Synopsis: Get ready for use later.
  133. //
  134. // Arguments: [pObj] - value retriever for the object
  135. // [pInfoSortKey] - sort info
  136. //
  137. // History: 8-20-98 dlee Created
  138. //
  139. //----------------------------------------------------------------------------
  140. void CTableRowKey::PreSet(
  141. CRetriever * pObj,
  142. XArray<VARTYPE> * pInfoSortKey )
  143. {
  144. _pObj = pObj;
  145. _pVarType = pInfoSortKey;
  146. } //PreSet
  147. //+---------------------------------------------------------------------------
  148. //
  149. // Method: CTableRowKey::MakeReady
  150. //
  151. // Synopsis: Retrieves the sort key values
  152. //
  153. // History: 8-20-98 dlee Created
  154. //
  155. //----------------------------------------------------------------------------
  156. void CTableRowKey::MakeReady()
  157. {
  158. Set( *_pObj, *_pVarType );
  159. } //MakeReady
  160. //+---------------------------------------------------------------------------
  161. //
  162. // Method: CTableRowKey::Set
  163. //
  164. // Synopsis: Given a "row" and the "obj" for a row, it
  165. // fills the "row" with the data from the "obj". It retrieves
  166. // only the columns in the sort key.
  167. //
  168. // Arguments: [row] - The row to fill
  169. // [obj] - Retriever for the columns.
  170. //
  171. // History: 2-15-95 srikants Created
  172. //
  173. //----------------------------------------------------------------------------
  174. void CTableRowKey::Set( CRetriever & obj, XArray<VARTYPE> & vtInfoSortKey )
  175. {
  176. Win4Assert( _sortSet.Count() == _cCols );
  177. for ( ULONG i = 0; i < _cCols; i++ )
  178. {
  179. SSortKey & key = _sortSet.Get(i);
  180. PROPID pid = key.pidColumn;
  181. ULONG cbVarnt;
  182. CTableVariant * pvarnt = Get(i, cbVarnt);
  183. GetValueResult eGvr;
  184. VARTYPE vt = vtInfoSortKey.Get()[i];
  185. if ( 0 == pvarnt )
  186. {
  187. //
  188. // This is the first time we are setting the value of this
  189. // variant. Determine its type and allocate the optimum amount
  190. // of memory.
  191. //
  192. CTableVariant varnt;
  193. cbVarnt = sizeof(varnt);
  194. pvarnt = &varnt;
  195. eGvr = obj.GetPropertyValue( pid, pvarnt, &cbVarnt );
  196. if ( GVRSuccess != eGvr &&
  197. GVRNotEnoughSpace != eGvr &&
  198. GVRSharingViolation != eGvr )
  199. {
  200. if ( eGvr == GVRNotSupported || eGvr == GVRNotAvailable )
  201. {
  202. THROW( CException( QUERY_E_INVALIDSORT ) );
  203. }
  204. else
  205. {
  206. THROW( CException(CRetriever::NtStatusFromGVR(eGvr)) );
  207. }
  208. }
  209. if ( ( GVRSharingViolation == eGvr ) ||
  210. ( 0 == cbVarnt ) )
  211. cbVarnt = sizeof varnt;
  212. ReAlloc( i, vt, cbVarnt );
  213. pvarnt = Get( i, cbVarnt );
  214. }
  215. Win4Assert( 0 != pvarnt );
  216. eGvr = obj.GetPropertyValue( pid, pvarnt, &cbVarnt );
  217. if ( GVRNotEnoughSpace == eGvr )
  218. {
  219. //
  220. // This path should be executed very rarely because for strings
  221. // we over-allocate the memory and for "fixed" length variants
  222. // the correct length must have been allocated the first time.
  223. //
  224. ReAlloc( i, vt, cbVarnt );
  225. pvarnt = Get( i, cbVarnt );
  226. eGvr = obj.GetPropertyValue( pid, pvarnt, &cbVarnt );
  227. }
  228. if ( GVRSharingViolation == eGvr )
  229. pvarnt->vt = VT_EMPTY;
  230. else if ( GVRSuccess != eGvr )
  231. THROW( CException(CRetriever::NtStatusFromGVR(eGvr)) );
  232. }
  233. } //Set