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.

241 lines
7.0 KiB

  1. //---------------------------------------------------------------------------
  2. // ColumnUpdate.cpp : ColumnUpdate implementation
  3. //
  4. // Copyright (c) 1996 Microsoft Corporation, All Rights Reserved
  5. // Developed by Sheridan Software Systems, Inc.
  6. //---------------------------------------------------------------------------
  7. #include "stdafx.h"
  8. #include "stdafx.h"
  9. #include "Notifier.h"
  10. #include "RSColumn.h"
  11. #include "RSSource.h"
  12. #include "CursMain.h"
  13. #include "CursBase.h"
  14. #include "ColUpdat.h"
  15. #include "resource.h"
  16. SZTHISFILE
  17. //=--------------------------------------------------------------------------=
  18. // CVDColumnUpdate - Constructor
  19. //
  20. CVDColumnUpdate::CVDColumnUpdate()
  21. {
  22. m_dwRefCount = 1;
  23. m_pColumn = NULL;
  24. m_cbVarDataLen = 0;
  25. m_dwInfo = 0;
  26. VariantInit((VARIANT*)&m_variant);
  27. #ifdef _DEBUG
  28. g_cVDColumnUpdateCreated++;
  29. #endif
  30. }
  31. //=--------------------------------------------------------------------------=
  32. // ~CVDColumnUpdate - Destructor
  33. //
  34. CVDColumnUpdate::~CVDColumnUpdate()
  35. {
  36. VariantClear((VARIANT*)&m_variant);
  37. #ifdef _DEBUG
  38. g_cVDColumnUpdateDestroyed++;
  39. #endif
  40. }
  41. //=--------------------------------------------------------------------------=
  42. // ExtractVariant - Extract variant
  43. //=--------------------------------------------------------------------------=
  44. // This function extracts a variant from update update data
  45. //
  46. // Parameters:
  47. // pBindParams - [in] a pointer to column update data
  48. // pVariant - [out] a pointer a variant where to return data
  49. //
  50. // Output:
  51. // HRESULT - S_OK if successful
  52. // E_OUTOFMEMORY not enough memory to create object
  53. //
  54. // Notes:
  55. //
  56. HRESULT CVDColumnUpdate::ExtractVariant(CURSOR_DBBINDPARAMS * pBindParams, CURSOR_DBVARIANT * pVariant)
  57. {
  58. ASSERT_POINTER(pBindParams, CURSOR_DBBINDPARAMS)
  59. ASSERT_POINTER(pVariant, CURSOR_DBVARIANT)
  60. // make sure we have all necessary pointers
  61. if (!pBindParams || !pBindParams->pData || !pVariant)
  62. return E_INVALIDARG;
  63. CURSOR_DBVARIANT varTemp;
  64. // initialize all variants
  65. VariantInit((VARIANT*)&varTemp);
  66. VariantInit((VARIANT*)pVariant);
  67. // create temporary variant from supplied data
  68. if (pBindParams->dwBinding & CURSOR_DBBINDING_VARIANT)
  69. {
  70. varTemp = *(CURSOR_DBVARIANT*)pBindParams->pData;
  71. }
  72. else // extract variant from default binding
  73. {
  74. BYTE * pData = (BYTE*)pBindParams->pData;
  75. varTemp.vt = (VARTYPE)pBindParams->dwDataType;
  76. switch (pBindParams->dwDataType)
  77. {
  78. case CURSOR_DBTYPE_BYTES:
  79. varTemp.vt = CURSOR_DBTYPE_BLOB;
  80. varTemp.blob.cbSize = *(ULONG*)pData;
  81. varTemp.blob.pBlobData = (BYTE*)(pData + sizeof(ULONG));
  82. break;
  83. case CURSOR_DBTYPE_CHARS:
  84. varTemp.vt = CURSOR_DBTYPE_LPSTR;
  85. varTemp.pszVal = (CHAR*)pData;
  86. break;
  87. case CURSOR_DBTYPE_WCHARS:
  88. varTemp.vt = CURSOR_DBTYPE_LPWSTR;
  89. varTemp.pwszVal = (WCHAR*)pData;
  90. break;
  91. case CURSOR_DBTYPE_BLOB:
  92. varTemp.blob.cbSize = *(ULONG*)pData;
  93. varTemp.blob.pBlobData = *(LPBYTE*)(pData + sizeof(ULONG));
  94. break;
  95. case CURSOR_DBTYPE_LPSTR:
  96. varTemp.pszVal = *(LPSTR*)pData;
  97. break;
  98. case CURSOR_DBTYPE_LPWSTR:
  99. varTemp.pwszVal = *(LPWSTR*)pData;
  100. break;
  101. default:
  102. memcpy(&varTemp.cyVal, pBindParams->pData, CVDCursorBase::GetCursorTypeLength(varTemp.vt, 0));
  103. break;
  104. }
  105. }
  106. HRESULT hr = S_OK;
  107. // convert temporary variant to a desirable type and return
  108. switch (varTemp.vt)
  109. {
  110. case CURSOR_DBTYPE_LPSTR:
  111. pVariant->vt = VT_BSTR;
  112. pVariant->bstrVal = BSTRFROMANSI(varTemp.pszVal);
  113. break;
  114. case CURSOR_DBTYPE_LPWSTR:
  115. pVariant->vt = VT_BSTR;
  116. pVariant->bstrVal = SysAllocString(varTemp.pwszVal);
  117. break;
  118. default:
  119. hr = VariantCopy((VARIANT*)pVariant, (VARIANT*)&varTemp);
  120. break;
  121. }
  122. return hr;
  123. }
  124. //=--------------------------------------------------------------------------=
  125. // Create - Create column update object
  126. //=--------------------------------------------------------------------------=
  127. // This function creates and initializes a new column update object
  128. //
  129. // Parameters:
  130. // pColumn - [in] rowset column pointer
  131. // pBindParams - [in] a pointer to column update data
  132. // ppColumnUpdate - [out] a pointer in which to return pointer to
  133. // column update object
  134. // pResourceDLL - [in] a pointer which keeps track of resource DLL
  135. //
  136. // Output:
  137. // HRESULT - S_OK if successful
  138. // E_OUTOFMEMORY not enough memory to create object
  139. //
  140. // Notes:
  141. //
  142. HRESULT CVDColumnUpdate::Create(CVDRowsetColumn * pColumn, CURSOR_DBBINDPARAMS * pBindParams,
  143. CVDColumnUpdate ** ppColumnUpdate, CVDResourceDLL * pResourceDLL)
  144. {
  145. ASSERT_POINTER(pColumn, CVDRowsetColumn)
  146. ASSERT_POINTER(pBindParams, CURSOR_DBBINDPARAMS)
  147. ASSERT_POINTER(ppColumnUpdate, CVDColumnUpdate)
  148. // make sure we have all necessary pointers
  149. if (!pColumn || !pBindParams || !pBindParams->pData || !ppColumnUpdate)
  150. {
  151. VDSetErrorInfo(IDS_ERR_INVALIDARG, IID_ICursorUpdateARow, pResourceDLL);
  152. return E_INVALIDARG;
  153. }
  154. // init out parameter
  155. *ppColumnUpdate = NULL;
  156. // create new column update object
  157. CVDColumnUpdate * pColumnUpdate = new CVDColumnUpdate();
  158. if (!pColumnUpdate)
  159. {
  160. VDSetErrorInfo(IDS_ERR_OUTOFMEMORY, IID_ICursorUpdateARow, pResourceDLL);
  161. return E_OUTOFMEMORY;
  162. }
  163. CURSOR_DBVARIANT variant;
  164. // extract a variant from update data
  165. HRESULT hr = ExtractVariant(pBindParams, &variant);
  166. if (FAILED(hr))
  167. {
  168. // destroy object
  169. delete pColumnUpdate;
  170. VDSetErrorInfo(IDS_ERR_INVALIDARG, IID_ICursorUpdateARow, pResourceDLL);
  171. return E_INVALIDARG;
  172. }
  173. // store update information
  174. pColumnUpdate->m_pColumn = pColumn;
  175. pColumnUpdate->m_variant = variant;
  176. pColumnUpdate->m_cbVarDataLen = pBindParams->cbVarDataLen;
  177. pColumnUpdate->m_dwInfo = pBindParams->dwInfo;
  178. pColumnUpdate->m_pResourceDLL = pResourceDLL;
  179. // we're done
  180. *ppColumnUpdate = pColumnUpdate;
  181. return S_OK;
  182. }
  183. //=--------------------------------------------------------------------------=
  184. // AddRef
  185. //
  186. ULONG CVDColumnUpdate::AddRef(void)
  187. {
  188. return ++m_dwRefCount;
  189. }
  190. //=--------------------------------------------------------------------------=
  191. // Release
  192. //
  193. ULONG CVDColumnUpdate::Release(void)
  194. {
  195. if (1 > --m_dwRefCount)
  196. {
  197. delete this;
  198. return 0;
  199. }
  200. return m_dwRefCount;
  201. }