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.

377 lines
8.7 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Copyright (c) 1997-1999 Microsoft Corporation
  4. //
  5. // File: vertab.cpp
  6. //
  7. // Contents:
  8. //
  9. // History:
  10. //
  11. //---------------------------------------------------------------------------
  12. #include "version.h"
  13. LPCTSTR __VersionIndexOnVersionId::pszIndexName = VERSION_ID_INDEXNAME;
  14. LPCTSTR __VersionIndexOnVersionId::pszIndexKey = VERSION_ID_INDEXNAME_INDEXKEY;
  15. //----------------------------------------------------
  16. CCriticalSection VersionTable::g_TableLock;
  17. LPCTSTR VersionTable::pszTableName = VERSION_TABLE_NAME;
  18. //----------------------------------------------------
  19. TLSJBIndex
  20. VersionTable::g_TableIndex[] =
  21. {
  22. {
  23. VERSION_ID_INDEXNAME,
  24. VERSION_ID_INDEXNAME_INDEXKEY,
  25. -1,
  26. JET_bitIndexIgnoreNull,
  27. TLSTABLE_INDEX_DEFAULT_DENSITY
  28. }
  29. };
  30. int
  31. VersionTable::g_NumTableIndex = sizeof(VersionTable::g_TableIndex) / sizeof(VersionTable::g_TableIndex[0]);
  32. TLSJBColumn
  33. VersionTable::g_Columns[] =
  34. {
  35. {
  36. VERSION_TABLE_VERSION,
  37. JET_coltypLong,
  38. 0,
  39. JET_bitColumnFixed | JET_bitColumnNotNULL,
  40. NULL,
  41. 0,
  42. TLS_JETBLUE_COLUMN_CODE_PAGE,
  43. TLS_JETBLUE_COLUMN_COUNTRY_CODE,
  44. TLS_JETBLUE_COLUMN_LANGID
  45. },
  46. {
  47. VERSION_TABLE_DOMAINID,
  48. JET_coltypLongBinary,
  49. TLSTABLE_MAX_BINARY_LENGTH,
  50. 0,
  51. NULL,
  52. 0,
  53. TLS_JETBLUE_COLUMN_CODE_PAGE,
  54. TLS_JETBLUE_COLUMN_COUNTRY_CODE,
  55. TLS_JETBLUE_COLUMN_LANGID
  56. },
  57. {
  58. VERSION_TABLE_INSTALLID,
  59. JB_COLTYPE_TEXT,
  60. (MAX_JETBLUE_TEXT_LENGTH + 1)*sizeof(TCHAR),
  61. 0,
  62. JBSTRING_NULL,
  63. _tcslen(JBSTRING_NULL),
  64. TLS_JETBLUE_COLUMN_CODE_PAGE,
  65. TLS_JETBLUE_COLUMN_COUNTRY_CODE,
  66. TLS_JETBLUE_COLUMN_LANGID
  67. }
  68. };
  69. int
  70. VersionTable::g_NumColumns=sizeof(VersionTable::g_Columns) / sizeof(VersionTable::g_Columns[0]);
  71. //-------------------------------------------------------------
  72. JBKeyBase*
  73. VersionTable::EnumerationIndex(
  74. BOOL bMatchAll,
  75. DWORD dwSearchParam,
  76. TLSVersion* pVersion,
  77. BOOL* bCompareKey
  78. )
  79. /*
  80. */
  81. {
  82. // not expecting more than one row.
  83. *bCompareKey = (bMatchAll && (dwSearchParam & VERSION_TABLE_PROCESS_VERSION));
  84. return new TLSVersionIndexVersionId(pVersion);
  85. }
  86. //------------------------------------------------------------
  87. BOOL
  88. VersionTable::EqualValue(
  89. TLSVersion& s1,
  90. TLSVersion& s2,
  91. BOOL bMatchAll,
  92. DWORD dwParam
  93. )
  94. /*
  95. */
  96. {
  97. BOOL bRetCode = TRUE;
  98. if(dwParam & VERSION_TABLE_PROCESS_VERSION)
  99. {
  100. bRetCode = (s1.dwVersion == s2.dwVersion);
  101. if(bRetCode != bMatchAll)
  102. goto cleanup;
  103. }
  104. if(dwParam & VERSION_TABLE_PROCESS_INSTALLID)
  105. {
  106. bRetCode = (_tcscmp(s1.szInstallId, s2.szInstallId) == 0);
  107. if(bRetCode != bMatchAll)
  108. goto cleanup;
  109. }
  110. //if(dwParam & VERSION_TABLE_PROCESS_DOMAINID)
  111. //{
  112. // bRetCode = EqualSid(s1.pbDomainSid, s2.pbDomainSid);
  113. //}
  114. cleanup:
  115. return bRetCode;
  116. }
  117. //----------------------------------------------------
  118. BOOL
  119. VersionTable::ResolveToTableColumn()
  120. /*
  121. */
  122. {
  123. m_JetErr = dwVersion.AttachToTable(
  124. *this,
  125. VERSION_TABLE_VERSION
  126. );
  127. if(IsSuccess() == FALSE)
  128. {
  129. DebugOutput(
  130. _TEXT("Can't find column %s in table %s\n"),
  131. VERSION_TABLE_VERSION,
  132. GetTableName()
  133. );
  134. return FALSE;
  135. }
  136. m_JetErr = szInstallId.AttachToTable(
  137. *this,
  138. VERSION_TABLE_INSTALLID
  139. );
  140. if(IsSuccess() == FALSE)
  141. {
  142. DebugOutput(
  143. _TEXT("Can't find column %s in table %s\n"),
  144. VERSION_TABLE_INSTALLID,
  145. GetTableName()
  146. );
  147. return FALSE;
  148. }
  149. m_JetErr = pbDomainSid.AttachToTable(
  150. *this,
  151. VERSION_TABLE_DOMAINID
  152. );
  153. if(IsSuccess() == FALSE)
  154. {
  155. DebugOutput(
  156. _TEXT("Can't find column %s in table %s\n"),
  157. VERSION_TABLE_DOMAINID,
  158. GetTableName()
  159. );
  160. }
  161. return IsSuccess();
  162. }
  163. //----------------------------------------------------
  164. BOOL
  165. VersionTable::FetchRecord(
  166. TLSVersion& v,
  167. DWORD dwParam
  168. )
  169. /*
  170. */
  171. {
  172. if(dwParam & VERSION_TABLE_PROCESS_VERSION)
  173. {
  174. m_JetErr = dwVersion.FetchColumnValue(
  175. &(v.dwVersion),
  176. sizeof(v.dwVersion),
  177. 0,
  178. NULL
  179. );
  180. REPORT_IF_FETCH_FAILED(GetTableName(),
  181. VERSION_TABLE_VERSION,
  182. m_JetErr);
  183. if(IsSuccess() == FALSE)
  184. goto cleanup;
  185. }
  186. if(dwParam & VERSION_TABLE_PROCESS_INSTALLID)
  187. {
  188. m_JetErr = szInstallId.FetchColumnValue(
  189. v.szInstallId,
  190. sizeof(v.szInstallId),
  191. 0,
  192. NULL
  193. );
  194. REPORT_IF_FETCH_FAILED(
  195. GetTableName(),
  196. VERSION_TABLE_INSTALLID,
  197. m_JetErr
  198. );
  199. if(IsSuccess() == FALSE)
  200. goto cleanup;
  201. }
  202. #if 0
  203. if(dwParam & VERSION_TABLE_PROCESS_DOMAINID)
  204. {
  205. DWORD size;
  206. m_JetErr = pbDomainSid.FetchColumnValue(
  207. NULL,
  208. 0,
  209. 0,
  210. &size
  211. );
  212. if(size > v.cbDomainSid || v.pbDomainSid == NULL)
  213. {
  214. FreeMemory(v.pbDomainSid);
  215. v.pbDomainSid = (PBYTE)AllocateMemory(v.cbDomainSid = size);
  216. if(v.pbDomainSid == NULL)
  217. {
  218. SetLastJetError(JET_errOutOfMemory);
  219. goto cleanup;
  220. }
  221. }
  222. m_JetErr = pbDomainSid.FetchColumnValue(
  223. v.pbDomainSid,
  224. v.cbDomainSid,
  225. 0,
  226. &v.cbDomainSid
  227. );
  228. REPORT_IF_FETCH_FAILED(
  229. GetTableName(),
  230. VERSION_TABLE_DOMAINID,
  231. m_JetErr
  232. );
  233. }
  234. #endif
  235. cleanup:
  236. return IsSuccess();
  237. }
  238. //----------------------------------------------------
  239. BOOL
  240. VersionTable::InsertUpdateRecord(
  241. TLSVersion* v,
  242. DWORD dwParam
  243. )
  244. /*
  245. */
  246. {
  247. if(dwParam & VERSION_TABLE_PROCESS_VERSION)
  248. {
  249. m_JetErr = dwVersion.InsertColumnValue(
  250. &(v->dwVersion),
  251. sizeof(v->dwVersion),
  252. 0
  253. );
  254. REPORT_IF_INSERT_FAILED(GetTableName(),
  255. VERSION_TABLE_VERSION,
  256. m_JetErr);
  257. if(IsSuccess() == FALSE)
  258. goto cleanup;
  259. }
  260. if(dwParam & VERSION_TABLE_PROCESS_INSTALLID)
  261. {
  262. m_JetErr = szInstallId.InsertColumnValue(
  263. v->szInstallId,
  264. _tcslen(v->szInstallId) * sizeof(TCHAR),
  265. 0
  266. );
  267. REPORT_IF_INSERT_FAILED(
  268. GetTableName(),
  269. VERSION_TABLE_INSTALLID,
  270. m_JetErr
  271. );
  272. if(IsSuccess() == FALSE)
  273. goto cleanup;
  274. }
  275. #if 0
  276. // no more domain SID
  277. if(dwParam & VERSION_TABLE_PROCESS_DOMAINID)
  278. {
  279. m_JetErr = pbDomainSid.InsertColumnValue(
  280. v->pbDomainSid,
  281. v->cbDomainSid,
  282. 0
  283. );
  284. REPORT_IF_INSERT_FAILED(
  285. GetTableName(),
  286. VERSION_TABLE_DOMAINID,
  287. m_JetErr
  288. );
  289. }
  290. #endif
  291. cleanup:
  292. return IsSuccess();
  293. }
  294. //----------------------------------------------------
  295. BOOL
  296. VersionTable::InsertRecord(
  297. TLSVersion& v,
  298. DWORD dwParam
  299. )
  300. /*
  301. */
  302. {
  303. if(BeginUpdate(FALSE) == FALSE)
  304. return FALSE;
  305. InsertUpdateRecord(&v, dwParam);
  306. EndUpdate(IsSuccess() == FALSE);
  307. return IsSuccess();
  308. }
  309. //----------------------------------------------------
  310. BOOL
  311. VersionTable::UpdateRecord(
  312. TLSVersion& v,
  313. DWORD dwParam
  314. )
  315. /*
  316. */
  317. {
  318. if(BeginUpdate(TRUE) == FALSE)
  319. return FALSE;
  320. InsertUpdateRecord(&v, dwParam);
  321. EndUpdate(IsSuccess() == FALSE);
  322. return IsSuccess();
  323. }