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.

381 lines
13 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright(C) 2000 Microsoft Corporation all rights reserved.
  4. //
  5. // Module: Properties.cpp
  6. //
  7. // Project: Windows 2000 IAS
  8. //
  9. // Description: Implementation of the CProperties class
  10. //
  11. // Author: tperraut
  12. //
  13. // Revision 02/24/2000 created
  14. //
  15. /////////////////////////////////////////////////////////////////////////////
  16. #include "stdafx.h"
  17. #include "Properties.h"
  18. //////////////////////////////////////////////////////////////////////////
  19. // class CProperties
  20. //////////////////////////////////////////////////////////////////////////
  21. //Constructor
  22. //////////////
  23. CProperties::CProperties(CSession& SessionParam)
  24. :m_PropertiesCommandGet(SessionParam),
  25. m_PropertiesCommandGetByName(SessionParam),
  26. m_PropertiesCommandInsert(SessionParam),
  27. m_PropertiesCommandDelete(SessionParam),
  28. m_PropertiesCommandDeleteMultiple(SessionParam)
  29. {
  30. };
  31. //////////////
  32. // Destructor
  33. //////////////
  34. CProperties::~CProperties()
  35. {
  36. };
  37. ///////////////
  38. // GetProperty
  39. ///////////////
  40. HRESULT CProperties::GetProperty(
  41. LONG Bag,
  42. _bstr_t& Name,
  43. LONG& Type,
  44. _bstr_t& StrVal
  45. )
  46. {
  47. return m_PropertiesCommandGet.GetProperty(
  48. Bag,
  49. Name,
  50. Type,
  51. StrVal
  52. );
  53. }
  54. ///////////////////
  55. // GetNextProperty
  56. ///////////////////
  57. HRESULT CProperties::GetNextProperty(
  58. LONG Bag,
  59. _bstr_t& Name,
  60. LONG& Type,
  61. _bstr_t& StrVal,
  62. LONG Index
  63. )
  64. {
  65. return m_PropertiesCommandGet.GetProperty(
  66. Bag,
  67. Name,
  68. Type,
  69. StrVal,
  70. Index
  71. );
  72. }
  73. /////////////////////
  74. // GetPropertyByName
  75. /////////////////////
  76. HRESULT CProperties::GetPropertyByName(
  77. LONG Bag,
  78. const _bstr_t& Name,
  79. LONG& Type,
  80. _bstr_t& StrVal
  81. )
  82. {
  83. return m_PropertiesCommandGetByName.GetPropertyByName(
  84. Bag,
  85. Name,
  86. Type,
  87. StrVal
  88. );
  89. }
  90. //////////////////////////////////
  91. // InsertProperty
  92. // throw an exception if it fails
  93. //////////////////////////////////
  94. void CProperties::InsertProperty(
  95. LONG Bag,
  96. const _bstr_t& Name,
  97. LONG Type,
  98. const _bstr_t& StrVal
  99. )
  100. {
  101. m_PropertiesCommandInsert.InsertProperty(
  102. Bag,
  103. Name,
  104. Type,
  105. StrVal
  106. );
  107. }
  108. //////////////////////////////////
  109. // DeleteProperty
  110. // throw an exception if it fails
  111. //////////////////////////////////
  112. void CProperties::DeleteProperty(
  113. LONG Bag,
  114. const _bstr_t& Name
  115. )
  116. {
  117. m_PropertiesCommandDelete.DeleteProperty(
  118. Bag,
  119. Name
  120. );
  121. }
  122. //////////////////////////
  123. // DeletePropertiesExcept
  124. //////////////////////////
  125. void CProperties::DeletePropertiesExcept(
  126. LONG Bag,
  127. const _bstr_t& Exception
  128. )
  129. {
  130. m_PropertiesCommandDeleteMultiple.DeletePropertiesExcept(Bag, Exception);
  131. }
  132. ///////////////////////////////////////////////////
  133. // UpdateProperty
  134. // throw an exception if it fails
  135. // Improvement possible: create a SQL statement
  136. // to update instead of doing a delete then insert
  137. ///////////////////////////////////////////////////
  138. void CProperties::UpdateProperty(
  139. LONG Bag,
  140. const _bstr_t& Name,
  141. LONG Type,
  142. const _bstr_t& StrVal
  143. )
  144. {
  145. try
  146. {
  147. m_PropertiesCommandDelete.DeleteProperty(
  148. Bag,
  149. Name
  150. );
  151. }
  152. catch(...)
  153. {
  154. // ignore the failure. If delete fails but insert works, that's ok
  155. }
  156. m_PropertiesCommandInsert.InsertProperty(
  157. Bag,
  158. Name,
  159. Type,
  160. StrVal
  161. );
  162. }
  163. //////////////////////////////////////////////////////////////////////////////
  164. // class CPropertiesCommandGet
  165. //////////////////////////////////////////////////////////////////////////////
  166. CProperties::CPropertiesCommandGet::CPropertiesCommandGet(
  167. CSession& CurrentSession
  168. )
  169. {
  170. Init(CurrentSession);
  171. };
  172. ///////////////
  173. // GetProperty
  174. ///////////////
  175. HRESULT CProperties::CPropertiesCommandGet::GetProperty(
  176. LONG Bag,
  177. _bstr_t& Name,
  178. LONG& Type,
  179. _bstr_t& StrVal
  180. )
  181. {
  182. m_BagParam = Bag;
  183. HRESULT hr = BaseExecute();
  184. if ( SUCCEEDED(hr) )
  185. {
  186. Name = m_Name;
  187. Type = m_Type;
  188. StrVal = m_StrVal;
  189. }
  190. return hr;
  191. }
  192. //////////////////////////
  193. // GetProperty overloaded
  194. //////////////////////////
  195. HRESULT CProperties::CPropertiesCommandGet::GetProperty(
  196. LONG Bag,
  197. _bstr_t& Name,
  198. LONG& Type,
  199. _bstr_t& StrVal,
  200. LONG Index
  201. )
  202. {
  203. m_BagParam = Bag;
  204. HRESULT hr = BaseExecute(Index);
  205. if ( SUCCEEDED(hr) )
  206. {
  207. Name = m_Name;
  208. Type = m_Type;
  209. StrVal = m_StrVal;
  210. }
  211. return hr;
  212. }
  213. //////////////////////////////////////////////////////////////////////////////
  214. // class CPropertiesCommandGetByName
  215. //////////////////////////////////////////////////////////////////////////////
  216. CProperties::CPropertiesCommandGetByName::CPropertiesCommandGetByName(
  217. CSession& CurrentSession
  218. )
  219. {
  220. Init(CurrentSession);
  221. };
  222. //////////////////////
  223. // GetPropertyByName
  224. //////////////////////
  225. HRESULT CProperties::CPropertiesCommandGetByName::GetPropertyByName(
  226. LONG Bag,
  227. const _bstr_t& Name,
  228. LONG& Type,
  229. _bstr_t& StrVal
  230. )
  231. {
  232. m_BagParam = Bag;
  233. if ( Name.length() )
  234. {
  235. lstrcpynW(m_NameParam, Name, NAME_SIZE);
  236. }
  237. HRESULT hr = BaseExecute();
  238. if ( SUCCEEDED(hr) )
  239. {
  240. Type = m_Type;
  241. StrVal = m_StrVal;
  242. }
  243. return hr;
  244. };
  245. //////////////////////////////////////////////////////////////////////////////
  246. // class CPropertiesCommandInsert
  247. //////////////////////////////////////////////////////////////////////////////
  248. CProperties::CPropertiesCommandInsert::CPropertiesCommandInsert(
  249. CSession& CurrentSession
  250. )
  251. {
  252. Init(CurrentSession);
  253. }
  254. //////////////////
  255. // InsertProperty
  256. //////////////////
  257. void CProperties::CPropertiesCommandInsert::InsertProperty(
  258. LONG Bag,
  259. const _bstr_t& Name,
  260. LONG Type,
  261. const _bstr_t& StrVal
  262. )
  263. {
  264. ClearRecord();
  265. m_BagParam = Bag;
  266. if ( Name.length() )
  267. {
  268. lstrcpynW(m_NameParam, Name, NAME_SIZE);
  269. }
  270. m_TypeParam = Type;
  271. if ( StrVal.length() )
  272. {
  273. lstrcpynW(m_StrValParam, StrVal, STRVAL_SIZE);
  274. }
  275. CDBPropSet propset(DBPROPSET_ROWSET);
  276. propset.AddProperty(DBPROP_IRowsetChange, true);
  277. propset.AddProperty(DBPROP_UPDATABILITY, DBPROPVAL_UP_CHANGE
  278. | DBPROPVAL_UP_INSERT );
  279. _com_util::CheckError(Open(&propset));
  280. Close();
  281. }
  282. //////////////////////////////////////////////////////////////////////////////
  283. // class CPropertiesCommandDelete
  284. //////////////////////////////////////////////////////////////////////////////
  285. CProperties::CPropertiesCommandDelete::CPropertiesCommandDelete(
  286. CSession& CurrentSession
  287. )
  288. {
  289. Init(CurrentSession);
  290. }
  291. //////////////////
  292. // DeleteProperty
  293. //////////////////
  294. void CProperties::CPropertiesCommandDelete::DeleteProperty(
  295. LONG Bag,
  296. const _bstr_t& Name
  297. )
  298. {
  299. m_BagParam = Bag;
  300. lstrcpynW(m_NameParam, Name, NAME_SIZE);
  301. CDBPropSet propset(DBPROPSET_ROWSET);
  302. propset.AddProperty(DBPROP_IRowsetChange, true);
  303. propset.AddProperty(DBPROP_UPDATABILITY, DBPROPVAL_UP_CHANGE
  304. | DBPROPVAL_UP_DELETE );
  305. _com_util::CheckError(Open(&propset));
  306. Close();
  307. }
  308. //////////////////////////////////////////////////////////////////////////////
  309. // class CPropertiesCommandDeleteMultiple
  310. //////////////////////////////////////////////////////////////////////////////
  311. CProperties::CPropertiesCommandDeleteMultiple::
  312. CPropertiesCommandDeleteMultiple(CSession& CurrentSession)
  313. {
  314. Init(CurrentSession);
  315. }
  316. //////////////////
  317. // DeleteProperty
  318. //////////////////
  319. void CProperties::CPropertiesCommandDeleteMultiple::DeletePropertiesExcept(
  320. LONG Bag,
  321. const _bstr_t& Exception
  322. )
  323. {
  324. m_BagParam = Bag;
  325. lstrcpynW(m_ExceptionParam, Exception, SIZE_EXCEPTION_MAX);
  326. CDBPropSet propset(DBPROPSET_ROWSET);
  327. propset.AddProperty(DBPROP_IRowsetChange, true);
  328. propset.AddProperty(DBPROP_UPDATABILITY, DBPROPVAL_UP_CHANGE
  329. | DBPROPVAL_UP_DELETE );
  330. Open(&propset); // ignore the result
  331. Close();
  332. }