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.

2417 lines
60 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 2000.
  5. //
  6. // File: dbcmdbas.cxx
  7. //
  8. // Contents: Wrapper classes for DBCOMMANDTREE
  9. //
  10. // Classes: CDbCmdTreeNode
  11. // CDbColumnNode
  12. //
  13. // History: 6-06-95 srikants Created
  14. //
  15. //----------------------------------------------------------------------------
  16. #include <pch.cxx>
  17. #pragma hdrstop
  18. #include <sstream.hxx>
  19. const GUID CDbCmdTreeNode::guidNull = DB_NULLGUID;
  20. inline BOOL IsNotImplemented( WORD wKind )
  21. {
  22. return (wKind & DBVALUEKIND_VECTOR) || (wKind & DBVALUEKIND_ARRAY);
  23. }
  24. //+---------------------------------------------------------------------------
  25. //
  26. // Method: CDbCmdTreeNode::PutWString, static public
  27. //
  28. // Synopsis: Marshal a wide charater string.
  29. //
  30. // Arguments: [stm] - Serialization stream
  31. // [pwszStr] - String to be serialized
  32. //
  33. // Returns: -NOTHING-
  34. //
  35. // History: 6-21-95 srikants Created
  36. //
  37. // Notes:
  38. //
  39. //----------------------------------------------------------------------------
  40. void CDbCmdTreeNode::PutWString( PSerStream & stm,
  41. WCHAR const * pwszStr )
  42. {
  43. ULONG cwc = (0 != pwszStr) ? wcslen( pwszStr ) : 0;
  44. stm.PutULong( cwc );
  45. if (cwc)
  46. stm.PutWChar( pwszStr, cwc );
  47. }
  48. //+---------------------------------------------------------------------------
  49. //
  50. // Method: CDbCmdTreeNode::GetWString, static public
  51. //
  52. // Synopsis: Unmarshal a wide character string.
  53. //
  54. // Arguments: [stm] - Deserialization stream
  55. // [fSuccess] - On return, TRUE if string allocation was successful
  56. // [fBstr] - TRUE if output string should be a BSTR
  57. //
  58. // Returns: WCHAR * - output string, can be null.
  59. //
  60. // History: 6-21-95 srikants Created
  61. //
  62. // Notes:
  63. //
  64. //----------------------------------------------------------------------------
  65. WCHAR * CDbCmdTreeNode::GetWString( PDeSerStream & stm,
  66. BOOL & fSuccess,
  67. BOOL fBstr )
  68. {
  69. ULONG cwc = stm.GetULong();
  70. // Guard against attack
  71. if ( cwc >= 65536 )
  72. {
  73. fSuccess = FALSE;
  74. return 0;
  75. }
  76. fSuccess = TRUE;
  77. if ( 0 == cwc )
  78. {
  79. return 0;
  80. }
  81. WCHAR * pwszStr = 0;
  82. if (fBstr)
  83. {
  84. pwszStr = (WCHAR *)SysAllocStringLen( L"", cwc );
  85. }
  86. else
  87. {
  88. ULONG cb = (cwc+1) * sizeof(WCHAR);
  89. pwszStr = (WCHAR *) CoTaskMemAlloc( cb );
  90. }
  91. if ( 0 == pwszStr )
  92. {
  93. fSuccess = FALSE;
  94. return 0;
  95. }
  96. stm.GetWChar( pwszStr, cwc );
  97. pwszStr[cwc] = L'\0';
  98. return pwszStr;
  99. }
  100. //+---------------------------------------------------------------------------
  101. //
  102. // Method: CDbCmdTreeNode::AllocAndCopyWString, static public
  103. //
  104. // Synopsis:
  105. //
  106. // Arguments: [pSrc] -
  107. //
  108. // Returns:
  109. //
  110. // History: 6-22-95 srikants Created
  111. //
  112. // Notes:
  113. //
  114. //----------------------------------------------------------------------------
  115. WCHAR * CDbCmdTreeNode::AllocAndCopyWString( const WCHAR * pSrc )
  116. {
  117. WCHAR * pDst = 0;
  118. if ( 0 != pSrc )
  119. {
  120. const cb = ( wcslen( pSrc ) + 1 ) * sizeof(WCHAR);
  121. pDst = (WCHAR *) CoTaskMemAlloc( cb );
  122. if ( 0 != pDst )
  123. {
  124. RtlCopyMemory( pDst, pSrc, cb );
  125. }
  126. }
  127. return pDst;
  128. }
  129. //+---------------------------------------------------------------------------
  130. //
  131. // Method: CDbCmdTreeNode::UnMarshallTree, static public
  132. //
  133. // Synopsis:
  134. //
  135. // Arguments: [stm] -
  136. //
  137. // Returns:
  138. //
  139. // History: 6-21-95 srikants Created
  140. //
  141. // Notes:
  142. //
  143. //----------------------------------------------------------------------------
  144. CDbCmdTreeNode * CDbCmdTreeNode::UnMarshallTree( PDeSerStream & stm )
  145. {
  146. CDbCmdTreeNode * pRoot = new CDbCmdTreeNode();
  147. if ( 0 != pRoot )
  148. {
  149. if ( !pRoot->UnMarshall(stm) )
  150. {
  151. delete pRoot;
  152. pRoot = 0;
  153. }
  154. }
  155. return pRoot;
  156. }
  157. void CDbCmdTreeNode::CleanupDataValue()
  158. {
  159. if ( IsNotImplemented(wKind) )
  160. {
  161. Win4Assert( !"Type Not Implemented" );
  162. return;
  163. }
  164. void * pMemToFree = 0;
  165. //
  166. // Deallocate any memory allocated for this node.
  167. //
  168. switch ( wKind )
  169. {
  170. case DBVALUEKIND_EMPTY:
  171. break;
  172. case DBVALUEKIND_WSTR:
  173. pMemToFree = (void *) value.pwszValue;
  174. break;
  175. case DBVALUEKIND_BSTR:
  176. SysFreeString( (BSTR)value.pbstrValue );
  177. break;
  178. case DBVALUEKIND_COMMAND:
  179. if ( 0 != value.pCommand )
  180. {
  181. value.pCommand->Release();
  182. }
  183. break;
  184. case DBVALUEKIND_IDISPATCH:
  185. if ( 0 != value.pDispatch )
  186. {
  187. value.pDispatch->Release();
  188. }
  189. break;
  190. case DBVALUEKIND_MONIKER:
  191. if ( 0 != value.pMoniker )
  192. {
  193. value.pMoniker->Release();
  194. }
  195. break;
  196. case DBVALUEKIND_ROWSET:
  197. if ( 0 != value.pRowset )
  198. {
  199. value.pRowset->Release();
  200. }
  201. break;
  202. case DBVALUEKIND_IUNKNOWN:
  203. if ( 0 != value.pUnknown )
  204. {
  205. value.pUnknown->Release();
  206. }
  207. break;
  208. case DBVALUEKIND_BYGUID:
  209. if ( 0 != value.pdbbygdValue )
  210. {
  211. delete ((CDbByGuid *) value.pdbbygdValue);
  212. }
  213. break;
  214. case DBVALUEKIND_LIKE:
  215. if ( 0 != value.pdblikeValue )
  216. {
  217. delete ((CDbLike *) value.pdblikeValue);
  218. }
  219. break;
  220. case DBVALUEKIND_COLDESC:
  221. Win4Assert(! "DBVALUEKIND_COLDESC unsupported !");
  222. break;
  223. case DBVALUEKIND_ID:
  224. if ( 0 != value.pdbidValue )
  225. {
  226. delete ((CDbColId *) value.pdbidValue);
  227. }
  228. break;
  229. case DBVALUEKIND_CONTENT:
  230. if ( 0 != value.pdbcntntValue )
  231. {
  232. delete ((CDbContent *) value.pdbcntntValue);
  233. }
  234. break;
  235. case DBVALUEKIND_CONTENTPROXIMITY:
  236. if ( 0 != value.pdbcntntproxValue )
  237. {
  238. delete ((CDbContentProximity *) value.pdbcntntproxValue);
  239. }
  240. break;
  241. case DBVALUEKIND_CONTENTSCOPE:
  242. if ( 0 != value.pdbcntntscpValue )
  243. {
  244. delete ((CDbContentScope *) value.pdbcntntscpValue);
  245. }
  246. break;
  247. case DBVALUEKIND_CONTENTTABLE:
  248. if ( 0 != value.pdbcntnttblValue )
  249. {
  250. delete ((CDbContentTable *) value.pdbcntnttblValue);
  251. }
  252. break;
  253. case DBVALUEKIND_CONTENTVECTOR:
  254. if ( 0 != value.pdbcntntvcValue )
  255. {
  256. delete ((CDbContentVector *) value.pdbcntntvcValue );
  257. }
  258. break;
  259. case DBVALUEKIND_GROUPINFO:
  260. if ( 0 != value.pdbgrpinfValue )
  261. {
  262. Win4Assert( !"NYI - DBVALUEKIND_GROUPINFO" );
  263. delete ((CDbGroupInfo *) value.pdbgrpinfValue );
  264. }
  265. break;
  266. case DBVALUEKIND_PARAMETER:
  267. if ( 0 != value.pdbparamValue )
  268. {
  269. Win4Assert( !"NYI - DBVALUEKIND_PARAMETER" );
  270. delete ((CDbParameter *) value.pdbparamValue );
  271. }
  272. break;
  273. case DBVALUEKIND_PROPERTY:
  274. if ( 0 != value.pdbpropValue )
  275. {
  276. Win4Assert( !"NYI - DBVALUEKIND_PROPERTY" );
  277. delete ((CDbPropSet *) value.pdbpropValue);
  278. }
  279. break;
  280. case DBVALUEKIND_SETFUNC:
  281. if ( 0 != value.pdbstfncValue )
  282. {
  283. Win4Assert( !"NYI - DBVALUEKIND_SETFUNC" );
  284. // delete ((CDbSetFunc *) value.pdbstfncValue);
  285. }
  286. break;
  287. case DBVALUEKIND_SORTINFO:
  288. if ( 0 != value.pdbsrtinfValue )
  289. {
  290. delete ((CDbSortInfo *) value.pdbsrtinfValue);
  291. }
  292. break;
  293. case DBVALUEKIND_TEXT:
  294. if ( 0 != value.pdbtxtValue )
  295. {
  296. Win4Assert( !"NYI - DBVALUEKIND_TEXT" );
  297. delete ((CDbText *) value.pdbtxtValue );
  298. }
  299. break;
  300. case DBVALUEKIND_VARIANT:
  301. if ( 0 != value.pvarValue )
  302. {
  303. CStorageVariant * pVarnt = CastToStorageVariant( *value.pvarValue );
  304. delete pVarnt;
  305. }
  306. break;
  307. case DBVALUEKIND_GUID:
  308. pMemToFree = (void *) value.pGuid;
  309. break;
  310. case DBVALUEKIND_BYTES:
  311. pMemToFree = (void *) value.pbValue;
  312. break;
  313. case DBVALUEKIND_STR:
  314. pMemToFree = (void *) value.pzValue;
  315. break;
  316. case DBVALUEKIND_NUMERIC:
  317. delete ((CDbNumeric *) value.pdbnValue );
  318. break;
  319. #if CIDBG==1
  320. case DBVALUEKIND_BOOL:
  321. case DBVALUEKIND_UI1:
  322. case DBVALUEKIND_I1:
  323. case DBVALUEKIND_UI2:
  324. case DBVALUEKIND_I2:
  325. case DBVALUEKIND_I4:
  326. case DBVALUEKIND_UI4:
  327. case DBVALUEKIND_R4:
  328. case DBVALUEKIND_R8:
  329. case DBVALUEKIND_CY:
  330. case DBVALUEKIND_DATE:
  331. case DBVALUEKIND_ERROR:
  332. case DBVALUEKIND_I8:
  333. case DBVALUEKIND_UI8:
  334. break;
  335. default:
  336. Win4Assert( !"Illegal Case Statement" );
  337. #endif // CIDBG==1
  338. };
  339. if ( 0 != pMemToFree )
  340. {
  341. CoTaskMemFree( pMemToFree );
  342. }
  343. RtlZeroMemory( &value, sizeof(value) );
  344. }
  345. //+---------------------------------------------------------------------------
  346. //
  347. // Method: CDbCmdTreeNode::CDbCmdTreeNode, public
  348. //
  349. // Synopsis:
  350. //
  351. // Returns:
  352. //
  353. // History: 6-06-95 srikants Created
  354. //
  355. // Notes:
  356. //
  357. //----------------------------------------------------------------------------
  358. CDbCmdTreeNode::~CDbCmdTreeNode()
  359. {
  360. //
  361. // Unlink pointers before deleting, in case the caller gives
  362. // a tree with cycles.
  363. //
  364. if ( 0 != pctFirstChild )
  365. {
  366. CDbCmdTreeNode * pTree = (CDbCmdTreeNode *)pctFirstChild;
  367. pctFirstChild = 0;
  368. delete pTree;
  369. }
  370. if ( 0 != pctNextSibling )
  371. {
  372. CDbCmdTreeNode * pTree = GetNextSibling();
  373. pctNextSibling = 0;
  374. while ( 0 != pTree)
  375. {
  376. CDbCmdTreeNode * pNext = pTree->GetNextSibling();
  377. pTree->pctNextSibling = 0;
  378. delete pTree;
  379. pTree = pNext;
  380. }
  381. }
  382. CleanupDataValue();
  383. }
  384. //+---------------------------------------------------------------------------
  385. //
  386. // Method: CDbCmdTreeNode::AppendChild, protected
  387. //
  388. // Synopsis: Add a node to the end of the child list.
  389. //
  390. // Arguments: [pChild] -
  391. //
  392. // Returns: Nothing
  393. //
  394. // History: 6-06-95 srikants Created
  395. //
  396. // Notes:
  397. //
  398. //----------------------------------------------------------------------------
  399. void CDbCmdTreeNode::AppendChild( CDbCmdTreeNode *pChild )
  400. {
  401. Win4Assert( 0 != pChild );
  402. if ( 0 == pctFirstChild )
  403. {
  404. pctFirstChild = pChild;
  405. }
  406. else
  407. {
  408. DBCOMMANDTREE * pCurr = pctFirstChild;
  409. while ( 0 != pCurr->pctNextSibling )
  410. {
  411. pCurr = pCurr->pctNextSibling;
  412. }
  413. pCurr->pctNextSibling = pChild;
  414. }
  415. }
  416. //+---------------------------------------------------------------------------
  417. //
  418. // Method: CDbCmdTreeNode::InsertChild, protected
  419. //
  420. // Synopsis: Add a node to the beginning of the child list.
  421. //
  422. // Arguments: [pChild] -
  423. //
  424. // Returns: Nothing
  425. //
  426. // History: 6-06-95 srikants Created
  427. //
  428. // Notes:
  429. //
  430. //----------------------------------------------------------------------------
  431. void CDbCmdTreeNode::InsertChild( CDbCmdTreeNode *pChild )
  432. {
  433. Win4Assert( 0 != pChild );
  434. Win4Assert( 0 == pChild->pctNextSibling );
  435. pChild->pctNextSibling = pctFirstChild;
  436. pctFirstChild = pChild;
  437. }
  438. //+---------------------------------------------------------------------------
  439. //
  440. // Method: CDbCmdTreeNode::SetChildren, protected
  441. //
  442. // Synopsis: Add a list of nodes as children
  443. //
  444. // Arguments: [pChild] - head of list
  445. //
  446. // Returns: Nothing
  447. //
  448. // History: 23 Apr 1997 AlanW Created
  449. //
  450. // Notes: Could be inline if it weren't for the asserts
  451. //
  452. //----------------------------------------------------------------------------
  453. void CDbCmdTreeNode::SetChildren( CDbCmdTreeNode *pChild )
  454. {
  455. Win4Assert( 0 != pChild );
  456. Win4Assert( 0 == pctFirstChild );
  457. pctFirstChild = pChild;
  458. }
  459. //+---------------------------------------------------------------------------
  460. //
  461. // Method: CDbCmdTreeNode::RemoveFirstChild, protected
  462. //
  463. // Synopsis: Unlink first child node and return it.
  464. //
  465. // Arguments: -NONE-
  466. //
  467. // Returns: First child node. NULL if no children.
  468. //
  469. // Notes:
  470. //
  471. // History: 13 July 1995 AlanW Created
  472. //
  473. //----------------------------------------------------------------------------
  474. CDbCmdTreeNode * CDbCmdTreeNode::RemoveFirstChild( )
  475. {
  476. CDbCmdTreeNode * pChild = (CDbCmdTreeNode *)pctFirstChild;
  477. if (0 != pChild)
  478. {
  479. pctFirstChild = pChild->pctNextSibling;
  480. pChild->pctNextSibling = 0;
  481. }
  482. return pChild;
  483. }
  484. //+---------------------------------------------------------------------------
  485. //
  486. // Method: CDbCmdTreeNode::AppendSibling, protected
  487. //
  488. // Synopsis: Append a node to the end of the sibling list
  489. //
  490. // Arguments: [pSibling] - node to be added to the sibling list
  491. //
  492. // Returns: Nothing
  493. //
  494. // History: 6-13-95 srikants Created
  495. //
  496. // Notes: The pSibling may have siblings and children.
  497. //
  498. //----------------------------------------------------------------------------
  499. void CDbCmdTreeNode::AppendSibling( CDbCmdTreeNode *pSibling )
  500. {
  501. Win4Assert( 0 != pSibling );
  502. if ( 0 == pctNextSibling )
  503. {
  504. pctNextSibling = pSibling;
  505. }
  506. else
  507. {
  508. DBCOMMANDTREE * pCurr = pctNextSibling;
  509. while ( 0 != pCurr->pctNextSibling )
  510. {
  511. pCurr = pCurr->pctNextSibling;
  512. }
  513. pCurr->pctNextSibling = pSibling;
  514. }
  515. }
  516. //+---------------------------------------------------------------------------
  517. //
  518. // Method: CDbCmdTreeNode::TransferNode, public
  519. //
  520. // Synopsis: Transfer pointers and data from one command tree node
  521. // to another.
  522. //
  523. // Arguments: [pNode] - pointer to target node.
  524. //
  525. // Returns: nothing
  526. //
  527. // History: 27 Jun 1995 AlanW Created
  528. //
  529. // Notes: Specific to the needs of IQuery::AddPostProcessing;
  530. // not available to client code.
  531. //
  532. //----------------------------------------------------------------------------
  533. void CDbCmdTreeNode::TransferNode( CDbCmdTreeNode *pNode )
  534. {
  535. RtlCopyMemory( pNode, this, sizeof(CDbCmdTreeNode));
  536. RtlZeroMemory( this, sizeof(CDbCmdTreeNode) );
  537. op = DBOP_DEFAULT;
  538. wKind = DBVALUEKIND_EMPTY;
  539. }
  540. //+---------------------------------------------------------------------------
  541. //
  542. // Method: CDbCmdTreeNode::Clone, public
  543. //
  544. // Synopsis: Create a copy of a command tree
  545. //
  546. // Arguments: [fCopyErrors] - optional, TRUE if error fields are to be copied
  547. //
  548. // Returns: CdbCmdTreeNode* - the copy of the tree
  549. //
  550. // History: 6-13-95 srikants Created
  551. //
  552. // Notes:
  553. //
  554. //----------------------------------------------------------------------------
  555. CDbCmdTreeNode * CDbCmdTreeNode::Clone( BOOL fCopyErrors ) const
  556. {
  557. if ( IsNotImplemented(wKind) )
  558. {
  559. Win4Assert( !"Type Not Implemented" );
  560. return 0;
  561. }
  562. CDbCmdTreeNode * pCopy = new CDbCmdTreeNode( op );
  563. if ( 0 == pCopy )
  564. return 0;
  565. if (fCopyErrors)
  566. pCopy->hrError = hrError;
  567. else
  568. pCopy->hrError = S_OK;
  569. BOOL fSuccess = TRUE;
  570. pCopy->wKind = wKind;
  571. switch ( wKind )
  572. {
  573. case DBVALUEKIND_EMPTY:
  574. break;
  575. case DBVALUEKIND_BOOL:
  576. case DBVALUEKIND_UI1:
  577. case DBVALUEKIND_I1:
  578. case DBVALUEKIND_UI2:
  579. case DBVALUEKIND_I2:
  580. case DBVALUEKIND_I4:
  581. case DBVALUEKIND_UI4:
  582. case DBVALUEKIND_R4:
  583. case DBVALUEKIND_R8:
  584. case DBVALUEKIND_CY:
  585. case DBVALUEKIND_DATE:
  586. case DBVALUEKIND_ERROR:
  587. case DBVALUEKIND_I8:
  588. case DBVALUEKIND_UI8:
  589. //
  590. // Just copy the eight bytes.
  591. //
  592. pCopy->value.llValue = value.llValue;
  593. break;
  594. case DBVALUEKIND_WSTR:
  595. if ( 0 != value.pwszValue )
  596. {
  597. pCopy->value.pwszValue = AllocAndCopyWString( value.pwszValue );
  598. fSuccess = 0 != pCopy->value.pwszValue;
  599. }
  600. break;
  601. case DBVALUEKIND_BSTR:
  602. if ( 0 != value.pbstrValue )
  603. {
  604. *((BSTR*)&(pCopy->value.pbstrValue)) = SysAllocStringLen( (BSTR)value.pbstrValue,
  605. SysStringLen( (BSTR)value.pbstrValue ) );
  606. fSuccess = ( 0 != pCopy->value.pbstrValue );
  607. }
  608. break;
  609. case DBVALUEKIND_COMMAND:
  610. if ( 0 != value.pCommand )
  611. {
  612. value.pCommand->AddRef();
  613. pCopy->value.pCommand = value.pCommand;
  614. }
  615. break;
  616. case DBVALUEKIND_IDISPATCH:
  617. if ( 0 != value.pDispatch )
  618. {
  619. value.pDispatch->AddRef();
  620. pCopy->value.pDispatch = value.pDispatch;
  621. }
  622. break;
  623. case DBVALUEKIND_MONIKER:
  624. if ( 0 != value.pMoniker )
  625. {
  626. value.pMoniker->AddRef();
  627. pCopy->value.pMoniker = value.pMoniker;
  628. }
  629. break;
  630. case DBVALUEKIND_ROWSET:
  631. if ( 0 != value.pRowset )
  632. {
  633. value.pRowset->AddRef();
  634. pCopy->value.pRowset = value.pRowset;
  635. }
  636. break;
  637. case DBVALUEKIND_IUNKNOWN:
  638. if ( 0 != value.pUnknown )
  639. {
  640. value.pUnknown->AddRef();
  641. pCopy->value.pUnknown = value.pUnknown;
  642. }
  643. break;
  644. case DBVALUEKIND_BYGUID:
  645. if ( 0 != value.pdbbygdValue )
  646. {
  647. CDbByGuid * pTemp = new CDbByGuid( *value.pdbbygdValue );
  648. if ( 0 != pTemp )
  649. {
  650. pCopy->value.pdbbygdValue = pTemp->CastToStruct();
  651. }
  652. else
  653. {
  654. fSuccess = FALSE;
  655. }
  656. }
  657. break;
  658. case DBVALUEKIND_COLDESC:
  659. Win4Assert(! "DBVALUEKIND_COLDESC unsupported !");
  660. break;
  661. case DBVALUEKIND_ID:
  662. if ( 0 != value.pdbidValue )
  663. {
  664. CDbColId * pId = new CDbColId( *value.pdbidValue );
  665. if ( 0 != pId )
  666. {
  667. if ( !pId->IsValid() )
  668. {
  669. delete pId;
  670. fSuccess = FALSE;
  671. }
  672. else
  673. pCopy->value.pdbidValue = pId->CastToStruct();
  674. }
  675. else
  676. {
  677. fSuccess = FALSE;
  678. }
  679. }
  680. break;
  681. case DBVALUEKIND_CONTENT:
  682. if ( 0 != value.pdbcntntValue )
  683. {
  684. CDbContent * pContent = new CDbContent( *value.pdbcntntValue );
  685. if ( 0 != pContent )
  686. {
  687. if ( !pContent->IsValid() )
  688. {
  689. delete pContent;
  690. fSuccess = FALSE;
  691. }
  692. else
  693. pCopy->value.pdbcntntValue = (DBCONTENT *) pContent;
  694. }
  695. else
  696. {
  697. fSuccess = FALSE;
  698. }
  699. }
  700. break;
  701. case DBVALUEKIND_CONTENTSCOPE:
  702. if ( 0 != value.pdbcntntscpValue )
  703. {
  704. CDbContentScope * pContentScp = new CDbContentScope( *value.pdbcntntscpValue );
  705. if ( 0 != pContentScp )
  706. {
  707. if ( !pContentScp->IsValid() )
  708. {
  709. delete pContentScp;
  710. fSuccess = FALSE;
  711. }
  712. else
  713. pCopy->value.pdbcntntscpValue = (DBCONTENTSCOPE *) pContentScp;
  714. }
  715. else
  716. {
  717. fSuccess = FALSE;
  718. }
  719. }
  720. break;
  721. case DBVALUEKIND_CONTENTTABLE:
  722. if ( 0 != value.pdbcntnttblValue )
  723. {
  724. CDbContentTable * pContentTbl = new CDbContentTable( *value.pdbcntnttblValue );
  725. if ( 0 != pContentTbl )
  726. {
  727. if ( !pContentTbl->IsValid() )
  728. {
  729. delete pContentTbl;
  730. fSuccess = FALSE;
  731. }
  732. else
  733. pCopy->value.pdbcntnttblValue = (DBCONTENTTABLE *) pContentTbl;
  734. }
  735. else
  736. {
  737. fSuccess = FALSE;
  738. }
  739. }
  740. break;
  741. case DBVALUEKIND_CONTENTVECTOR:
  742. if ( 0 != value.pdbcntntvcValue )
  743. {
  744. CDbContentVector * pTemp = new CDbContentVector( *value.pdbcntntvcValue );
  745. if ( pTemp )
  746. {
  747. if ( !pTemp->IsValid() )
  748. {
  749. delete pTemp;
  750. fSuccess = FALSE;
  751. }
  752. else
  753. pCopy->value.pdbcntntvcValue = pTemp->CastToStruct();
  754. }
  755. else
  756. {
  757. fSuccess = FALSE;
  758. }
  759. }
  760. break;
  761. case DBVALUEKIND_CONTENTPROXIMITY:
  762. if ( 0 != value.pdbcntntproxValue )
  763. {
  764. CDbContentProximity * pTemp = new CDbContentProximity( *value.pdbcntntproxValue );
  765. if (pTemp)
  766. {
  767. if ( !pTemp->IsValid() )
  768. {
  769. delete pTemp;
  770. fSuccess = FALSE;
  771. }
  772. else
  773. pCopy->value.pdbcntntproxValue = pTemp->CastToStruct();
  774. }
  775. else
  776. {
  777. fSuccess = FALSE;
  778. }
  779. }
  780. break;
  781. case DBVALUEKIND_LIKE:
  782. if ( 0 != value.pdblikeValue )
  783. {
  784. CDbLike * pTemp = new CDbLike( *value.pdblikeValue );
  785. if (pTemp)
  786. {
  787. if ( !pTemp->IsValid() )
  788. {
  789. delete pTemp;
  790. fSuccess = FALSE;
  791. }
  792. else
  793. pCopy->value.pdblikeValue = pTemp->CastToStruct();
  794. }
  795. else
  796. {
  797. fSuccess = FALSE;
  798. }
  799. }
  800. break;
  801. case DBVALUEKIND_GROUPINFO:
  802. if ( 0 != value.pdbgrpinfValue )
  803. {
  804. CDbGroupInfo * pTemp = new CDbGroupInfo( *value.pdbgrpinfValue );
  805. if ( pTemp )
  806. {
  807. if ( !pTemp->IsValid() )
  808. {
  809. delete pTemp;
  810. fSuccess = FALSE;
  811. }
  812. else
  813. pCopy->value.pdbgrpinfValue = (CDbGroupInfo *) pTemp;
  814. }
  815. else
  816. {
  817. fSuccess = FALSE;
  818. }
  819. }
  820. break;
  821. case DBVALUEKIND_PARAMETER:
  822. if ( 0 != value.pdbparamValue )
  823. {
  824. CDbParameter * pTemp = new CDbParameter( *value.pdbparamValue );
  825. if ( pTemp )
  826. {
  827. if ( !pTemp->IsValid() )
  828. {
  829. delete pTemp;
  830. fSuccess = FALSE;
  831. }
  832. else
  833. pCopy->value.pdbparamValue = pTemp->CastToStruct();
  834. }
  835. else
  836. {
  837. fSuccess = FALSE;
  838. }
  839. }
  840. break;
  841. case DBVALUEKIND_PROPERTY:
  842. if ( 0 != value.pdbpropValue )
  843. {
  844. CDbPropSet * pTemp = new CDbPropSet( *value.pdbpropValue );
  845. if ( 0 != pTemp )
  846. {
  847. if ( !pTemp->IsValid() )
  848. {
  849. delete pTemp;
  850. fSuccess = FALSE;
  851. }
  852. else
  853. pCopy->value.pdbpropValue = pTemp->CastToStruct();
  854. }
  855. else
  856. {
  857. fSuccess = FALSE;
  858. }
  859. }
  860. break;
  861. case DBVALUEKIND_SETFUNC:
  862. Win4Assert( !"NYI - DBVALUEKIND_SETFUNC");
  863. break;
  864. case DBVALUEKIND_SORTINFO:
  865. if ( 0 != value.pdbsrtinfValue )
  866. {
  867. CDbSortInfo * pTemp = new CDbSortInfo( *value.pdbsrtinfValue );
  868. if ( 0 != pTemp )
  869. {
  870. if ( !pTemp->IsValid() )
  871. {
  872. delete pTemp;
  873. fSuccess = FALSE;
  874. }
  875. else
  876. pCopy->value.pdbsrtinfValue = (DBSORTINFO *) pTemp;
  877. }
  878. else
  879. {
  880. fSuccess = FALSE;
  881. }
  882. }
  883. break;
  884. case DBVALUEKIND_TEXT:
  885. if ( 0 != value.pdbtxtValue )
  886. {
  887. CDbText * pTemp = new CDbText( *value.pdbtxtValue );
  888. if ( pTemp )
  889. {
  890. if ( !pTemp->IsValid() )
  891. {
  892. delete pTemp;
  893. fSuccess = FALSE;
  894. }
  895. else
  896. pCopy->value.pdbtxtValue = (DBTEXT *) pTemp;
  897. }
  898. else
  899. {
  900. fSuccess = FALSE;
  901. }
  902. }
  903. break;
  904. case DBVALUEKIND_VARIANT:
  905. if ( 0 != value.pvarValue )
  906. {
  907. CStorageVariant const * pSrcVarnt = CastToStorageVariant( *value.pvarValue );
  908. CStorageVariant * pDstVarnt = new CStorageVariant( *pSrcVarnt );
  909. fSuccess = ( 0 != pDstVarnt ) && pDstVarnt->IsValid();
  910. if ( fSuccess )
  911. pCopy->value.pvarValue = (VARIANT *) (void *) pDstVarnt;
  912. else
  913. delete pDstVarnt;
  914. }
  915. break;
  916. case DBVALUEKIND_GUID:
  917. if ( 0 != value.pGuid )
  918. {
  919. GUID * pTemp = (GUID *) CoTaskMemAlloc( sizeof(GUID) );
  920. if ( 0 != pTemp )
  921. {
  922. *pTemp = *value.pGuid;
  923. pCopy->value.pGuid = pTemp;
  924. }
  925. else
  926. {
  927. fSuccess = FALSE;
  928. }
  929. }
  930. break;
  931. case DBVALUEKIND_BYTES:
  932. // how do we know the length of this ??
  933. Win4Assert( !"NYI - DBVALUEKIND_BYTES" );
  934. break;
  935. case DBVALUEKIND_STR:
  936. if ( 0 != value.pzValue )
  937. {
  938. unsigned cb = strlen( value.pzValue ) + 1;
  939. char * pTemp = (char *) CoTaskMemAlloc( cb );
  940. if ( pTemp )
  941. {
  942. strcpy( pTemp, value.pzValue );
  943. pCopy->value.pzValue = pTemp;
  944. }
  945. else
  946. {
  947. fSuccess = FALSE;
  948. }
  949. }
  950. break;
  951. case DBVALUEKIND_NUMERIC:
  952. Win4Assert( !"NYI - DBVALUEKIND_NUMERIC" );
  953. break;
  954. case DBVALUEKIND_BYREF:
  955. Win4Assert( !"NYI - DBVALUEKIND_BYREF" );
  956. break;
  957. default:
  958. Win4Assert( !"Invalid Case Statement" );
  959. pCopy->wKind = DBVALUEKIND_EMPTY;
  960. }
  961. if ( !fSuccess )
  962. {
  963. delete pCopy;
  964. return 0;
  965. }
  966. //
  967. // Next allocate the children nodes
  968. //
  969. if ( 0 != pctFirstChild )
  970. {
  971. CDbCmdTreeNode * pFirstChild = GetFirstChild();
  972. pCopy->pctFirstChild = pFirstChild->Clone( fCopyErrors );
  973. if ( 0 == pCopy->pctFirstChild )
  974. {
  975. delete pCopy;
  976. return 0;
  977. }
  978. }
  979. //
  980. // Next allocate all the siblings.
  981. // If stack space on the client becomes an issue we could iterate to
  982. // reduce stack depth.
  983. //
  984. if ( 0 != pctNextSibling )
  985. {
  986. CDbCmdTreeNode * pSibling = GetNextSibling();
  987. pCopy->pctNextSibling = pSibling->Clone( fCopyErrors );
  988. if ( 0 == pCopy->pctNextSibling )
  989. {
  990. delete pCopy;
  991. return 0;
  992. }
  993. }
  994. return pCopy;
  995. }
  996. //+---------------------------------------------------------------------------
  997. //
  998. // Method: CDbCmdTreeNode::Marshall
  999. //
  1000. // Synopsis:
  1001. //
  1002. // Arguments: [stm] -
  1003. //
  1004. // Returns:
  1005. //
  1006. // History: 6-20-95 srikants Created
  1007. //
  1008. // Notes:
  1009. //
  1010. //----------------------------------------------------------------------------
  1011. void CDbCmdTreeNode::Marshall( PSerStream & stm ) const
  1012. {
  1013. if ( IsNotImplemented( wKind ) )
  1014. {
  1015. Win4Assert( !"Type Not Implemented" );
  1016. return;
  1017. }
  1018. //
  1019. // Serialize the operator
  1020. //
  1021. stm.PutULong( (ULONG) op );
  1022. //
  1023. // Indicate the kind of the value.
  1024. //
  1025. Win4Assert( sizeof(wKind) == sizeof(USHORT) );
  1026. stm.PutUShort( wKind );
  1027. //
  1028. // Serialize the hrError
  1029. //
  1030. Win4Assert( sizeof(hrError) == sizeof(hrError) );
  1031. stm.PutULong( hrError );
  1032. //
  1033. //
  1034. // Indicate if the child is null or not
  1035. //
  1036. if ( 0 != pctFirstChild )
  1037. {
  1038. stm.PutByte(1);
  1039. }
  1040. else
  1041. {
  1042. stm.PutByte(0);
  1043. }
  1044. //
  1045. // Indicate if the sibling is null or not
  1046. //
  1047. if ( 0 != pctNextSibling )
  1048. {
  1049. stm.PutByte(1);
  1050. }
  1051. else
  1052. {
  1053. stm.PutByte(0);
  1054. }
  1055. //
  1056. // Next serialize the value.
  1057. //
  1058. switch ( wKind )
  1059. {
  1060. case DBVALUEKIND_EMPTY:
  1061. break; // nothing to marshall
  1062. case DBVALUEKIND_BOOL:
  1063. Win4Assert( sizeof(DBTYPE_BOOL) == sizeof(BYTE) );
  1064. case DBVALUEKIND_UI1:
  1065. case DBVALUEKIND_I1:
  1066. stm.PutByte( (BYTE) value.schValue );
  1067. break;
  1068. case DBVALUEKIND_UI2:
  1069. case DBVALUEKIND_I2:
  1070. stm.PutUShort( (USHORT) value.sValue );
  1071. break;
  1072. case DBVALUEKIND_I4:
  1073. case DBVALUEKIND_UI4:
  1074. stm.PutULong( (ULONG) value.ulValue );
  1075. break;
  1076. case DBVALUEKIND_R4:
  1077. stm.PutFloat( value.flValue );
  1078. break;
  1079. case DBVALUEKIND_R8:
  1080. stm.PutDouble( value.dblValue );
  1081. break;
  1082. case DBVALUEKIND_CY:
  1083. case DBVALUEKIND_DATE:
  1084. case DBVALUEKIND_ERROR:
  1085. case DBVALUEKIND_I8:
  1086. case DBVALUEKIND_UI8:
  1087. stm.PutBlob( (BYTE *) &value, sizeof(value) );
  1088. break;
  1089. case DBVALUEKIND_WSTR:
  1090. stm.PutWString( value.pwszValue );
  1091. break;
  1092. case DBVALUEKIND_BSTR:
  1093. {
  1094. ULONG cwc = (0 != value.pbstrValue) ? SysStringLen( (BSTR)value.pbstrValue ) : 0;
  1095. stm.PutULong( cwc );
  1096. if (cwc)
  1097. stm.PutWChar( (BSTR)value.pbstrValue, cwc );
  1098. }
  1099. break;
  1100. case DBVALUEKIND_COMMAND:
  1101. case DBVALUEKIND_IDISPATCH:
  1102. case DBVALUEKIND_MONIKER:
  1103. case DBVALUEKIND_ROWSET:
  1104. case DBVALUEKIND_IUNKNOWN:
  1105. // How do you marshall an open interface?
  1106. stm.PutByte(0);
  1107. break;
  1108. case DBVALUEKIND_BYGUID:
  1109. if ( value.pdbbygdValue )
  1110. {
  1111. stm.PutByte(1);
  1112. CDbByGuid * pTemp = (CDbByGuid *) value.pdbbygdValue;
  1113. pTemp->Marshall( stm );
  1114. }
  1115. else
  1116. {
  1117. stm.PutByte(0);
  1118. }
  1119. break;
  1120. case DBVALUEKIND_COLDESC:
  1121. Win4Assert(! "DBVALUEKIND_COLDESC unsupported !");
  1122. break;
  1123. case DBVALUEKIND_ID:
  1124. if ( value.pdbidValue )
  1125. {
  1126. stm.PutByte(1);
  1127. CDbColId * pTemp = (CDbColId *) value.pdbidValue;
  1128. pTemp->Marshall( stm );
  1129. }
  1130. else
  1131. {
  1132. stm.PutByte(0);
  1133. }
  1134. break;
  1135. case DBVALUEKIND_CONTENT:
  1136. if ( value.pdbcntntValue )
  1137. {
  1138. stm.PutByte(1);
  1139. CDbContent * pTemp = (CDbContent *) value.pdbcntntValue;
  1140. pTemp->Marshall( stm );
  1141. }
  1142. else
  1143. {
  1144. stm.PutByte(0);
  1145. }
  1146. break;
  1147. case DBVALUEKIND_CONTENTVECTOR:
  1148. if ( value.pdbcntntvcValue )
  1149. {
  1150. stm.PutByte(1);
  1151. CDbContentVector * pTemp =
  1152. (CDbContentVector *)value.pdbcntntvcValue;
  1153. pTemp->Marshall( stm );
  1154. }
  1155. else
  1156. {
  1157. stm.PutByte(0);
  1158. }
  1159. break;
  1160. case DBVALUEKIND_LIKE:
  1161. if (value.pdblikeValue )
  1162. {
  1163. stm.PutByte(1);
  1164. CDbLike * pTemp = (CDbLike *)value.pdblikeValue;
  1165. pTemp->Marshall( stm );
  1166. }
  1167. else
  1168. {
  1169. stm.PutByte( 0 );
  1170. }
  1171. break;
  1172. case DBVALUEKIND_CONTENTPROXIMITY:
  1173. if (value.pdbcntntproxValue )
  1174. {
  1175. stm.PutByte(1);
  1176. CDbContentProximity * pTemp = (CDbContentProximity *)value.pdbcntntproxValue;
  1177. pTemp->Marshall( stm );
  1178. }
  1179. else
  1180. {
  1181. stm.PutByte( 0 );
  1182. }
  1183. break;
  1184. case DBVALUEKIND_GROUPINFO:
  1185. if ( value.pdbgrpinfValue )
  1186. {
  1187. stm.PutByte(1);
  1188. CDbGroupInfo * pTemp =
  1189. (CDbGroupInfo *)value.pdbgrpinfValue;
  1190. pTemp->Marshall( stm );
  1191. }
  1192. else
  1193. {
  1194. stm.PutByte(0);
  1195. }
  1196. break;
  1197. case DBVALUEKIND_PARAMETER:
  1198. if ( value.pdbparamValue )
  1199. {
  1200. stm.PutByte(1);
  1201. CDbParameter * pTemp = (CDbParameter *)value.pdbparamValue;
  1202. pTemp->Marshall( stm );
  1203. }
  1204. else
  1205. {
  1206. stm.PutByte(0);
  1207. }
  1208. break;
  1209. case DBVALUEKIND_PROPERTY:
  1210. if ( value.pdbpropValue )
  1211. {
  1212. stm.PutByte(1);
  1213. CDbPropSet * pTemp = (CDbPropSet *)value.pdbpropValue;
  1214. pTemp->Marshall( stm );
  1215. }
  1216. else
  1217. {
  1218. stm.PutByte(0);
  1219. }
  1220. break;
  1221. case DBVALUEKIND_SETFUNC:
  1222. stm.PutByte(0);
  1223. Win4Assert( !"NYI - DBVALUEKIND_SETFUNC" );
  1224. break;
  1225. case DBVALUEKIND_SORTINFO:
  1226. if ( value.pdbsrtinfValue )
  1227. {
  1228. stm.PutByte(1);
  1229. CDbSortInfo const * pSortInfo = (CDbSortInfo const *)
  1230. value.pdbsrtinfValue;
  1231. pSortInfo->Marshall( stm );
  1232. }
  1233. else
  1234. {
  1235. stm.PutByte(0);
  1236. }
  1237. break;
  1238. case DBVALUEKIND_TEXT:
  1239. if ( value.pdbtxtValue )
  1240. {
  1241. stm.PutByte(1);
  1242. CDbText * pTemp = (CDbText *) value.pdbtxtValue;
  1243. pTemp->Marshall(stm);
  1244. }
  1245. else
  1246. {
  1247. stm.PutByte(0);
  1248. }
  1249. break;
  1250. case DBVALUEKIND_VARIANT:
  1251. if ( value.pvarValue )
  1252. {
  1253. stm.PutByte(1);
  1254. CStorageVariant * pVarnt = CastToStorageVariant( *value.pvarValue );
  1255. pVarnt->Marshall(stm);
  1256. }
  1257. else
  1258. {
  1259. stm.PutByte(0);
  1260. }
  1261. break;
  1262. case DBVALUEKIND_GUID:
  1263. if ( value.pGuid )
  1264. {
  1265. stm.PutByte(1);
  1266. stm.PutBlob( (BYTE *) value.pGuid, sizeof(GUID) );
  1267. }
  1268. else
  1269. {
  1270. stm.PutByte(0);
  1271. }
  1272. break;
  1273. case DBVALUEKIND_BYTES:
  1274. stm.PutByte(0);
  1275. Win4Assert( !"NYI - DBVALUEKIND_BYTES" );
  1276. break;
  1277. case DBVALUEKIND_STR:
  1278. stm.PutByte(0);
  1279. Win4Assert( !"NYI - DBVALUEKIND_STR" );
  1280. // if ( value.pzValue )
  1281. // {
  1282. // stm.PutByte(1);
  1283. // stm.PutString( value.pzValue );
  1284. // }
  1285. // else
  1286. // {
  1287. // stm.PutByte(0);
  1288. // }
  1289. break;
  1290. case DBVALUEKIND_NUMERIC:
  1291. if ( value.pdbnValue )
  1292. {
  1293. stm.PutByte(1);
  1294. CDbNumeric * pTemp = (CDbNumeric *) value.pdbnValue;
  1295. pTemp->Marshall( stm );
  1296. }
  1297. else
  1298. {
  1299. stm.PutByte(0);
  1300. }
  1301. break;
  1302. case DBVALUEKIND_BYREF:
  1303. stm.PutByte(0);
  1304. Win4Assert( !"NYI - DBVALUEKIND_BYREF" );
  1305. break;
  1306. default:
  1307. Win4Assert( !"CDbCmdNode::Marshall - Invalid wKind" );
  1308. }
  1309. //
  1310. // If the child is non-null, serialize the child
  1311. //
  1312. if ( 0 != pctFirstChild )
  1313. {
  1314. GetFirstChild()->Marshall(stm);
  1315. }
  1316. //
  1317. // If the sibling is non-null, serialize the sibling
  1318. // If stack space on the client becomes an issue we could iterate to
  1319. // reduce stack depth.
  1320. //
  1321. if ( 0 != pctNextSibling )
  1322. {
  1323. GetNextSibling()->Marshall(stm);
  1324. }
  1325. }
  1326. //+---------------------------------------------------------------------------
  1327. //
  1328. // Method: CDbCmdTreeNode::UnMarshall, public
  1329. //
  1330. // Synopsis:
  1331. //
  1332. // Arguments: [stm] -
  1333. //
  1334. // Returns:
  1335. //
  1336. // History: 6-20-95 srikants Created
  1337. //
  1338. // Notes:
  1339. //
  1340. //----------------------------------------------------------------------------
  1341. BOOL CDbCmdTreeNode::UnMarshall( PDeSerStream & stm )
  1342. {
  1343. CleanupValue();
  1344. //
  1345. // De-Serialize the operator
  1346. //
  1347. op = (DBCOMMANDOP)stm.GetULong();
  1348. //
  1349. // Indicate the kind of the value.
  1350. //
  1351. Win4Assert( sizeof(wKind) == sizeof(USHORT) );
  1352. wKind = stm.GetUShort();
  1353. Win4Assert( !IsNotImplemented(wKind) );
  1354. hrError = stm.GetULong();
  1355. //
  1356. // Indicate if the child is null or not
  1357. //
  1358. BOOL fChildPresent = 0 != stm.GetByte();
  1359. BOOL fSiblingPresent = 0 != stm.GetByte();
  1360. //
  1361. // Next serialize the value.
  1362. //
  1363. WCHAR * pwszStr;
  1364. BOOL fSuccess = TRUE;
  1365. switch ( wKind )
  1366. {
  1367. case DBVALUEKIND_EMPTY:
  1368. break; // nothing to marshall
  1369. case DBVALUEKIND_BOOL:
  1370. Win4Assert( sizeof(DBTYPE_BOOL) == sizeof(BYTE) );
  1371. case DBVALUEKIND_UI1:
  1372. case DBVALUEKIND_I1:
  1373. value.schValue = (BYTE) stm.GetByte();
  1374. break;
  1375. case DBVALUEKIND_UI2:
  1376. case DBVALUEKIND_I2:
  1377. value.usValue = stm.GetUShort();
  1378. break;
  1379. case DBVALUEKIND_I4:
  1380. case DBVALUEKIND_UI4:
  1381. value.ulValue = stm.GetULong();
  1382. break;
  1383. case DBVALUEKIND_R4:
  1384. value.flValue = stm.GetFloat();
  1385. break;
  1386. case DBVALUEKIND_R8:
  1387. value.dblValue = stm.GetDouble();
  1388. break;
  1389. case DBVALUEKIND_CY:
  1390. case DBVALUEKIND_DATE:
  1391. case DBVALUEKIND_ERROR:
  1392. case DBVALUEKIND_I8:
  1393. case DBVALUEKIND_UI8:
  1394. stm.GetBlob( (BYTE *) &value, sizeof(value) );
  1395. break;
  1396. case DBVALUEKIND_WSTR:
  1397. pwszStr = GetWString( stm, fSuccess);
  1398. if ( fSuccess )
  1399. {
  1400. value.pwszValue = pwszStr;
  1401. }
  1402. break;
  1403. case DBVALUEKIND_BSTR:
  1404. pwszStr = GetWString( stm, fSuccess, TRUE );
  1405. if ( fSuccess )
  1406. {
  1407. value.pwszValue = pwszStr;
  1408. }
  1409. break;
  1410. case DBVALUEKIND_COMMAND:
  1411. case DBVALUEKIND_IDISPATCH:
  1412. case DBVALUEKIND_MONIKER:
  1413. case DBVALUEKIND_ROWSET:
  1414. case DBVALUEKIND_IUNKNOWN:
  1415. vqDebugOut(( DEB_WARN, "CDbCmdNode::UnMarshall -- Unmarshalling "
  1416. "interface pointer failed\n" ));
  1417. stm.GetByte();
  1418. wKind = DBVALUEKIND_EMPTY;
  1419. break;
  1420. case DBVALUEKIND_BYGUID:
  1421. if ( 0 != stm.GetByte() )
  1422. {
  1423. CDbByGuid * pTemp = new CDbByGuid();
  1424. if ( pTemp )
  1425. {
  1426. value.pdbbygdValue = pTemp->CastToStruct();
  1427. fSuccess = pTemp->UnMarshall( stm );
  1428. }
  1429. else
  1430. {
  1431. fSuccess = FALSE;
  1432. }
  1433. }
  1434. break;
  1435. case DBVALUEKIND_COLDESC:
  1436. Win4Assert(! "DBVALUEKIND_COLDESC unsupported !");
  1437. break;
  1438. case DBVALUEKIND_ID:
  1439. if ( 0 != stm.GetByte() )
  1440. {
  1441. CDbColId * pTemp = new CDbColId();
  1442. if ( pTemp )
  1443. {
  1444. value.pdbidValue = pTemp->CastToStruct();
  1445. fSuccess = pTemp->UnMarshall( stm );
  1446. }
  1447. else
  1448. {
  1449. fSuccess = FALSE;
  1450. }
  1451. }
  1452. break;
  1453. case DBVALUEKIND_CONTENT:
  1454. if ( 0 != stm.GetByte() )
  1455. {
  1456. CDbContent * pTemp = new CDbContent();
  1457. if ( pTemp )
  1458. {
  1459. value.pdbcntntValue = pTemp->CastToStruct();
  1460. fSuccess = pTemp->UnMarshall( stm );
  1461. }
  1462. else
  1463. {
  1464. fSuccess = FALSE;
  1465. }
  1466. }
  1467. break;
  1468. case DBVALUEKIND_CONTENTPROXIMITY:
  1469. if ( 0 != stm.GetByte() )
  1470. {
  1471. CDbContentProximity * pTemp = new CDbContentProximity();
  1472. if ( pTemp )
  1473. {
  1474. value.pdbcntntproxValue = pTemp->CastToStruct();
  1475. fSuccess = pTemp->UnMarshall( stm );
  1476. }
  1477. else
  1478. {
  1479. fSuccess = FALSE;
  1480. }
  1481. }
  1482. break;
  1483. case DBVALUEKIND_CONTENTVECTOR:
  1484. if ( 0 != stm.GetByte() )
  1485. {
  1486. CDbContentVector * pTemp = new CDbContentVector();
  1487. if ( pTemp )
  1488. {
  1489. value.pdbcntntvcValue = pTemp->CastToStruct();
  1490. fSuccess = pTemp->UnMarshall( stm );
  1491. }
  1492. else
  1493. {
  1494. fSuccess = FALSE;
  1495. }
  1496. }
  1497. break;
  1498. case DBVALUEKIND_LIKE:
  1499. if ( 0 != stm.GetByte() )
  1500. {
  1501. CDbLike * pTemp = new CDbLike();
  1502. if ( pTemp )
  1503. {
  1504. value.pdblikeValue = pTemp->CastToStruct();
  1505. fSuccess = pTemp->UnMarshall( stm );
  1506. }
  1507. else
  1508. {
  1509. fSuccess = FALSE;
  1510. }
  1511. }
  1512. break;
  1513. case DBVALUEKIND_GROUPINFO:
  1514. if ( 0 != stm.GetByte() )
  1515. {
  1516. CDbGroupInfo * pTemp = new CDbGroupInfo;
  1517. if ( pTemp )
  1518. {
  1519. value.pdbgrpinfValue = pTemp->CastToStruct();
  1520. fSuccess = pTemp->UnMarshall( stm );
  1521. }
  1522. else
  1523. {
  1524. fSuccess = FALSE;
  1525. }
  1526. }
  1527. break;
  1528. case DBVALUEKIND_PARAMETER:
  1529. if ( 0 != stm.GetByte() )
  1530. {
  1531. CDbParameter * pTemp = new CDbParameter();
  1532. if ( pTemp )
  1533. {
  1534. value.pdbparamValue = pTemp->CastToStruct();
  1535. fSuccess = pTemp->UnMarshall(stm);
  1536. }
  1537. else
  1538. {
  1539. fSuccess = FALSE;
  1540. }
  1541. }
  1542. break;
  1543. case DBVALUEKIND_PROPERTY:
  1544. if ( 0 != stm.GetByte() )
  1545. {
  1546. CDbPropSet * pTemp = new CDbPropSet();
  1547. if ( pTemp )
  1548. {
  1549. value.pdbpropValue = pTemp->CastToStruct();
  1550. fSuccess = pTemp->UnMarshall( stm );
  1551. }
  1552. else
  1553. {
  1554. fSuccess = FALSE;
  1555. }
  1556. }
  1557. break;
  1558. case DBVALUEKIND_SETFUNC:
  1559. stm.GetByte();
  1560. Win4Assert( !"NYI - DBVALUEKIND_SETFUNC" );
  1561. break;
  1562. case DBVALUEKIND_SORTINFO:
  1563. if ( 0 != stm.GetByte() )
  1564. {
  1565. CDbSortInfo * pTemp = new CDbSortInfo();
  1566. if ( pTemp )
  1567. {
  1568. value.pdbsrtinfValue = pTemp->CastToStruct();
  1569. fSuccess = pTemp->UnMarshall( stm );
  1570. }
  1571. else
  1572. {
  1573. fSuccess = FALSE;
  1574. }
  1575. }
  1576. break;
  1577. case DBVALUEKIND_TEXT:
  1578. if ( stm.GetByte() )
  1579. {
  1580. CDbText * pTemp = new CDbText();
  1581. if ( pTemp )
  1582. {
  1583. value.pdbtxtValue = pTemp->CastToStruct();
  1584. fSuccess = pTemp->UnMarshall( stm );
  1585. }
  1586. else
  1587. {
  1588. fSuccess = FALSE;
  1589. }
  1590. }
  1591. break;
  1592. case DBVALUEKIND_VARIANT:
  1593. if ( stm.GetByte() )
  1594. {
  1595. CStorageVariant * pTemp = new CStorageVariant(stm);
  1596. if ( pTemp )
  1597. {
  1598. value.pvarValue = (VARIANT *) (void *) pTemp;
  1599. }
  1600. else
  1601. {
  1602. fSuccess = FALSE;
  1603. }
  1604. }
  1605. break;
  1606. case DBVALUEKIND_GUID:
  1607. if ( stm.GetByte() )
  1608. {
  1609. value.pGuid = new GUID;
  1610. if ( value.pGuid )
  1611. {
  1612. stm.GetBlob( (BYTE *) value.pGuid, sizeof(GUID) );
  1613. }
  1614. else
  1615. {
  1616. fSuccess = FALSE;
  1617. }
  1618. }
  1619. break;
  1620. case DBVALUEKIND_BYTES:
  1621. stm.GetByte();
  1622. Win4Assert( !"NYI - DBVALUEKIND_BYTES" );
  1623. break;
  1624. case DBVALUEKIND_STR:
  1625. stm.GetByte();
  1626. Win4Assert( !"NYI - DBVALUEKIND_STR" );
  1627. break;
  1628. case DBVALUEKIND_NUMERIC:
  1629. if ( stm.GetByte() )
  1630. {
  1631. CDbNumeric * pTemp = new CDbNumeric();
  1632. if ( pTemp )
  1633. {
  1634. value.pdbnValue = pTemp->CastToStruct();
  1635. fSuccess = pTemp->UnMarshall(stm);
  1636. }
  1637. else
  1638. {
  1639. fSuccess = FALSE;
  1640. }
  1641. }
  1642. break;
  1643. case DBVALUEKIND_BYREF:
  1644. stm.GetByte();
  1645. Win4Assert( !"NYI - DBVALUEKIND_BYREF" );
  1646. break;
  1647. default:
  1648. Win4Assert( !"CDbCmdNode::UnMarshall - Invalid wKind" );
  1649. }
  1650. if ( !fSuccess )
  1651. {
  1652. vqDebugOut(( DEB_WARN, "UnMarshalling 0x%X Failed for out of memory\n",
  1653. this ));
  1654. return FALSE;
  1655. }
  1656. //
  1657. // If the child is non-null, serialize the child
  1658. //
  1659. if ( fChildPresent )
  1660. {
  1661. pctFirstChild = new CDbCmdTreeNode();
  1662. if ( 0 != pctFirstChild )
  1663. fSuccess = GetFirstChild()->UnMarshall(stm);
  1664. else
  1665. fSuccess = FALSE;
  1666. }
  1667. if ( !fSuccess )
  1668. {
  1669. return FALSE;
  1670. }
  1671. //
  1672. // If the sibling is non-null, serialize the sibling
  1673. //
  1674. if ( fSiblingPresent )
  1675. {
  1676. pctNextSibling = new CDbCmdTreeNode();
  1677. if ( 0 != pctNextSibling )
  1678. {
  1679. fSuccess = GetNextSibling()->UnMarshall(stm);
  1680. }
  1681. else
  1682. {
  1683. fSuccess = FALSE;
  1684. }
  1685. }
  1686. return fSuccess;
  1687. }
  1688. //+---------------------------------------------------------------------------
  1689. //
  1690. // Method: CDbCmdTreeNode::GetWeight, protected
  1691. //
  1692. // Synopsis:
  1693. //
  1694. // Arguments: [lWeight] - The weight to be set.
  1695. //
  1696. // Returns: The weight.
  1697. //
  1698. // History: 13-Aug-97 KrishnaN Created
  1699. //
  1700. // Notes:
  1701. //
  1702. //----------------------------------------------------------------------------
  1703. void CDbCmdTreeNode::SetWeight( LONG lWeight )
  1704. {
  1705. switch (GetValueType())
  1706. {
  1707. // Takes care of DBOP_content and DBOP_content_freetext
  1708. case DBVALUEKIND_CONTENT:
  1709. {
  1710. CDbContentRestriction *pCont = (CDbContentRestriction *)this;
  1711. pCont->SetWeight( lWeight );
  1712. break;
  1713. }
  1714. // Takes care of DBOP_vector_or
  1715. case DBVALUEKIND_CONTENTVECTOR:
  1716. {
  1717. CDbVectorRestriction *pVector = (CDbVectorRestriction *)this;
  1718. pVector->SetWeight(lWeight);
  1719. break;
  1720. }
  1721. case DBVALUEKIND_LIKE:
  1722. {
  1723. Win4Assert(DBOP_like == GetCommandType());
  1724. CDbPropertyRestriction *pProp = (CDbPropertyRestriction *)this;
  1725. pProp->SetWeight(lWeight);
  1726. break;
  1727. }
  1728. case DBVALUEKIND_CONTENTPROXIMITY:
  1729. {
  1730. Win4Assert(DBOP_content_proximity == GetCommandType());
  1731. CDbProximityNodeRestriction *pProx = (CDbProximityNodeRestriction *)this;
  1732. pProx->SetWeight(lWeight);
  1733. break;
  1734. }
  1735. case DBVALUEKIND_I4:
  1736. {
  1737. switch (GetCommandType())
  1738. {
  1739. case DBOP_equal:
  1740. case DBOP_not_equal:
  1741. case DBOP_less:
  1742. case DBOP_less_equal:
  1743. case DBOP_greater:
  1744. case DBOP_greater_equal:
  1745. case DBOP_equal_any:
  1746. case DBOP_not_equal_any:
  1747. case DBOP_less_any:
  1748. case DBOP_less_equal_any:
  1749. case DBOP_greater_any:
  1750. case DBOP_greater_equal_any:
  1751. case DBOP_equal_all:
  1752. case DBOP_not_equal_all:
  1753. case DBOP_less_all:
  1754. case DBOP_less_equal_all:
  1755. case DBOP_greater_all:
  1756. case DBOP_greater_equal_all:
  1757. case DBOP_anybits:
  1758. case DBOP_allbits:
  1759. case DBOP_anybits_any:
  1760. case DBOP_allbits_any:
  1761. case DBOP_anybits_all:
  1762. case DBOP_allbits_all:
  1763. {
  1764. CDbPropertyRestriction *pProp = (CDbPropertyRestriction *)this;
  1765. pProp->SetWeight(lWeight);
  1766. break;
  1767. }
  1768. case DBOP_not:
  1769. {
  1770. CDbNotRestriction *pNot = (CDbNotRestriction *)this;
  1771. pNot->SetWeight(lWeight);
  1772. break;
  1773. }
  1774. case DBOP_or:
  1775. case DBOP_and:
  1776. {
  1777. CDbBooleanNodeRestriction *pBoolean = (CDbBooleanNodeRestriction *)this;
  1778. pBoolean->SetWeight(lWeight);
  1779. break;
  1780. }
  1781. default:
  1782. Win4Assert(!"How did we get here?");
  1783. break;
  1784. }
  1785. break;
  1786. }
  1787. default:
  1788. Win4Assert(!"How did we get here?");
  1789. break;
  1790. }
  1791. }
  1792. //+---------------------------------------------------------------------------
  1793. //
  1794. // Method: CDbCmdTreeNode::GetWeight, protected
  1795. //
  1796. // Synopsis:
  1797. //
  1798. // Returns: The weight.
  1799. //
  1800. // History: 13-Aug-97 KrishnaN Created
  1801. //
  1802. // Notes:
  1803. //
  1804. //----------------------------------------------------------------------------
  1805. LONG CDbCmdTreeNode::GetWeight() const
  1806. {
  1807. switch (GetValueType())
  1808. {
  1809. case DBVALUEKIND_CONTENT:
  1810. {
  1811. CDbContentRestriction *pCont = (CDbContentRestriction *)this;
  1812. return pCont->GetWeight();
  1813. }
  1814. case DBVALUEKIND_CONTENTVECTOR:
  1815. {
  1816. CDbVectorRestriction *pVector = (CDbVectorRestriction *)this;
  1817. return pVector->GetWeight();
  1818. }
  1819. case DBVALUEKIND_CONTENTPROXIMITY:
  1820. {
  1821. CDbProximityNodeRestriction *pProx = (CDbProximityNodeRestriction *)this;
  1822. return pProx->GetWeight();
  1823. }
  1824. case DBVALUEKIND_LIKE:
  1825. {
  1826. CDbPropertyRestriction *pProp = (CDbPropertyRestriction *)this;
  1827. return pProp->GetWeight();
  1828. }
  1829. case DBVALUEKIND_I4:
  1830. {
  1831. switch (GetCommandType())
  1832. {
  1833. case DBOP_equal:
  1834. case DBOP_not_equal:
  1835. case DBOP_less:
  1836. case DBOP_less_equal:
  1837. case DBOP_greater:
  1838. case DBOP_greater_equal:
  1839. case DBOP_equal_any:
  1840. case DBOP_not_equal_any:
  1841. case DBOP_less_any:
  1842. case DBOP_less_equal_any:
  1843. case DBOP_greater_any:
  1844. case DBOP_greater_equal_any:
  1845. case DBOP_equal_all:
  1846. case DBOP_not_equal_all:
  1847. case DBOP_less_all:
  1848. case DBOP_less_equal_all:
  1849. case DBOP_greater_all:
  1850. case DBOP_greater_equal_all:
  1851. case DBOP_anybits:
  1852. case DBOP_allbits:
  1853. case DBOP_anybits_any:
  1854. case DBOP_allbits_any:
  1855. case DBOP_anybits_all:
  1856. case DBOP_allbits_all:
  1857. {
  1858. CDbPropertyRestriction *pProp = (CDbPropertyRestriction *)this;
  1859. return pProp->GetWeight();
  1860. }
  1861. case DBOP_not:
  1862. {
  1863. CDbNotRestriction *pNot = (CDbNotRestriction *)this;
  1864. return pNot->GetWeight();
  1865. }
  1866. case DBOP_or:
  1867. case DBOP_and:
  1868. {
  1869. CDbBooleanNodeRestriction *pVector = (CDbBooleanNodeRestriction *)this;
  1870. return pVector->GetWeight();
  1871. }
  1872. default:
  1873. Win4Assert(!"How did we get here?");
  1874. break;
  1875. }
  1876. break;
  1877. }
  1878. default:
  1879. Win4Assert(!"Need to call the GetWeight for the appropriate class.");
  1880. break;
  1881. }
  1882. return MAX_QUERY_RANK;
  1883. }
  1884. //+---------------------------------------------------------------------------
  1885. //
  1886. // Method: CDbColumnNode::CDbColumnNode, public
  1887. //
  1888. // Synopsis: Construct a CDbColumnNode
  1889. //
  1890. // Arguments: [guidPropSet] -
  1891. // [wcsProperty] -
  1892. //
  1893. // History: 6-06-95 srikants Created
  1894. //
  1895. // Notes: The assert here validates an assumption in the inline
  1896. // SetPropSet and GetPropSet methods.
  1897. //
  1898. //----------------------------------------------------------------------------
  1899. CDbColumnNode::CDbColumnNode( GUID const & guidPropSet,
  1900. WCHAR const * wcsProperty )
  1901. : CDbCmdTreeNode(DBOP_column_name)
  1902. {
  1903. wKind = DBVALUEKIND_ID;
  1904. CDbColId * pTemp = new CDbColId( guidPropSet, wcsProperty );
  1905. if ( 0 != pTemp && !pTemp->IsValid() )
  1906. {
  1907. delete pTemp;
  1908. pTemp = 0;
  1909. }
  1910. value.pdbidValue = (DBID *) pTemp;
  1911. }
  1912. //+---------------------------------------------------------------------------
  1913. //
  1914. // Method: CDbColumnNode::CDbColumnNode, public
  1915. //
  1916. // Synopsis: Construct a CDbColumnNode from a DBID
  1917. //
  1918. // Arguments: [rColSpec] - DBID from which to initialize the node
  1919. //
  1920. // History: 6-20-95 srikants Created
  1921. //
  1922. // Notes: The column must be named by guid & number, or guid & name.
  1923. //
  1924. //----------------------------------------------------------------------------
  1925. CDbColumnNode::CDbColumnNode( DBID const & propSpec, BOOL fIMeanIt )
  1926. : CDbCmdTreeNode(DBOP_column_name)
  1927. {
  1928. wKind = DBVALUEKIND_ID;
  1929. CDbColId * pTemp = new CDbColId( propSpec );
  1930. if ( 0 != pTemp && !pTemp->IsValid() )
  1931. {
  1932. delete pTemp;
  1933. pTemp = 0;
  1934. }
  1935. value.pdbidValue = (DBID *) pTemp;
  1936. }
  1937. //+---------------------------------------------------------------------------
  1938. //
  1939. // Member: CDbScalarValue::Value
  1940. //
  1941. // Synopsis: Gets the value in the scalar into a variant.
  1942. //
  1943. // Arguments: [valOut] - Output value.
  1944. //
  1945. // Returns: TRUE if successful. FALSE o/w
  1946. //
  1947. // History: 11-16-95 srikants Created
  1948. //
  1949. //----------------------------------------------------------------------------
  1950. void CDbScalarValue::Value( CStorageVariant & valOut )
  1951. {
  1952. //
  1953. // Deallocate any memory allocated for this node.
  1954. //
  1955. switch ( wKind )
  1956. {
  1957. case DBVALUEKIND_EMPTY:
  1958. valOut.SetEMPTY();
  1959. break;
  1960. case DBVALUEKIND_BOOL:
  1961. valOut.SetBOOL((SHORT)value.fValue);
  1962. break;
  1963. case DBVALUEKIND_UI1:
  1964. valOut.SetUI1( value.uchValue );
  1965. break;
  1966. case DBVALUEKIND_I1:
  1967. valOut.SetI1( value.schValue );
  1968. break;
  1969. case DBVALUEKIND_UI2:
  1970. valOut = value.usValue;
  1971. break;
  1972. case DBVALUEKIND_I2:
  1973. valOut = value.sValue;
  1974. break;
  1975. case DBVALUEKIND_I4:
  1976. valOut = value.lValue;
  1977. break;
  1978. case DBVALUEKIND_UI4:
  1979. valOut = value.ulValue;
  1980. break;
  1981. case DBVALUEKIND_R4:
  1982. valOut = value.flValue;
  1983. break;
  1984. case DBVALUEKIND_R8:
  1985. valOut = value.dblValue;
  1986. break;
  1987. case DBVALUEKIND_CY:
  1988. valOut = value.cyValue;
  1989. break;
  1990. case DBVALUEKIND_DATE:
  1991. valOut = value.dateValue;
  1992. break;
  1993. case DBVALUEKIND_ERROR:
  1994. valOut = value.scodeValue;
  1995. break;
  1996. case DBVALUEKIND_I8:
  1997. valOut.SetI8( *((LARGE_INTEGER *)(&value.llValue)) );
  1998. break;
  1999. case DBVALUEKIND_UI8:
  2000. valOut.SetUI8( *((ULARGE_INTEGER *)(&value.ullValue)) );
  2001. break;
  2002. case DBVALUEKIND_WSTR:
  2003. valOut = value.pwszValue;
  2004. break;
  2005. case DBVALUEKIND_BSTR:
  2006. valOut.SetBSTR( (BSTR)value.pbstrValue );
  2007. break;
  2008. case DBVALUEKIND_VARIANT:
  2009. {
  2010. CStorageVariant * pVarnt = _GetStorageVariant();
  2011. if ( 0 != pVarnt )
  2012. {
  2013. valOut = *pVarnt;
  2014. }
  2015. else
  2016. {
  2017. valOut.SetEMPTY();
  2018. }
  2019. }
  2020. break;
  2021. case DBVALUEKIND_STR:
  2022. if ( value.pzValue )
  2023. {
  2024. valOut = value.pzValue;
  2025. }
  2026. else
  2027. {
  2028. valOut.SetEMPTY();
  2029. }
  2030. break;
  2031. case DBVALUEKIND_BYTES:
  2032. case DBVALUEKIND_NUMERIC:
  2033. case DBVALUEKIND_BYREF:
  2034. valOut.SetEMPTY();
  2035. Win4Assert( !"CDbScalarValue::Value - Not Implemented" );
  2036. break;
  2037. default:
  2038. valOut.SetEMPTY();
  2039. Win4Assert( !"Illegal Case Statement" );
  2040. }
  2041. }