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.

672 lines
22 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1994 - 1999.
  5. //
  6. // File: query.hxx
  7. //
  8. // Contents: Declarations of classes which implement IRowset and
  9. // related OLE DB interfaces over file stores.
  10. //
  11. // Classes: PQuery - abstract base class
  12. // CAsyncQuery - container of table/query for a set of cursors
  13. // CSvcQueryProxy - Proxy to PQuery for the CI Service
  14. //
  15. // History: 31 May 94 AlanW Created
  16. //
  17. //----------------------------------------------------------------------------
  18. #pragma once
  19. #include <querydef.hxx>
  20. #include <dbgproxy.hxx>
  21. #include <proxymsg.hxx>
  22. #include <bigtable.hxx>
  23. #include <execute.hxx>
  24. #include <coldesc.hxx>
  25. #include <pidremap.hxx>
  26. #include <tablecol.hxx>
  27. #include <tablecur.hxx>
  28. #include <categ.hxx>
  29. #include <querydef.hxx>
  30. #include <crequest.hxx>
  31. #include <rstprop.hxx>
  32. const CI_TBL_CHAPT chaptInvalid = 0xffffffff;
  33. class PVarAllocator;
  34. class PFixedVarAllocator;
  35. class CRowSeekDescription;
  36. //+-------------------------------------------------------------------------
  37. //
  38. // Class: CGetRowsParams
  39. //
  40. // Purpose: Bundles the parameters for a GetRows call.
  41. //
  42. // History: 3 Sep 99 KLam Added ReplyBase
  43. //
  44. //--------------------------------------------------------------------------
  45. class CGetRowsParams
  46. {
  47. public:
  48. CGetRowsParams( ULONG cRows,
  49. BOOL fFwdFetch,
  50. ULONG cbRowWidth,
  51. PFixedVarAllocator & rAlloc) :
  52. _cRowsRequested( cRows ),
  53. _fFwdFetch( fFwdFetch ),
  54. _cbRowWidth( cbRowWidth ),
  55. _pData( 0 ),
  56. _cRowsReturned( 0 ),
  57. _rAllocator( rAlloc ),
  58. _pbReplyBase ( 0 ) { }
  59. PBYTE GetRowBuffer( );
  60. size_t GetRowWidth( ) const
  61. // NOTE: _rAllocator.FixedWidth() may differ
  62. // for GetRowsInfo case.
  63. { return _cbRowWidth; }
  64. PVarAllocator& GetVarAllocator( ) {
  65. return (PVarAllocator &) _rAllocator;
  66. }
  67. PFixedVarAllocator& GetFixedVarAllocator( ) {
  68. return _rAllocator;
  69. }
  70. void SetRowsRequested( ULONG cRows ) {
  71. Win4Assert(_cRowsReturned == 0);
  72. _cRowsRequested = cRows;
  73. }
  74. void IncrementRowsRequested( ) {
  75. _cRowsRequested++;
  76. Win4Assert(_cRowsReturned <= _cRowsRequested);
  77. _pData = 0;
  78. }
  79. void SetRowsTransferred( ULONG cRows ) {
  80. Win4Assert(_cRowsReturned == 0);
  81. _cRowsReturned = cRows;
  82. }
  83. void IncrementRowCount( ) {
  84. _cRowsReturned++;
  85. Win4Assert(_cRowsReturned <= _cRowsRequested);
  86. _pData = 0;
  87. }
  88. unsigned RowsTransferred( ) const
  89. { return _cRowsReturned; }
  90. unsigned RowsToTransfer( ) const
  91. { return _cRowsRequested - _cRowsReturned; }
  92. PBYTE GetBuffer( ) const;
  93. BOOL GetFwdFetch() { return _fFwdFetch; }
  94. BYTE * GetReplyBase () const { return _pbReplyBase; }
  95. void SetReplyBase ( BYTE * pbReplyBase ) { _pbReplyBase = pbReplyBase; }
  96. private:
  97. ULONG _cRowsRequested; // number of rows to transfer
  98. ULONG _cRowsReturned; // number of rows transferred
  99. PFixedVarAllocator & _rAllocator; // allocator for row and indirect data
  100. ULONG _cbRowWidth; // size of a row in the row buffer
  101. void * _pData; // pointer to current row data buffer
  102. BOOL _fFwdFetch; // True if rows are to be fetched in
  103. // forward direction
  104. BYTE * _pbReplyBase; // pointer to base of reply
  105. // only needed for Win64Client->Win32Server
  106. };
  107. //+---------------------------------------------------------------------------
  108. //
  109. // Class: PQuery
  110. //
  111. // Purpose: Abstract base class for CAsyncQuery, CSeqQuery and
  112. // CSvcQueryProxy. Abstracts the operations needed by CRowset.
  113. //
  114. // History: 26 Aug 1994 AlanW Created
  115. // 27 Jan 1995 Alanw Rearranged methods for ole-db phase 3
  116. //
  117. // Notes:
  118. //
  119. //----------------------------------------------------------------------------
  120. class __declspec(novtable) PQuery
  121. {
  122. public:
  123. PQuery( void ) { }
  124. virtual ~PQuery() { }
  125. virtual ULONG AddRef(void) = 0;
  126. virtual ULONG Release(void) = 0;
  127. virtual void WorkIdToPath( WORKID wid, CFunnyPath & funnyPath ) = 0;
  128. virtual BOOL CanDoWorkIdToPath() = 0;
  129. //
  130. // Methods supporting IRowset
  131. //
  132. virtual void SetBindings(
  133. ULONG hCursor,
  134. ULONG cbRowLength,
  135. CTableColumnSet& cols,
  136. CPidMapper & pids) = 0;
  137. virtual SCODE GetRows(
  138. ULONG hCursor,
  139. const CRowSeekDescription& rSeekDesc,
  140. CGetRowsParams& rRowsParams,
  141. XPtr<CRowSeekDescription>& pSeekDescOut) = 0;
  142. virtual void RatioFinished(
  143. ULONG hCursor,
  144. DBCOUNTITEM & rulDenominator,
  145. DBCOUNTITEM & rulNumerator,
  146. DBCOUNTITEM & rcRows,
  147. BOOL & rfNewRows ) = 0;
  148. virtual SCODE RatioFinished(
  149. CNotificationSync & rSync,
  150. ULONG hCursor,
  151. DBCOUNTITEM & rulDenominator,
  152. DBCOUNTITEM & rulNumerator,
  153. DBCOUNTITEM & rcRows,
  154. BOOL & rfNewRows )
  155. {
  156. RatioFinished(hCursor, rulDenominator, rulNumerator,
  157. rcRows, rfNewRows );
  158. return S_OK;
  159. }
  160. virtual void RestartPosition(
  161. ULONG hCursor,
  162. CI_TBL_CHAPT chapt ) = 0;
  163. //
  164. // Methods supporting IRowsetLocate
  165. //
  166. virtual void Compare(
  167. ULONG hCursor,
  168. CI_TBL_CHAPT chapt,
  169. CI_TBL_BMK bmkFirst,
  170. CI_TBL_BMK bmkSecond,
  171. DWORD & rdwComparison) = 0;
  172. //
  173. // Methods supporting IRowsetScroll
  174. //
  175. virtual void GetApproximatePosition(
  176. ULONG hCursor,
  177. CI_TBL_CHAPT chapt,
  178. CI_TBL_BMK bmk,
  179. DBCOUNTITEM * pulNumerator,
  180. DBCOUNTITEM * pulDenominator) = 0;
  181. //
  182. // Support routines
  183. //
  184. virtual unsigned FreeCursor(ULONG hCursor) = 0;
  185. virtual SCODE GetNotifications(
  186. CNotificationSync &rSync,
  187. DBWATCHNOTIFY &changeType) = 0;
  188. //
  189. // IRowsetWatchRegion methods
  190. //
  191. virtual void SetWatchMode (
  192. HWATCHREGION* phRegion,
  193. ULONG mode) = 0;
  194. virtual void GetWatchInfo (
  195. HWATCHREGION hRegion,
  196. ULONG* pMode,
  197. CI_TBL_CHAPT* pChapt,
  198. CI_TBL_BMK* pBmk,
  199. DBCOUNTITEM* pcRows) = 0;
  200. virtual void ShrinkWatchRegion (
  201. HWATCHREGION hRegion,
  202. CI_TBL_CHAPT chapt,
  203. CI_TBL_BMK bmk,
  204. LONG cRows ) = 0;
  205. virtual void Refresh () = 0;
  206. //
  207. // Methods supporting IRowsetWatchAll
  208. //
  209. virtual void StartWatching(
  210. ULONG hCursor) = 0;
  211. virtual void StopWatching ( // Stop method (Stop already used by IRowsetAsync)
  212. ULONG hCursor) = 0;
  213. //
  214. // Methods supporting IRowsetAsync
  215. //
  216. virtual void StopAsynch (ULONG hCursor) = 0;
  217. //
  218. // Method supporting IRowsetQueryStatus
  219. //
  220. virtual void GetQueryStatus(
  221. ULONG hCursor,
  222. DWORD & rdwStatus) = 0;
  223. virtual void GetQueryStatusEx(
  224. ULONG hCursor,
  225. DWORD & rdwStatus,
  226. DWORD & rcFilteredDocuments,
  227. DWORD & rcDocumentsToFilter,
  228. DBCOUNTITEM & rdwRatioFinishedDenominator,
  229. DBCOUNTITEM & rdwRatioFinishedNumerator,
  230. CI_TBL_BMK bmk,
  231. DBCOUNTITEM & riRowBmk,
  232. DBCOUNTITEM & rcRowsTotal ) = 0;
  233. //
  234. // Method supporting load of deferred values.
  235. //
  236. virtual BOOL FetchDeferredValue( WORKID wid,
  237. CFullPropSpec const & ps,
  238. PROPVARIANT & var ) = 0;
  239. };
  240. class CRequestServer;
  241. //+---------------------------------------------------------------------------
  242. //
  243. // Class: CAsyncQuery
  244. //
  245. // Purpose: Encapsulates a query execution context, PID mapper
  246. // and large table for use by a row cursor.
  247. //
  248. // Interface: PQuery
  249. //
  250. // History: 02 Jun 94 AlanW Created
  251. //
  252. // Notes:
  253. //
  254. //----------------------------------------------------------------------------
  255. class CAsyncQuery : public PQuery
  256. {
  257. public:
  258. //
  259. // Local methods.
  260. //
  261. CAsyncQuery( XQueryOptimizer & qopt,
  262. XColumnSet & pcol,
  263. XSortSet & sort,
  264. XCategorizationSet &categ,
  265. unsigned cCursors,
  266. ULONG * aCursors,
  267. XInterface<CPidRemapper> & pidremap,
  268. BOOL fEnableNotification,
  269. ICiCDocStore *pDocStore,
  270. CRequestServer * pQuiesce );
  271. virtual ~CAsyncQuery();
  272. ULONG AddRef(void);
  273. ULONG Release(void);
  274. void WorkIdToPath( WORKID wid, CFunnyPath & funnyPath );
  275. BOOL CanDoWorkIdToPath();
  276. //
  277. // Methods supporting IRowset
  278. //
  279. void SetBindings(
  280. ULONG hCursor,
  281. ULONG cbRowLength,
  282. CTableColumnSet& cols,
  283. CPidMapper & pids
  284. );
  285. SCODE GetRows(
  286. ULONG hCursor,
  287. const CRowSeekDescription& crSeekDesc,
  288. CGetRowsParams& rRowsParams,
  289. XPtr<CRowSeekDescription>& pSeekDescOut
  290. );
  291. void RatioFinished(
  292. ULONG hCursor,
  293. DBCOUNTITEM & rulDenominator,
  294. DBCOUNTITEM & rulNumerator,
  295. DBCOUNTITEM & rcRows,
  296. BOOL & rfNewRows
  297. );
  298. void RestartPosition(
  299. ULONG hCursor,
  300. CI_TBL_CHAPT chapt
  301. );
  302. //
  303. // Methods supporting IRowsetLocate
  304. //
  305. void Compare(
  306. ULONG hCursor,
  307. CI_TBL_CHAPT chapt,
  308. CI_TBL_BMK bmkFirst,
  309. CI_TBL_BMK bmkSecond,
  310. DWORD & rdwComparison
  311. );
  312. //
  313. // Methods supporting IRowsetScroll
  314. //
  315. void GetApproximatePosition(
  316. ULONG hCursor,
  317. CI_TBL_CHAPT chapt,
  318. CI_TBL_BMK bmk,
  319. DBCOUNTITEM * pulNumerator,
  320. DBCOUNTITEM * pulDenominator
  321. );
  322. //
  323. // Support routines
  324. //
  325. unsigned FreeCursor(ULONG hCursor);
  326. SCODE GetNotifications(
  327. CNotificationSync &rSync,
  328. DBWATCHNOTIFY &changeType);
  329. //
  330. // Methods supporting IRowsetWatchRegion
  331. //
  332. void SetWatchMode (
  333. HWATCHREGION * phRegion,
  334. ULONG mode);
  335. void GetWatchInfo (
  336. HWATCHREGION hRegion,
  337. ULONG* pMode,
  338. CI_TBL_CHAPT* pChapt,
  339. CI_TBL_BMK* pBmk,
  340. DBCOUNTITEM* pcRows);
  341. void ShrinkWatchRegion (
  342. HWATCHREGION hRegion,
  343. CI_TBL_CHAPT chapt,
  344. CI_TBL_BMK bmk,
  345. LONG cRows );
  346. void Refresh ();
  347. //
  348. // Methods supporting IRowsetWatchAll
  349. //
  350. void StartWatching(ULONG hCursor)
  351. {
  352. THROW(CException( E_NOTIMPL ));
  353. }
  354. void StopWatching (ULONG hCursor)
  355. {
  356. THROW(CException( E_NOTIMPL ));
  357. }
  358. //
  359. // Methods supporting IRowsetAsync
  360. //
  361. void StopAsynch (ULONG hCursor)
  362. {
  363. THROW(CException( E_NOTIMPL ));
  364. }
  365. //
  366. // Method supporting IRowsetQueryStatus
  367. //
  368. void GetQueryStatus(
  369. ULONG hCursor,
  370. DWORD & rdwStatus);
  371. void GetQueryStatusEx(
  372. ULONG hCursor,
  373. DWORD & rdwStatus,
  374. DWORD & rcFilteredDocuments,
  375. DWORD & rcDocumentsToFilter,
  376. DBCOUNTITEM & rdwRatioFinishedDenominator,
  377. DBCOUNTITEM & rdwRatioFinishedNumerator,
  378. CI_TBL_BMK bmk,
  379. DBCOUNTITEM & riRowBmk,
  380. DBCOUNTITEM & rcRowsTotal );
  381. //
  382. // Method supporting load of deferred values.
  383. //
  384. BOOL FetchDeferredValue( WORKID wid,
  385. CFullPropSpec const & ps,
  386. PROPVARIANT & var );
  387. private:
  388. ULONG _CreateRowCursor();
  389. LONG _ref; // reference count
  390. BOOL _fCanDoWorkidToPath; // TRUE if paths are cached.
  391. CMutexSem _mutex; // Serialize access to tables
  392. XInterface<CPidRemapper> _pidremap; // Pid remapper for props. in query
  393. CLargeTable _Table; // The cached table
  394. CTableCursorSet _aCursors; // Array of table cursors
  395. DBCOUNTITEM _cRowsLastAsked; // for RatioFinished
  396. CDynArray<CCategorize> _aCategorize; // array of categorization objects
  397. XInterface<ICiManager> _xCiManager;
  398. XInterface<ICiCDocNameToWorkidTranslator> _xNameToWidTranslator;
  399. XQAsyncExecute _QExec; // The query execution context
  400. // WARNING: don't put any more embedded objects after the XQAsyncExecute
  401. // if you are concerned that they be around if a notification
  402. // arrives while CAsyncQuery is being destroyed!
  403. };
  404. //+---------------------------------------------------------------------------
  405. //
  406. // Class: CSvcQueryProxy
  407. //
  408. // Purpose: Proxy to the PQuery class in the Svc driver.
  409. //
  410. // Interface: PQuery
  411. //
  412. // History: 26 Aug 94 AlanW Created
  413. // 13 Sep 96 dlee Converted to cisvc
  414. //
  415. //----------------------------------------------------------------------------
  416. class CSvcQueryProxy : public PQuery
  417. {
  418. public:
  419. // Local methods.
  420. CSvcQueryProxy( CRequestClient & client,
  421. CColumnSet const & col,
  422. CRestriction const & rst,
  423. CSortSet const * pso,
  424. CCategorizationSet const * pcateg,
  425. CRowsetProperties const & RstProp,
  426. CPidMapper const & pidmap ,
  427. ULONG cCursors,
  428. ULONG * aCursors );
  429. ULONG AddRef(void);
  430. ULONG Release(void);
  431. void WorkIdToPath(
  432. WORKID wid,
  433. CFunnyPath & funnyPath );
  434. // Methods supporting IRowset
  435. void SetBindings(
  436. ULONG hCursor,
  437. ULONG cbRowLength,
  438. CTableColumnSet & cols,
  439. CPidMapper & pids );
  440. SCODE GetRows(
  441. ULONG hCursor,
  442. const CRowSeekDescription & rSeekDesc,
  443. CGetRowsParams& rRowsParams,
  444. XPtr<CRowSeekDescription> & pSeekDescOut );
  445. void RatioFinished(
  446. ULONG hCursor,
  447. DBCOUNTITEM & rulDenominator,
  448. DBCOUNTITEM & rulNumerator,
  449. DBCOUNTITEM & rcRows,
  450. BOOL & rfNewRows );
  451. SCODE RatioFinished(
  452. CNotificationSync & rSync,
  453. ULONG hCursor,
  454. DBCOUNTITEM & rulDenominator,
  455. DBCOUNTITEM & rulNumerator,
  456. DBCOUNTITEM & rcRows,
  457. BOOL & rfNewRows );
  458. void RestartPosition(
  459. ULONG hCursor,
  460. CI_TBL_CHAPT chapt );
  461. // Methods supporting IRowsetLocate
  462. void Compare(
  463. ULONG hCursor,
  464. CI_TBL_CHAPT chapt,
  465. CI_TBL_BMK bmkFirst,
  466. CI_TBL_BMK bmkSecond,
  467. DWORD & rdwComparison );
  468. // Methods supporting IRowsetScroll
  469. void GetApproximatePosition(
  470. ULONG hCursor,
  471. CI_TBL_CHAPT chapt,
  472. CI_TBL_BMK bmk,
  473. DBCOUNTITEM * pulNumerator,
  474. DBCOUNTITEM * pulDenominator );
  475. // Support routines
  476. unsigned FreeCursor(
  477. ULONG hCursor );
  478. SCODE GetNotifications(
  479. CNotificationSync & rSync,
  480. DBWATCHNOTIFY & changeType );
  481. // IRowsetWatchRegion methods
  482. void SetWatchMode(
  483. HWATCHREGION * phRegion,
  484. ULONG mode );
  485. void GetWatchInfo(
  486. HWATCHREGION hRegion,
  487. ULONG * pMode,
  488. CI_TBL_CHAPT * pChapt,
  489. CI_TBL_BMK * pBmk,
  490. DBCOUNTITEM * pcRows );
  491. void ShrinkWatchRegion (
  492. HWATCHREGION hRegion,
  493. CI_TBL_CHAPT chapt,
  494. CI_TBL_BMK bmk,
  495. LONG cRows );
  496. void Refresh();
  497. //
  498. // Methods supporting IRowsetWatchAll
  499. //
  500. void StartWatching(ULONG hCursor);
  501. void StopWatching (ULONG hCursor);
  502. //
  503. // Methods supporting IRowsetAsync
  504. //
  505. void StopAsynch (ULONG hCursor);
  506. // Method supporting IRowsetQueryStatus
  507. void GetQueryStatus(
  508. ULONG hCursor,
  509. DWORD & rdwStatus );
  510. void GetQueryStatusEx(
  511. ULONG hCursor,
  512. DWORD & rdwStatus,
  513. DWORD & rcFilteredDocuments,
  514. DWORD & rcDocumentsToFilter,
  515. DBCOUNTITEM & rdwRatioFinishedDenominator,
  516. DBCOUNTITEM & rdwRatioFinishedNumerator,
  517. CI_TBL_BMK bmk,
  518. DBCOUNTITEM & riRowBmk,
  519. DBCOUNTITEM & rcRowsTotal );
  520. BOOL FetchDeferredValue(
  521. WORKID wid,
  522. CFullPropSpec const & ps,
  523. PROPVARIANT & var );
  524. BOOL CanDoWorkIdToPath() { return _fWorkIdUnique ||
  525. !_fTrueSequential; }
  526. private:
  527. ~CSvcQueryProxy();
  528. void ReExecuteSequentialQuery( );
  529. CRequestClient & _client; // handles communication with cisvc
  530. long _ref; // reference count
  531. BOOL _fTrueSequential; // TRUE if a CSeqQuery
  532. BOOL _fWorkIdUnique; // TRUE if wid is backed by a catalog,
  533. // not by a fake wid in bigtable
  534. ULONG_PTR _ulServerCookie; // CRequestServer in cisvc
  535. CMutexSem _mutexFetchValue; // Serialize access to FetchValue
  536. XArray<BYTE> _xQuery; // binary stream for CreateQuery (cache for RestartPosition)
  537. XArray<BYTE> _xBindings; // binary stream for SetBindings (cache for RestartPosition)
  538. XArray<ULONG> _aCursors; // cursors (cache for RestartPosition)
  539. };