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.

512 lines
13 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1996-1998
  5. //
  6. // File: kpdtab.cpp
  7. //
  8. // Contents: Licensed Pack Description Table
  9. //
  10. // History:
  11. //
  12. //---------------------------------------------------------------------------
  13. #include "KpDesc.h"
  14. LPCTSTR __JBKPDescIndexKeyPackId::pszIndexName = LICPACKDESCRECORD_ID_INDEXNAME;
  15. LPCTSTR __JBKPDescIndexKeyPackId::pszIndexKey = LICPACKDESCRECORD_ID_INDEXNAME_INDEXKEY;
  16. LPCTSTR __JBKPDescIndexKeyPackLangId::pszIndexName = LICPACKDESCRECORD_ID_LANGID_INDEXNAME;
  17. LPCTSTR __JBKPDescIndexKeyPackLangId::pszIndexKey = LICPACKDESCRECORD_ID_LANGID_INDEXNAME_INDEXKEY;
  18. LPCTSTR __LICPACKDESCRECORDIdxOnModifyTime::pszIndexName = LICPACKDESCRECORD_LASTMODIFYTIME_INDEXNAME;
  19. LPCTSTR __LICPACKDESCRECORDIdxOnModifyTime::pszIndexKey = LICPACKDESCRECORD_LASTMODIFYTIME_INDEXNAME_INDEXKEY;
  20. LPCTSTR LicPackDescTable::pszTableName = LICPACKDESCRECORD_TABLE_NAME;
  21. CCriticalSection LicPackDescTable::g_TableLock;
  22. //----------------------------------------------------------
  23. TLSJBIndex
  24. LicPackDescTable::g_TableIndex[] =
  25. {
  26. {
  27. LICPACKDESCRECORD_ID_INDEXNAME,
  28. LICPACKDESCRECORD_ID_INDEXNAME_INDEXKEY,
  29. -1,
  30. JET_bitIndexIgnoreNull, //JET_bitIndexUnique,
  31. TLSTABLE_INDEX_DEFAULT_DENSITY
  32. },
  33. {
  34. LICPACKDESCRECORD_ID_LANGID_INDEXNAME,
  35. LICPACKDESCRECORD_ID_LANGID_INDEXNAME_INDEXKEY,
  36. -1,
  37. JET_bitIndexPrimary,
  38. TLSTABLE_INDEX_DEFAULT_DENSITY
  39. }
  40. };
  41. int LicPackDescTable::g_NumTableIndex = sizeof(LicPackDescTable::g_TableIndex) / sizeof(LicPackDescTable::g_TableIndex[0]);
  42. TLSJBColumn
  43. LicPackDescTable::g_Columns[] =
  44. {
  45. {
  46. LICPACKDESCRECORD_ENTRYSTATUS,
  47. JET_coltypUnsignedByte,
  48. 0,
  49. JET_bitColumnFixed,
  50. NULL,
  51. 0,
  52. TLS_JETBLUE_COLUMN_CODE_PAGE,
  53. TLS_JETBLUE_COLUMN_COUNTRY_CODE,
  54. TLS_JETBLUE_COLUMN_LANGID
  55. },
  56. {
  57. LICPACKDESCRECORD_ID_COLUMN,
  58. JET_coltypLong,
  59. 0,
  60. JET_bitColumnFixed | JET_bitColumnNotNULL,
  61. NULL,
  62. 0,
  63. TLS_JETBLUE_COLUMN_CODE_PAGE,
  64. TLS_JETBLUE_COLUMN_COUNTRY_CODE,
  65. TLS_JETBLUE_COLUMN_LANGID
  66. },
  67. {
  68. LICPACKDESCRECORD_LASTMODIFYTIME,
  69. JET_coltypBinary,
  70. sizeof(FILETIME),
  71. JET_bitColumnNotNULL,
  72. NULL,
  73. 0,
  74. TLS_JETBLUE_COLUMN_CODE_PAGE,
  75. TLS_JETBLUE_COLUMN_COUNTRY_CODE,
  76. TLS_JETBLUE_COLUMN_LANGID
  77. },
  78. {
  79. LICPACKDESCRECORD_LANGID,
  80. JET_coltypLong,
  81. 0,
  82. JET_bitColumnFixed | JET_bitColumnNotNULL,
  83. NULL,
  84. 0,
  85. TLS_JETBLUE_COLUMN_CODE_PAGE,
  86. TLS_JETBLUE_COLUMN_COUNTRY_CODE,
  87. TLS_JETBLUE_COLUMN_LANGID
  88. },
  89. {
  90. LICPACKDESCRECORD_COMPANY_NAME,
  91. //JET_coltypLongText,
  92. JB_COLTYPE_TEXT,
  93. (MAX_JETBLUE_TEXT_LENGTH + 1)*sizeof(TCHAR),
  94. 0,
  95. JBSTRING_NULL,
  96. _tcslen(JBSTRING_NULL),
  97. TLS_JETBLUE_COLUMN_CODE_PAGE,
  98. TLS_JETBLUE_COLUMN_COUNTRY_CODE,
  99. TLS_JETBLUE_COLUMN_LANGID
  100. },
  101. {
  102. LICPACKDESCRECORD_PRODUCT_NAME,
  103. //JET_coltypLongText,
  104. JB_COLTYPE_TEXT,
  105. (MAX_JETBLUE_TEXT_LENGTH + 1)*sizeof(TCHAR),
  106. 0,
  107. JBSTRING_NULL,
  108. _tcslen(JBSTRING_NULL),
  109. TLS_JETBLUE_COLUMN_CODE_PAGE,
  110. TLS_JETBLUE_COLUMN_COUNTRY_CODE,
  111. TLS_JETBLUE_COLUMN_LANGID
  112. },
  113. {
  114. LICPACKDESCRECORD_PRODUCT_DESC,
  115. //JET_coltypLongText,
  116. JB_COLTYPE_TEXT,
  117. (MAX_JETBLUE_TEXT_LENGTH + 1)*sizeof(TCHAR),
  118. 0,
  119. JBSTRING_NULL,
  120. _tcslen(JBSTRING_NULL),
  121. TLS_JETBLUE_COLUMN_CODE_PAGE,
  122. TLS_JETBLUE_COLUMN_COUNTRY_CODE,
  123. TLS_JETBLUE_COLUMN_LANGID
  124. },
  125. };
  126. int
  127. LicPackDescTable::g_NumColumns = sizeof(LicPackDescTable::g_Columns) / sizeof(LicPackDescTable::g_Columns[0]);
  128. //--------------------------------------------------------------------------
  129. BOOL
  130. LicPackDescTable::ResolveToTableColumn()
  131. /*
  132. */
  133. {
  134. if(IsValid() == FALSE)
  135. {
  136. DebugOutput(
  137. _TEXT("Table %s is not valid...\n"),
  138. GetTableName()
  139. );
  140. JB_ASSERT(FALSE);
  141. SetLastJetError(JET_errNotInitialized);
  142. goto cleanup;
  143. }
  144. m_JetErr = ucEntryStatus.AttachToTable(
  145. *this,
  146. LICPACKDESCRECORD_ENTRYSTATUS
  147. );
  148. if(IsSuccess() == FALSE)
  149. goto cleanup;
  150. m_JetErr = dwKeyPackId.AttachToTable(
  151. *this,
  152. LICPACKDESCRECORD_ID_COLUMN
  153. );
  154. if(IsSuccess() == FALSE)
  155. goto cleanup;
  156. m_JetErr = dwLanguageId.AttachToTable(
  157. *this,
  158. LICPACKDESCRECORD_LANGID
  159. );
  160. if(IsSuccess() == FALSE)
  161. goto cleanup;
  162. m_JetErr = ftLastModifyTime.AttachToTable(
  163. *this,
  164. LICPACKDESCRECORD_LASTMODIFYTIME
  165. );
  166. if(IsSuccess() == FALSE)
  167. goto cleanup;
  168. m_JetErr = szCompanyName.AttachToTable(
  169. *this,
  170. LICPACKDESCRECORD_COMPANY_NAME
  171. );
  172. if(IsSuccess() == FALSE)
  173. goto cleanup;
  174. m_JetErr = szProductName.AttachToTable(
  175. *this,
  176. LICPACKDESCRECORD_PRODUCT_NAME
  177. );
  178. if(IsSuccess() == FALSE)
  179. goto cleanup;
  180. m_JetErr = szProductDesc.AttachToTable(
  181. *this,
  182. LICPACKDESCRECORD_PRODUCT_DESC
  183. );
  184. cleanup:
  185. return IsSuccess();
  186. }
  187. //-------------------------------------------------------------------------
  188. CLASS_PRIVATE BOOL
  189. LicPackDescTable::ProcessSingleColumn(
  190. BOOL bFetch,
  191. TLSColumnBase& column,
  192. DWORD offset,
  193. PVOID pbData,
  194. DWORD cbData,
  195. PDWORD pcbDataReturn,
  196. LPCTSTR szColumnName
  197. )
  198. /*
  199. */
  200. {
  201. if(bFetch)
  202. {
  203. m_JetErr = column.FetchColumnValue(
  204. pbData,
  205. cbData,
  206. offset,
  207. pcbDataReturn
  208. );
  209. }
  210. else
  211. {
  212. m_JetErr = column.InsertColumnValue(
  213. pbData,
  214. cbData,
  215. offset
  216. );
  217. }
  218. REPORTPROCESSFAILED(
  219. bFetch,
  220. GetTableName(),
  221. szColumnName,
  222. m_JetErr
  223. );
  224. return IsSuccess();
  225. }
  226. //--------------------------------------------------------------------------
  227. CLASS_PRIVATE BOOL
  228. LicPackDescTable::ProcessRecord(
  229. LICPACKDESCRECORD* record,
  230. BOOL bFetch,
  231. DWORD dwParam,
  232. BOOL bUpdate
  233. )
  234. /*
  235. */
  236. {
  237. DWORD dwSize;
  238. if(bFetch == FALSE)
  239. {
  240. //BeginTransaction();
  241. BeginUpdate(bUpdate);
  242. if(!(dwParam & LICPACKDESCRECORD_TABLE_PROCESS_LASTMODIFYTIME))
  243. {
  244. JB_ASSERT(FALSE);
  245. dwParam |= LICPACKDESCRECORD_TABLE_PROCESS_LASTMODIFYTIME;
  246. }
  247. }
  248. else
  249. {
  250. SetLastJetError(JET_errSuccess);
  251. }
  252. if(IsSuccess() == FALSE)
  253. return FALSE;
  254. if(dwParam & LICPACKDESCRECORD_TABLE_PROCESS_ENTRYSTATUS)
  255. {
  256. ProcessSingleColumn(
  257. bFetch,
  258. ucEntryStatus,
  259. 0,
  260. &(record->ucEntryStatus),
  261. sizeof(record->ucEntryStatus),
  262. &dwSize,
  263. LICPACKDESCRECORD_ENTRYSTATUS
  264. );
  265. }
  266. if(IsSuccess() == FALSE)
  267. goto cleanup;
  268. if(dwParam & LICPACKDESCRECORD_TABLE_PROCESS_KEYPACKID)
  269. {
  270. ProcessSingleColumn(
  271. bFetch,
  272. dwKeyPackId,
  273. 0,
  274. &(record->dwKeyPackId),
  275. sizeof(record->dwKeyPackId),
  276. &dwSize,
  277. LICPACKDESCRECORD_ID_COLUMN
  278. );
  279. }
  280. if(IsSuccess() == FALSE)
  281. goto cleanup;
  282. if(dwParam & LICPACKDESCRECORD_TABLE_PROCESS_LANGID)
  283. {
  284. ProcessSingleColumn(
  285. bFetch,
  286. dwLanguageId,
  287. 0,
  288. &(record->dwLanguageId),
  289. sizeof(record->dwLanguageId),
  290. &dwSize,
  291. LICPACKDESCRECORD_LANGID
  292. );
  293. }
  294. if(IsSuccess() == FALSE)
  295. goto cleanup;
  296. if(dwParam & LICPACKDESCRECORD_TABLE_PROCESS_LASTMODIFYTIME)
  297. {
  298. ProcessSingleColumn(
  299. bFetch,
  300. ftLastModifyTime,
  301. 0,
  302. &(record->ftLastModifyTime),
  303. sizeof(record->ftLastModifyTime),
  304. &dwSize,
  305. LICPACKDESCRECORD_LASTMODIFYTIME
  306. );
  307. }
  308. if(IsSuccess() == FALSE)
  309. goto cleanup;
  310. if(dwParam & LICPACKDESCRECORD_TABLE_PROCESS_COMPANYNAME)
  311. {
  312. ProcessSingleColumn(
  313. bFetch,
  314. szCompanyName,
  315. 0,
  316. record->szCompanyName,
  317. sizeof(record->szCompanyName),
  318. &dwSize,
  319. LICPACKDESCRECORD_COMPANY_NAME
  320. );
  321. }
  322. if(IsSuccess() == FALSE)
  323. goto cleanup;
  324. if(dwParam & LICPACKDESCRECORD_TABLE_PROCESS_PRODUCTNAME)
  325. {
  326. ProcessSingleColumn(
  327. bFetch,
  328. szProductName,
  329. 0,
  330. record->szProductName,
  331. sizeof(record->szProductName),
  332. &dwSize,
  333. LICPACKDESCRECORD_PRODUCT_NAME
  334. );
  335. }
  336. if(IsSuccess() == FALSE)
  337. goto cleanup;
  338. if(dwParam & LICPACKDESCRECORD_TABLE_PROCESS_PRODUCTDESC)
  339. {
  340. ProcessSingleColumn(
  341. bFetch,
  342. szProductDesc,
  343. 0,
  344. record->szProductDesc,
  345. sizeof(record->szProductDesc),
  346. &dwSize,
  347. LICPACKDESCRECORD_PRODUCT_DESC
  348. );
  349. }
  350. cleanup:
  351. //
  352. // For inserting/updating record
  353. if(bFetch == FALSE)
  354. {
  355. JET_ERR jetErr;
  356. jetErr = GetLastJetError();
  357. EndUpdate(IsSuccess() == FALSE);
  358. if(jetErr != JET_errSuccess && IsSuccess() == FALSE)
  359. SetLastJetError(jetErr);
  360. }
  361. return IsSuccess();
  362. }
  363. //----------------------------------------------------------------------------
  364. JBKeyBase*
  365. LicPackDescTable::EnumerationIndex(
  366. BOOL bMatchAll,
  367. DWORD dwSearchParam,
  368. LICPACKDESCRECORD* kpDesc,
  369. BOOL* bCompareKey
  370. )
  371. /*
  372. */
  373. {
  374. JBKeyBase* index=NULL;
  375. *bCompareKey = bMatchAll;
  376. // derive a index to use
  377. //
  378. if( bMatchAll == TRUE &&
  379. dwSearchParam & LICPACKDESCRECORD_TABLE_SEARCH_KEYPACKID &&
  380. dwSearchParam & LICPACKDESCRECORD_TABLE_SEARCH_LANGID)
  381. {
  382. index = new TLSKpDescIndexKpLangId(kpDesc);
  383. }
  384. else
  385. {
  386. index = new TLSKpDescIndexKpId(kpDesc);
  387. *bCompareKey = (bMatchAll && (dwSearchParam & LICPACKDESCRECORD_TABLE_SEARCH_KEYPACKID));
  388. }
  389. return index;
  390. }
  391. //---------------------------------------------------------------------------
  392. BOOL
  393. LicPackDescTable::EqualValue(
  394. LICPACKDESCRECORD& src,
  395. LICPACKDESCRECORD& dest,
  396. BOOL bMatchAll,
  397. DWORD dwParam
  398. )
  399. /*
  400. */
  401. {
  402. BOOL bRetCode = TRUE;
  403. if(dwParam & LICPACKDESCRECORD_TABLE_PROCESS_ENTRYSTATUS)
  404. {
  405. bRetCode = (src.ucEntryStatus == dest.ucEntryStatus);
  406. if(bMatchAll != bRetCode)
  407. goto cleanup;
  408. }
  409. if(dwParam & LICPACKDESCRECORD_TABLE_PROCESS_KEYPACKID)
  410. {
  411. bRetCode = (src.dwKeyPackId == dest.dwKeyPackId);
  412. //
  413. // bMatchAll == TRUE and bRetCode == FALSE -> return FALSE
  414. // bMatchAll == FALSE and bRetCode == TRUE -> return TRUE
  415. if(bMatchAll != bRetCode)
  416. goto cleanup;
  417. }
  418. if(dwParam & LICPACKDESCRECORD_TABLE_PROCESS_LANGID)
  419. {
  420. bRetCode = (src.dwLanguageId == dest.dwLanguageId);
  421. if(bMatchAll != bRetCode)
  422. goto cleanup;
  423. }
  424. if(dwParam & LICPACKDESCRECORD_TABLE_PROCESS_COMPANYNAME)
  425. {
  426. bRetCode = (_tcscmp(src.szCompanyName, dest.szCompanyName) == 0);
  427. if(bMatchAll != bRetCode)
  428. goto cleanup;
  429. }
  430. if(dwParam & LICPACKDESCRECORD_TABLE_PROCESS_PRODUCTNAME)
  431. {
  432. bRetCode = (_tcscmp(src.szProductName, dest.szProductName) == 0);
  433. if(bMatchAll != bRetCode)
  434. goto cleanup;
  435. }
  436. if(dwParam & LICPACKDESCRECORD_TABLE_PROCESS_PRODUCTDESC)
  437. {
  438. bRetCode = (_tcscmp(src.szProductDesc, dest.szProductDesc) == 0);
  439. }
  440. cleanup:
  441. return bRetCode;
  442. }