AGCDBParams.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /////////////////////////////////////////////////////////////////////////////
  2. // AGCDBParams.cpp : Implementation of the CAGCDBParams class.
  3. //
  4. #include "pch.h"
  5. #include "AGCDBParams.h"
  6. /////////////////////////////////////////////////////////////////////////////
  7. // CAGCDBParams
  8. TC_OBJECT_EXTERN_IMPL(CAGCDBParams)
  9. /////////////////////////////////////////////////////////////////////////////
  10. // IAGCDBParams Interface Methods
  11. STDMETHODIMP CAGCDBParams::put_ConnectionString(BSTR bstr)
  12. {
  13. XLock lock(this);
  14. m_bstrConnectionString = bstr;
  15. m_bDirty = true;
  16. return S_OK;
  17. }
  18. STDMETHODIMP CAGCDBParams::get_ConnectionString(BSTR* pbstr)
  19. {
  20. CLEAROUT(pbstr, (BSTR)NULL);
  21. XLock lock(this);
  22. *pbstr = m_bstrConnectionString.Copy();
  23. return S_OK;
  24. }
  25. STDMETHODIMP CAGCDBParams::put_TableName(BSTR bstr)
  26. {
  27. XLock lock(this);
  28. m_bstrTableName = bstr;
  29. m_bDirty = true;
  30. return S_OK;
  31. }
  32. STDMETHODIMP CAGCDBParams::get_TableName(BSTR* pbstr)
  33. {
  34. CLEAROUT(pbstr, (BSTR)NULL);
  35. XLock lock(this);
  36. *pbstr = m_bstrTableName.Copy();
  37. return S_OK;
  38. }
  39. /////////////////////////////////////////////////////////////////////////////
  40. // IPersist Interface Methods
  41. STDMETHODIMP CAGCDBParams::GetClassID(CLSID* pClassID)
  42. {
  43. __try
  44. {
  45. *pClassID = GetObjectCLSID();
  46. }
  47. __except(1)
  48. {
  49. return E_POINTER;
  50. }
  51. return S_OK;
  52. }
  53. /////////////////////////////////////////////////////////////////////////////
  54. // IPersistStreamInit Interface Methods
  55. STDMETHODIMP CAGCDBParams::IsDirty()
  56. {
  57. // Return dirty flag
  58. XLock lock(this);
  59. return m_bDirty ? S_OK : S_FALSE;
  60. }
  61. STDMETHODIMP CAGCDBParams::Load(LPSTREAM pStm)
  62. {
  63. XLock lock(this);
  64. // Read each string from the stream
  65. m_bstrConnectionString.Empty();
  66. m_bstrTableName.Empty();
  67. RETURN_FAILED(m_bstrConnectionString.ReadFromStream(pStm));
  68. RETURN_FAILED(m_bstrTableName.ReadFromStream(pStm));
  69. // Set the dirty flag
  70. m_bDirty = true;
  71. // Indicate success
  72. return S_OK;
  73. }
  74. STDMETHODIMP CAGCDBParams::Save(LPSTREAM pStm, BOOL fClearDirty)
  75. {
  76. XLock lock(this);
  77. // Write each string to the stream
  78. RETURN_FAILED(m_bstrConnectionString.WriteToStream(pStm));
  79. RETURN_FAILED(m_bstrTableName.WriteToStream(pStm));
  80. // Clear the dirty flag, if specified
  81. if (fClearDirty)
  82. m_bDirty = false;
  83. // Indicate success
  84. return S_OK;
  85. }
  86. STDMETHODIMP CAGCDBParams::GetSizeMax(ULARGE_INTEGER* pCbSize)
  87. {
  88. XLock lock(this);
  89. return TCGetPersistStreamSize(GetUnknown(), pCbSize);
  90. }
  91. STDMETHODIMP CAGCDBParams::InitNew( void)
  92. {
  93. XLock lock(this);
  94. // Initialize the strings
  95. m_bstrConnectionString.Empty();
  96. m_bstrTableName.Empty();
  97. // Indicate success
  98. return S_OK;
  99. }
  100. /////////////////////////////////////////////////////////////////////////////
  101. // IPersistPropertyBag Interface Methods
  102. STDMETHODIMP CAGCDBParams::Load(IPropertyBag* pPropBag, IErrorLog* pErrorLog)
  103. {
  104. // Load each string
  105. VARIANT varConnectionString, varTableName;
  106. RETURN_FAILED(pPropBag->Read(L"ConnectionString", &varConnectionString, pErrorLog));
  107. RETURN_FAILED(pPropBag->Read(L"TableName" , &varTableName , pErrorLog));
  108. // Attach the variants to the strings
  109. // Note: Do NOT call VariantClear since ownership is given to the strings
  110. XLock lock(this);
  111. m_bstrConnectionString.Empty();
  112. m_bstrConnectionString.Attach(V_BSTR(&varConnectionString));
  113. m_bstrTableName.Empty();
  114. m_bstrTableName.Attach(V_BSTR(&varTableName));
  115. // Set the dirty flag
  116. m_bDirty = true;
  117. // Indicate success
  118. return S_OK;
  119. }
  120. STDMETHODIMP CAGCDBParams::Save(IPropertyBag* pPropBag, BOOL fClearDirty, BOOL)
  121. {
  122. XLock lock(this);
  123. // Save each string
  124. RETURN_FAILED(pPropBag->Write(L"ConnectionString", &CComVariant(m_bstrConnectionString)));
  125. RETURN_FAILED(pPropBag->Write(L"TableName" , &CComVariant(m_bstrTableName )));
  126. // Clear the dirty flag, if specified
  127. if (fClearDirty)
  128. m_bDirty = false;
  129. // Indicate success
  130. return S_OK;
  131. }