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.

1291 lines
30 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 2000.
  5. //
  6. // File: dbwrap.cxx
  7. //
  8. // Contents: C++ wrapper classes for DBCOMMANDTREE value structures
  9. //
  10. // Classes: CDbColId
  11. //
  12. // Functions:
  13. //
  14. // History: 6-22-95 srikants Created
  15. //
  16. //----------------------------------------------------------------------------
  17. #include <pch.cxx>
  18. #pragma hdrstop
  19. //+-------------------------------------------------------------------------
  20. //
  21. // Member: CDbColId::CDbColId, public
  22. //
  23. // Synopsis: Default constructor
  24. //
  25. // Effects: Defines column with null guid and propid 0
  26. //
  27. // History: 19 Jul 1995 AlanW Created
  28. //
  29. //--------------------------------------------------------------------------
  30. CDbColId::CDbColId()
  31. {
  32. eKind = DBKIND_PROPID;
  33. uName.ulPropid = 0;
  34. }
  35. //+---------------------------------------------------------------------------
  36. //
  37. // Method: CDbColId::CDbColId
  38. //
  39. // Synopsis: Construct a CDbColId
  40. //
  41. // Arguments: [guidPropSet] -
  42. // [wcsProperty] -
  43. //
  44. // History: 6-06-95 srikants Created
  45. //
  46. // Notes:
  47. //
  48. //----------------------------------------------------------------------------
  49. CDbColId::CDbColId( GUID const & guidPropSet,
  50. WCHAR const * wcsProperty )
  51. {
  52. eKind = DBKIND_GUID_PROPID;
  53. BOOL fSuccess = SetProperty( wcsProperty );
  54. if (fSuccess)
  55. SetPropSet( guidPropSet );
  56. }
  57. //+---------------------------------------------------------------------------
  58. //
  59. // Method: CDbColId::CDbColId
  60. //
  61. // Synopsis: Construct a CDbColId from a DBID
  62. //
  63. // Arguments: [propSpec] - DBID from which to initialize the node
  64. //
  65. // History: 6-20-95 srikants Created
  66. //
  67. // Notes: The column must be named by guid & number, or guid & name.
  68. //
  69. //----------------------------------------------------------------------------
  70. CDbColId::CDbColId( DBID const & propSpec )
  71. {
  72. BOOL fSuccess = TRUE;
  73. eKind = DBKIND_GUID_PROPID;
  74. CDbColId const * rhs = (CDbColId const *) &propSpec;
  75. if ( rhs->IsPropertyName() )
  76. {
  77. fSuccess = SetProperty( rhs->GetPropertyName() );
  78. }
  79. else if ( rhs->IsPropertyPropid() )
  80. {
  81. SetProperty( rhs->GetPropertyPropid() );
  82. }
  83. else
  84. {
  85. return;
  86. }
  87. if ( fSuccess && rhs->IsPropSetPresent() )
  88. {
  89. SetPropSet( rhs->GetPropSet() );
  90. }
  91. }
  92. //+---------------------------------------------------------------------------
  93. //
  94. // Method: CDbColId::CDbColId
  95. //
  96. // Synopsis: Construct a CDbColId from another CDbColId
  97. //
  98. // Arguments: [propSpec] - CDbColId from which to initialize the node
  99. //
  100. // History: 6-20-95 srikants Created
  101. //
  102. // Notes: The column must be named by guid & number, or guid & name.
  103. //
  104. //----------------------------------------------------------------------------
  105. CDbColId::CDbColId( CDbColId const & propSpec )
  106. {
  107. BOOL fSuccess = TRUE;
  108. eKind = DBKIND_GUID_PROPID;
  109. if ( propSpec.IsPropertyName() )
  110. {
  111. fSuccess = SetProperty( propSpec.GetPropertyName() );
  112. }
  113. else if ( propSpec.IsPropertyPropid() )
  114. {
  115. SetProperty( propSpec.GetPropertyPropid() );
  116. }
  117. else
  118. {
  119. return;
  120. }
  121. if ( fSuccess && propSpec.IsPropSetPresent() )
  122. {
  123. SetPropSet( propSpec.GetPropSet() );
  124. }
  125. }
  126. //+---------------------------------------------------------------------------
  127. //
  128. // Method: CDbColId::SetProperty
  129. //
  130. // Synopsis:
  131. //
  132. // Arguments: [wcsProperty] -
  133. //
  134. // Returns:
  135. //
  136. // History: 6-06-95 srikants Created
  137. //
  138. // Notes:
  139. //
  140. //----------------------------------------------------------------------------
  141. BOOL CDbColId::SetProperty( WCHAR const * wcsProperty )
  142. {
  143. if ( !_IsValidKind() )
  144. {
  145. eKind = DBKIND_GUID_PROPID;
  146. }
  147. else if ( DBKIND_NAME == eKind ||
  148. DBKIND_GUID_NAME == eKind ||
  149. DBKIND_PGUID_NAME == eKind )
  150. {
  151. if ( uName.pwszName )
  152. {
  153. CoTaskMemFree( uName.pwszName );
  154. uName.pwszName = 0;
  155. }
  156. }
  157. BOOL fResult = TRUE;
  158. if ( wcsProperty )
  159. {
  160. uName.pwszName = CDbCmdTreeNode::AllocAndCopyWString( wcsProperty );
  161. if ( DBKIND_PROPID == eKind )
  162. {
  163. eKind = DBKIND_NAME;
  164. }
  165. else if ( DBKIND_GUID_PROPID == eKind )
  166. {
  167. eKind = DBKIND_GUID_NAME;
  168. }
  169. else if ( DBKIND_PGUID_PROPID == eKind )
  170. {
  171. eKind = DBKIND_PGUID_NAME;
  172. }
  173. fResult = (0 != uName.pwszName);
  174. }
  175. return fResult;
  176. }
  177. //+---------------------------------------------------------------------------
  178. //
  179. // Method: CDbColId::operator=
  180. //
  181. // Synopsis:
  182. //
  183. // Arguments: [Property] -
  184. //
  185. // Returns:
  186. //
  187. // History: 6-12-95 srikants Created
  188. //
  189. // Notes:
  190. //
  191. //----------------------------------------------------------------------------
  192. CDbColId & CDbColId::operator=( CDbColId const & Property )
  193. {
  194. if ( !_IsValidKind() )
  195. {
  196. eKind = DBKIND_GUID_PROPID;
  197. }
  198. else
  199. {
  200. Cleanup();
  201. }
  202. if ( DBKIND_GUID_PROPID == Property.eKind ||
  203. DBKIND_PGUID_PROPID == Property.eKind ||
  204. DBKIND_PROPID == Property.eKind )
  205. {
  206. uName.ulPropid = Property.uName.ulPropid;
  207. if ( DBKIND_PROPID == Property.eKind )
  208. {
  209. eKind = DBKIND_PROPID;
  210. }
  211. else if ( DBKIND_GUID_PROPID == Property.eKind )
  212. {
  213. eKind = DBKIND_GUID_PROPID;
  214. if ( DBKIND_GUID_PROPID == Property.eKind )
  215. {
  216. uGuid.guid = Property.uGuid.guid;
  217. }
  218. else
  219. {
  220. uGuid.guid = *(Property.uGuid.pguid);
  221. }
  222. }
  223. }
  224. else
  225. {
  226. Win4Assert( DBKIND_GUID_NAME == Property.eKind ||
  227. DBKIND_PGUID_NAME == Property.eKind ||
  228. DBKIND_NAME == Property.eKind );
  229. if ( SetProperty( Property.GetPropertyName() ) )
  230. {
  231. SetPropSet( Property.GetPropSet() );
  232. }
  233. }
  234. return *this;
  235. }
  236. //+---------------------------------------------------------------------------
  237. //
  238. // Method: CDbColId::operator==
  239. //
  240. // Synopsis: Compare two column IDs for equality
  241. //
  242. // Arguments: [Property] - column ID to be compared with
  243. //
  244. // Returns: TRUE if Property is equivalent to this one, FALSE otherwise
  245. //
  246. // Notes: The PGUID forms are not considered equivalent to the
  247. // forms with GUIDs embedded. It just isn't worth it!
  248. //
  249. // History: 6-13-95 srikants Created
  250. //
  251. //----------------------------------------------------------------------------
  252. BOOL CDbColId::operator==( CDbColId const & Property ) const
  253. {
  254. if ( eKind != Property.eKind )
  255. {
  256. return FALSE;
  257. }
  258. if ( DBKIND_GUID_PROPID == eKind )
  259. {
  260. return uName.ulPropid == Property.uName.ulPropid &&
  261. uGuid.guid == Property.uGuid.guid;
  262. }
  263. else if ( DBKIND_GUID_NAME == eKind )
  264. {
  265. return ( uGuid.guid == Property.uGuid.guid ) &&
  266. ( 0 == _wcsicmp( uName.pwszName, Property.uName.pwszName ) );
  267. }
  268. else if ( DBKIND_PROPID == eKind )
  269. {
  270. return uName.ulPropid == Property.uName.ulPropid;
  271. }
  272. else if ( DBKIND_NAME == eKind )
  273. {
  274. return 0 == _wcsicmp( uName.pwszName, Property.uName.pwszName );
  275. }
  276. else if ( DBKIND_PGUID_PROPID == eKind )
  277. {
  278. return uName.ulPropid == Property.uName.ulPropid &&
  279. *uGuid.pguid == *Property.uGuid.pguid;
  280. }
  281. else if ( DBKIND_PGUID_NAME == eKind )
  282. {
  283. return ( *uGuid.pguid == *Property.uGuid.pguid ) &&
  284. ( 0 == _wcsicmp( uName.pwszName, Property.uName.pwszName ) );
  285. }
  286. else
  287. return FALSE;
  288. }
  289. //+---------------------------------------------------------------------------
  290. //
  291. // Method: CDbColId::Marshall
  292. //
  293. // Synopsis:
  294. //
  295. // Arguments: [stm] -
  296. //
  297. // Returns:
  298. //
  299. // History: 6-21-95 srikants Created
  300. //
  301. // Notes:
  302. //
  303. //----------------------------------------------------------------------------
  304. void CDbColId::Marshall( PSerStream & stm ) const
  305. {
  306. stm.PutULong( eKind );
  307. switch ( eKind )
  308. {
  309. case DBKIND_PROPID:
  310. stm.PutGUID( uGuid.guid );
  311. break;
  312. case DBKIND_GUID_NAME:
  313. stm.PutGUID( uGuid.guid );
  314. CDbCmdTreeNode::PutWString( stm, uName.pwszName );
  315. break;
  316. case DBKIND_GUID_PROPID:
  317. stm.PutGUID( uGuid.guid );
  318. stm.PutULong( uName.ulPropid );
  319. break;
  320. case DBKIND_NAME:
  321. CDbCmdTreeNode::PutWString( stm, uName.pwszName );
  322. break;
  323. case DBKIND_PGUID_NAME:
  324. case DBKIND_PGUID_PROPID:
  325. if ( 0 != uGuid.pguid )
  326. {
  327. stm.PutGUID( *uGuid.pguid );
  328. }
  329. else
  330. {
  331. stm.PutGUID( CDbCmdTreeNode::guidNull );
  332. }
  333. if ( DBKIND_PGUID_PROPID == eKind )
  334. {
  335. stm.PutULong( uName.ulPropid );
  336. }
  337. else
  338. {
  339. CDbCmdTreeNode::PutWString( stm, uName.pwszName );
  340. }
  341. default:
  342. Win4Assert( !"Illegal Case Statement" );
  343. }
  344. }
  345. //+---------------------------------------------------------------------------
  346. //
  347. // Method: CDbColId::UnMarshall
  348. //
  349. // Synopsis:
  350. //
  351. // Arguments: [stm] -
  352. //
  353. // Returns:
  354. //
  355. // History: 6-21-95 srikants Created
  356. //
  357. // Notes:
  358. //
  359. //----------------------------------------------------------------------------
  360. BOOL CDbColId::UnMarshall( PDeSerStream & stm )
  361. {
  362. eKind = stm.GetULong();
  363. BOOL fSuccess = TRUE;
  364. switch ( eKind )
  365. {
  366. case DBKIND_PROPID:
  367. stm.GetGUID( uGuid.guid );
  368. break;
  369. case DBKIND_GUID_NAME:
  370. stm.GetGUID( uGuid.guid );
  371. uName.pwszName = CDbCmdTreeNode::GetWString( stm, fSuccess );
  372. // patch broken old clients
  373. if ( fSuccess && 0 == uName.pwszName )
  374. eKind = DBKIND_GUID_PROPID;
  375. break;
  376. case DBKIND_GUID_PROPID:
  377. stm.GetGUID( uGuid.guid );
  378. uName.ulPropid = stm.GetULong();
  379. break;
  380. case DBKIND_NAME:
  381. uName.pwszName = CDbCmdTreeNode::GetWString( stm, fSuccess );
  382. // patch broken old clients
  383. if ( fSuccess && 0 == uName.pwszName )
  384. eKind = DBKIND_GUID_PROPID;
  385. break;
  386. case DBKIND_PGUID_NAME:
  387. case DBKIND_PGUID_PROPID:
  388. stm.GetGUID( uGuid.guid );
  389. if ( DBKIND_PGUID_PROPID == eKind )
  390. {
  391. eKind = DBKIND_GUID_PROPID;
  392. uName.ulPropid = stm.GetULong();
  393. }
  394. else
  395. {
  396. eKind = DBKIND_GUID_NAME;
  397. uName.pwszName = CDbCmdTreeNode::GetWString( stm, fSuccess );
  398. }
  399. // We don't support these two yet -- so assert and return FALSE
  400. // break;
  401. default:
  402. Win4Assert( !"Illegal Case Statement" );
  403. fSuccess = FALSE;
  404. }
  405. return fSuccess;
  406. }
  407. //+---------------------------------------------------------------------------
  408. //
  409. // Method: CDbColId::Cleanup, public
  410. //
  411. // Synopsis: Cleans out allocated fields in a CDbColId structure
  412. //
  413. // Returns:
  414. //
  415. // History: 6-21-95 srikants Created
  416. //
  417. // Notes:
  418. //
  419. //----------------------------------------------------------------------------
  420. void CDbColId::Cleanup()
  421. {
  422. WCHAR * pwszStr = 0;
  423. switch ( eKind )
  424. {
  425. case DBKIND_GUID_NAME:
  426. case DBKIND_NAME:
  427. pwszStr = (WCHAR *) uName.pwszName;
  428. uName.pwszName = 0;
  429. break;
  430. case DBKIND_PGUID_NAME:
  431. pwszStr = (WCHAR *) uName.pwszName;
  432. uName.pwszName = 0;
  433. // NOTE: fall through
  434. case DBKIND_PGUID_PROPID:
  435. CoTaskMemFree( uGuid.pguid );
  436. uGuid.pguid = 0;
  437. }
  438. if ( 0 != pwszStr )
  439. {
  440. CoTaskMemFree( pwszStr );
  441. }
  442. }
  443. BOOL CDbColId::Copy( DBID const & rhs )
  444. {
  445. CDbColId const * pRhs = (CDbColId *) &rhs;
  446. *this = *pRhs;
  447. //
  448. // If the source is a bogus NAME propid with a 0 value, don't fail
  449. // the copy. This is true for broken old clients who pass a fully
  450. // 0 DBID.
  451. //
  452. if ( DBKIND_GUID_NAME == rhs.eKind && 0 == rhs.uName.pwszName )
  453. eKind = DBKIND_GUID_PROPID;
  454. return IsValid();
  455. }
  456. //+---------------------------------------------------------------------------
  457. //
  458. // Member: CDbByGuid::Marshall
  459. //
  460. // Synopsis:
  461. //
  462. // Arguments: [stm] -
  463. //
  464. // History: 11-17-95 srikants Created
  465. //
  466. // Notes:
  467. //
  468. //----------------------------------------------------------------------------
  469. void CDbByGuid::Marshall( PSerStream & stm ) const
  470. {
  471. stm.PutBlob( (BYTE *) &guid, sizeof(guid) );
  472. stm.PutULong( (ULONG) cbInfo );
  473. if ( cbInfo )
  474. {
  475. Win4Assert( 0 != pbInfo );
  476. stm.PutBlob( pbInfo, (ULONG) cbInfo );
  477. }
  478. }
  479. //+---------------------------------------------------------------------------
  480. //
  481. // Member: CDbByGuid::UnMarshall
  482. //
  483. // Synopsis:
  484. //
  485. // Arguments: [stm] -
  486. //
  487. // Returns: TRUE if successful; FALSE o/w
  488. //
  489. // History: 11-17-95 srikants Created
  490. //
  491. // Notes:
  492. //
  493. //----------------------------------------------------------------------------
  494. BOOL CDbByGuid::UnMarshall( PDeSerStream & stm )
  495. {
  496. _Cleanup();
  497. stm.GetBlob( (BYTE *) &guid, sizeof(guid) );
  498. cbInfo = stm.GetULong();
  499. // Guard against attack
  500. if ( cbInfo > 1000 )
  501. return FALSE;
  502. if ( cbInfo )
  503. {
  504. pbInfo = (BYTE *) CoTaskMemAlloc( (ULONG) cbInfo );
  505. if ( 0 != pbInfo )
  506. {
  507. stm.GetBlob( pbInfo, (ULONG) cbInfo );
  508. }
  509. }
  510. return IsValid();
  511. }
  512. //+---------------------------------------------------------------------------
  513. //
  514. // Member: CDbByGuid::operator
  515. //
  516. // Synopsis:
  517. //
  518. // Arguments: [rhs] -
  519. //
  520. // Returns:
  521. //
  522. // History: 11-21-95 srikants Created
  523. //
  524. // Notes:
  525. //
  526. //----------------------------------------------------------------------------
  527. CDbByGuid & CDbByGuid::operator=( CDbByGuid const & rhs )
  528. {
  529. _Cleanup();
  530. guid = rhs.guid;
  531. cbInfo = rhs.cbInfo;
  532. if ( cbInfo )
  533. {
  534. pbInfo = (BYTE *) CoTaskMemAlloc( (ULONG) cbInfo );
  535. if ( 0 != pbInfo )
  536. {
  537. RtlCopyMemory( pbInfo, rhs.pbInfo, cbInfo );
  538. }
  539. }
  540. return *this;
  541. }
  542. //+---------------------------------------------------------------------------
  543. //
  544. // Member: CDbParameter::Marshall
  545. //
  546. // Synopsis:
  547. //
  548. // Arguments: [stm] -
  549. //
  550. // History: 11-17-95 srikants Created
  551. //
  552. // Notes:
  553. //
  554. //----------------------------------------------------------------------------
  555. void CDbParameter::Marshall( PSerStream & stm ) const
  556. {
  557. if ( 0 != pwszName )
  558. {
  559. stm.PutByte(1);
  560. stm.PutWString( pwszName );
  561. }
  562. else
  563. {
  564. stm.PutByte(0);
  565. }
  566. stm.PutULong( wType );
  567. stm.PutULong( (ULONG) cbMaxLength );
  568. if ( pNum )
  569. {
  570. stm.PutByte(1);
  571. CDbNumeric * pNumeric = (CDbNumeric *) pNum;
  572. pNumeric->Marshall( stm );
  573. }
  574. else
  575. {
  576. stm.PutByte(0);
  577. }
  578. Win4Assert( sizeof(dwFlags) == sizeof(ULONG) );
  579. stm.PutULong( dwFlags );
  580. }
  581. //+---------------------------------------------------------------------------
  582. //
  583. // Member: CDbParameter::_Cleanup
  584. //
  585. // Synopsis:
  586. //
  587. // History: 11-21-95 srikants Created
  588. //
  589. // Notes:
  590. //
  591. //----------------------------------------------------------------------------
  592. void CDbParameter::_Cleanup()
  593. {
  594. if ( pwszName )
  595. {
  596. CoTaskMemFree( pwszName );
  597. pwszName = 0;
  598. }
  599. if ( pTypeInfo )
  600. {
  601. pTypeInfo->Release();
  602. pTypeInfo = 0;
  603. }
  604. if ( pNum )
  605. {
  606. CDbNumeric * pNumeric = (CDbNumeric *) pNum;
  607. delete pNumeric;
  608. pNum = 0;
  609. }
  610. }
  611. //+---------------------------------------------------------------------------
  612. //
  613. // Member: CDbParameter::UnMarshall
  614. //
  615. // Synopsis:
  616. //
  617. // Arguments: [stm] -
  618. //
  619. // Returns: TRUE if successful; FALSE o/w
  620. //
  621. // History: 11-17-95 srikants Created
  622. //
  623. // Notes:
  624. //
  625. //----------------------------------------------------------------------------
  626. BOOL CDbParameter::UnMarshall( PDeSerStream & stm )
  627. {
  628. _Cleanup();
  629. if ( stm.GetByte() )
  630. {
  631. BOOL fSuccess;
  632. pwszName = CDbCmdTreeNode::GetWString( stm, fSuccess );
  633. if ( 0 == pwszName || !fSuccess )
  634. return FALSE;
  635. }
  636. Win4Assert( sizeof(wType) == sizeof(ULONG) );
  637. wType = (DBTYPE) stm.GetULong();
  638. cbMaxLength = stm.GetULong();
  639. if ( stm.GetByte() )
  640. {
  641. CDbNumeric * pNumeric = new CDbNumeric();
  642. if ( pNumeric )
  643. {
  644. pNumeric->UnMarshall( stm );
  645. pNum = pNumeric->CastToStruct();
  646. }
  647. else
  648. {
  649. _Cleanup();
  650. return FALSE;
  651. }
  652. }
  653. Win4Assert( sizeof(dwFlags) == sizeof(ULONG) );
  654. dwFlags = stm.GetULong();
  655. return TRUE;
  656. }
  657. //+---------------------------------------------------------------------------
  658. //
  659. // Member: CDbParameter::Copy
  660. //
  661. // Synopsis:
  662. //
  663. // Arguments: [rhs] -
  664. //
  665. // Returns:
  666. //
  667. // History: 11-21-95 srikants Created
  668. //
  669. // Notes:
  670. //
  671. //----------------------------------------------------------------------------
  672. BOOL CDbParameter::Copy( DBPARAMETER const & rhs )
  673. {
  674. _Cleanup();
  675. if ( rhs.pwszName )
  676. {
  677. pwszName = CDbCmdTreeNode::AllocAndCopyWString( rhs.pwszName );
  678. if ( 0 == pwszName )
  679. {
  680. return FALSE;
  681. }
  682. }
  683. wType = rhs.wType;
  684. if ( rhs.pTypeInfo )
  685. {
  686. pTypeInfo = rhs.pTypeInfo;
  687. pTypeInfo->AddRef();
  688. }
  689. cbMaxLength = rhs.cbMaxLength;
  690. if ( rhs.pNum )
  691. {
  692. CDbNumeric * pTemp = new CDbNumeric( *rhs.pNum );
  693. if ( 0 == pTemp )
  694. {
  695. _Cleanup();
  696. return FALSE;
  697. }
  698. }
  699. dwFlags = rhs.dwFlags;
  700. return TRUE;
  701. }
  702. CDbProp::~CDbProp()
  703. {
  704. Cleanup();
  705. }
  706. void CDbProp::Cleanup()
  707. {
  708. ((CDbColId &)colid).Cleanup( );
  709. //
  710. // In their infinite wisdom, the OLE-DB headers are #pragma pack(2)
  711. // which can mess up the alignment of this Variant.
  712. //
  713. #if (_X86_ == 1)
  714. CStorageVariant * pVarnt = CastToStorageVariant( vValue );
  715. pVarnt->SetEMPTY();
  716. #else
  717. CStorageVariant * pVarnt = CastToStorageVariant( vValue );
  718. if ( (((ULONG_PTR)pVarnt) & 0x7) == 0 )
  719. pVarnt->SetEMPTY();
  720. else
  721. {
  722. VARIANT var;
  723. Win4Assert( sizeof(var) == sizeof(CStorageVariant) );
  724. RtlCopyMemory( &var, pVarnt, sizeof(var) );
  725. ((CStorageVariant *)&var)->SetEMPTY();
  726. RtlCopyMemory( pVarnt, &var, sizeof(var) );
  727. }
  728. #endif
  729. }
  730. CDbPropSet::~CDbPropSet()
  731. {
  732. if (rgProperties)
  733. {
  734. for (unsigned i=0; i<cProperties; i++)
  735. GetProperty(i)->Cleanup();
  736. deleteOLE(rgProperties);
  737. }
  738. }
  739. CDbPropIDSet::~CDbPropIDSet()
  740. {
  741. deleteOLE(rgPropertyIDs);
  742. }
  743. BOOL CDbPropIDSet::Copy( const DBPROPIDSET & rhs )
  744. {
  745. if ( cPropertyIDs )
  746. {
  747. deleteOLE(rgPropertyIDs);
  748. rgPropertyIDs = 0;
  749. cPropertyIDs = 0;
  750. }
  751. guidPropertySet = rhs.guidPropertySet;
  752. if ( rhs.cPropertyIDs )
  753. {
  754. XArrayOLE<DBPROPID> aPropId;
  755. aPropId.InitNoThrow( rhs.cPropertyIDs );
  756. if ( aPropId.IsNull() )
  757. return FALSE;
  758. RtlCopyMemory( aPropId.GetPointer(), rhs.rgPropertyIDs,
  759. rhs.cPropertyIDs * sizeof DBPROPID );
  760. rgPropertyIDs = aPropId.Acquire();
  761. cPropertyIDs = rhs.cPropertyIDs;
  762. }
  763. return TRUE;
  764. }
  765. //+---------------------------------------------------------------------------
  766. //
  767. // Member: CDbPropSet::Marshall
  768. //
  769. // Synopsis:
  770. //
  771. // Arguments: [stm] -
  772. //
  773. // History: 11-17-95 srikants Created
  774. //
  775. //----------------------------------------------------------------------------
  776. void CDbPropSet::Marshall( PSerStream & stm ) const
  777. {
  778. stm.PutBlob( (BYTE *) &guidPropertySet, sizeof(guidPropertySet) );
  779. stm.PutULong( cProperties );
  780. for (unsigned i=0; i<cProperties; i++)
  781. GetProperty(i)->Marshall( stm );
  782. }
  783. //+---------------------------------------------------------------------------
  784. //
  785. // Member: CDbPropSet::UnMarshall
  786. //
  787. // Synopsis: Unmarshalls the object from a stream
  788. //
  789. // Arguments: [stm] -- The stream from which the object is unmarshalled
  790. //
  791. // Returns: TRUE if successful; FALSE o/w
  792. //
  793. // History: 11-17-95 srikants Created
  794. //
  795. //----------------------------------------------------------------------------
  796. BOOL CDbPropSet::UnMarshall( PDeSerStream & stm )
  797. {
  798. stm.GetBlob( (BYTE *) &guidPropertySet, sizeof(guidPropertySet) );
  799. cProperties = stm.GetULong();
  800. // Guard against attack
  801. if ( cProperties > 100 )
  802. return FALSE;
  803. XArrayOLE<DBPROP> xDbProp;
  804. xDbProp.InitNoThrow( cProperties );
  805. if ( xDbProp.IsNull() )
  806. return FALSE;
  807. CDbProp * pProps = (CDbProp *) xDbProp.Get();
  808. BOOL fStatus = TRUE;
  809. unsigned cOk = 0;
  810. for (unsigned i=0; fStatus && i < cProperties; i++)
  811. {
  812. fStatus = pProps[i].UnMarshall( stm );
  813. if ( fStatus )
  814. cOk++;
  815. }
  816. if (fStatus)
  817. {
  818. rgProperties = pProps;
  819. xDbProp.Acquire();
  820. }
  821. else
  822. {
  823. for ( i = 0; i < cOk; i++ )
  824. pProps[i].Cleanup();
  825. cProperties = 0;
  826. rgProperties = 0;
  827. }
  828. return fStatus;
  829. } //UnMarshall
  830. //+---------------------------------------------------------------------------
  831. //
  832. // Member: CDbProp::Marshall
  833. //
  834. // Synopsis:
  835. //
  836. // Arguments: [stm] -
  837. //
  838. // History: 11-17-95 srikants Created
  839. //
  840. //----------------------------------------------------------------------------
  841. void CDbProp::Marshall( PSerStream & stm ) const
  842. {
  843. stm.PutULong( dwPropertyID );
  844. stm.PutULong( dwOptions );
  845. stm.PutULong( dwStatus );
  846. ((CDbColId &)colid).Marshall( stm );
  847. CStorageVariant const * pVarnt = CastToStorageVariant( vValue );
  848. //
  849. // In their infinite wisdom, the OLE-DB headers are #pragma pack(2)
  850. // which can mess up the alignment of this Variant.
  851. //
  852. #if (_X86_ == 1)
  853. pVarnt->Marshall( stm );
  854. #else
  855. if ( (((ULONG_PTR)pVarnt) & 0x7) == 0 )
  856. pVarnt->Marshall( stm );
  857. else
  858. {
  859. VARIANT var;
  860. RtlCopyMemory( &var, pVarnt, sizeof(var) );
  861. ((CStorageVariant *)&var)->Marshall( stm );
  862. }
  863. #endif
  864. } //Marshall
  865. //+---------------------------------------------------------------------------
  866. //
  867. // Member: CDbProp::UnMarshall
  868. //
  869. // Synopsis:
  870. //
  871. // Arguments: [stm] -
  872. //
  873. // Returns: TRUE if successful; FALSE o/w
  874. //
  875. // History: 11-17-95 srikants Created
  876. //
  877. // Notes:
  878. //
  879. //----------------------------------------------------------------------------
  880. BOOL CDbProp::UnMarshall( PDeSerStream & stm )
  881. {
  882. dwPropertyID = stm.GetULong( );
  883. dwOptions = stm.GetULong( );
  884. dwStatus = stm.GetULong( );
  885. ((CDbColId &)colid).Cleanup();
  886. if ( !((CDbColId &)colid).UnMarshall( stm ) )
  887. return FALSE;
  888. //
  889. // The OLE-DB headers are #pragma pack(2), which can mess up the
  890. // alignment of this Variant. As a work-around, unmarshall into a
  891. // variant on the stack, then copy the bytes over to vVariant.
  892. //
  893. CStorageVariant temp( stm );
  894. if ( !temp.IsValid() )
  895. return FALSE;
  896. RtlCopyMemory( &vValue, &temp, sizeof VARIANT );
  897. RtlZeroMemory( &temp, sizeof temp );
  898. return TRUE;
  899. } //UnMarshall
  900. //+---------------------------------------------------------------------------
  901. //
  902. // Member: CDbPropSet::Copy
  903. //
  904. // Synopsis: Copies a prop set
  905. //
  906. // Arguments: [rhs] - the source prop set
  907. //
  908. // Returns: TRUE if successful, FALSE otherwise
  909. //
  910. // History: 11-21-95 srikants Created
  911. //
  912. //----------------------------------------------------------------------------
  913. BOOL CDbPropSet::Copy( const DBPROPSET & rhs )
  914. {
  915. //
  916. // Cleanup existing properties.
  917. //
  918. if ( rgProperties )
  919. {
  920. for (unsigned i=0; i<cProperties; i++)
  921. GetProperty(i)->Cleanup();
  922. deleteOLE(rgProperties);
  923. rgProperties = 0;
  924. }
  925. guidPropertySet = rhs.guidPropertySet;
  926. cProperties = rhs.cProperties;
  927. if (cProperties == 0)
  928. return TRUE;
  929. XArrayOLE<DBPROP> xDbProp;
  930. xDbProp.InitNoThrow( cProperties );
  931. if ( xDbProp.IsNull() )
  932. return FALSE;
  933. CDbProp * pProps = (CDbProp *) xDbProp.Get();
  934. BOOL fStatus = TRUE;
  935. ULONG cOk = 0;
  936. for (unsigned i=0; fStatus && i<cProperties; i++)
  937. {
  938. fStatus = pProps[i].Copy( rhs.rgProperties[i] );
  939. if ( fStatus )
  940. cOk++;
  941. }
  942. if (fStatus)
  943. {
  944. rgProperties = pProps;
  945. xDbProp.Acquire();
  946. }
  947. else
  948. {
  949. for ( i = 0; i < cOk; i++ )
  950. pProps[ i ].Cleanup();
  951. cProperties = 0;
  952. rgProperties = 0;
  953. }
  954. return fStatus;
  955. }
  956. //+---------------------------------------------------------------------------
  957. //
  958. // Member: CDbProp::Copy
  959. //
  960. // Synopsis:
  961. //
  962. // Arguments: [rhs] -
  963. //
  964. // Returns:
  965. //
  966. // History: 11-21-95 srikants Created
  967. //
  968. //----------------------------------------------------------------------------
  969. #if CIDBG == 1
  970. LONG g_cDbPropCopies = 0;
  971. #endif
  972. BOOL CDbProp::Copy( const DBPROP & rhs )
  973. {
  974. #if CIDBG == 1
  975. g_cDbPropCopies++;
  976. #endif
  977. dwPropertyID = rhs.dwPropertyID;
  978. dwOptions = rhs.dwOptions;
  979. dwStatus = rhs.dwStatus;
  980. #if (_X86_ == 1)
  981. BOOL fOK = ((CDbColId &) colid).Copy( rhs.colid );
  982. if ( !fOK )
  983. return FALSE;
  984. * CastToStorageVariant( vValue ) = * CastToStorageVariant( rhs.vValue );
  985. return CastToStorageVariant( vValue )->IsValid();
  986. #else
  987. // rhs.colid is NOT 8 Byte aligned
  988. DBID rhsDbId, lhsDbId;
  989. RtlCopyMemory( &rhsDbId, &rhs.colid, sizeof DBID );
  990. RtlCopyMemory( &lhsDbId, &colid, sizeof DBID );
  991. BOOL fOK = ((CDbColId &)lhsDbId).Copy( rhsDbId );
  992. RtlCopyMemory( &colid, &lhsDbId, sizeof DBID );
  993. if ( !fOK )
  994. return FALSE;
  995. // vValue is not 8 Byte aligned
  996. VARIANT lhsVar, rhsVar;
  997. RtlCopyMemory( &rhsVar, &rhs.vValue, sizeof VARIANT );
  998. RtlCopyMemory( &lhsVar, &vValue, sizeof VARIANT );
  999. CStorageVariant * pLeft = CastToStorageVariant( lhsVar );
  1000. CStorageVariant const * pRight = CastToStorageVariant( rhsVar );
  1001. *pLeft = *pRight;
  1002. RtlCopyMemory( &vValue, &lhsVar, sizeof VARIANT );
  1003. return pLeft->IsValid();
  1004. #endif
  1005. } //Copy
  1006. //+---------------------------------------------------------------------------
  1007. //
  1008. // Member: CDbContentVector::Marshall
  1009. //
  1010. // Synopsis:
  1011. //
  1012. // Arguments: [stm] -
  1013. //
  1014. // History: 11-17-95 srikants Created
  1015. //
  1016. // Notes:
  1017. //
  1018. //----------------------------------------------------------------------------
  1019. void CDbContentVector::Marshall( PSerStream & stm ) const
  1020. {
  1021. Win4Assert( !"Not Yet Implemented" );
  1022. }
  1023. //+---------------------------------------------------------------------------
  1024. //
  1025. // Member: CDbContentVector::UnMarshall
  1026. //
  1027. // Synopsis:
  1028. //
  1029. // Arguments: [stm] -
  1030. //
  1031. // Returns: TRUE if successful; FALSE o/w
  1032. //
  1033. // History: 11-17-95 srikants Created
  1034. //
  1035. // Notes:
  1036. //
  1037. //----------------------------------------------------------------------------
  1038. BOOL CDbContentVector::UnMarshall( PDeSerStream & stm )
  1039. {
  1040. Win4Assert( !"Not Yet Implemented" );
  1041. return TRUE;
  1042. }
  1043. //+---------------------------------------------------------------------------
  1044. //
  1045. // Member: CDbNumeric::Marshall
  1046. //
  1047. // Synopsis:
  1048. //
  1049. // Arguments: [stm] -
  1050. //
  1051. // History: 11-17-95 srikants Created
  1052. //
  1053. // Notes:
  1054. //
  1055. //----------------------------------------------------------------------------
  1056. void CDbNumeric::Marshall( PSerStream & stm ) const
  1057. {
  1058. stm.PutByte( precision );
  1059. stm.PutByte( scale );
  1060. stm.PutByte( sign );
  1061. stm.PutBlob( (BYTE *) &val[0], sizeof(val) );
  1062. }
  1063. //+---------------------------------------------------------------------------
  1064. //
  1065. // Member: CDbNumeric::UnMarshall
  1066. //
  1067. // Synopsis:
  1068. //
  1069. // Arguments: [stm] -
  1070. //
  1071. // Returns: TRUE if successful; FALSE o/w
  1072. //
  1073. // History: 11-17-95 srikants Created
  1074. //
  1075. // Notes:
  1076. //
  1077. //----------------------------------------------------------------------------
  1078. BOOL CDbNumeric::UnMarshall( PDeSerStream & stm )
  1079. {
  1080. precision = stm.GetByte();
  1081. scale = stm.GetByte();
  1082. sign = stm.GetByte();
  1083. stm.GetBlob( (BYTE *) &val[0], sizeof(val) );
  1084. return TRUE;
  1085. }