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.

1247 lines
26 KiB

  1. #include "precomp.h"
  2. DWORD
  3. InitWZCDbGlobals(
  4. )
  5. {
  6. DWORD dwError = 0;
  7. gpSessionCont = NULL;
  8. gdwCurrentHeader = 1;
  9. gdwCurrentTableSize = 0;
  10. gdwCurrentMaxRecordID = 0;
  11. gJetInstance = 0;
  12. gpWZCDbSessionRWLock = &gWZCDbSessionRWLock;
  13. gpAppendSessionCont = &gAppendSessionCont;
  14. memset(gpAppendSessionCont, 0, sizeof(SESSION_CONTAINER));
  15. gbDBOpened = FALSE;
  16. dwError = InitializeRWLock(gpWZCDbSessionRWLock);
  17. BAIL_ON_WIN32_ERROR(dwError);
  18. //
  19. // Open log database.
  20. //
  21. dwError = WZCOpenAppendSession(gpAppendSessionCont);
  22. BAIL_ON_WIN32_ERROR(dwError);
  23. gbDBOpened = TRUE;
  24. error:
  25. return (dwError);
  26. }
  27. VOID
  28. DeInitWZCDbGlobals(
  29. )
  30. {
  31. if (gpSessionCont) {
  32. DestroySessionContList(gpSessionCont);
  33. gpSessionCont = NULL;
  34. }
  35. //
  36. // If database has been opened for appending then close it.
  37. //
  38. if (gbDBOpened) {
  39. (VOID) WZCCloseAppendSession(gpAppendSessionCont);
  40. gbDBOpened = FALSE;
  41. }
  42. if (gpWZCDbSessionRWLock) {
  43. DestroyRWLock(gpWZCDbSessionRWLock);
  44. gpWZCDbSessionRWLock = NULL;
  45. }
  46. return;
  47. }
  48. DWORD
  49. WZCMapJetError(
  50. JET_ERR JetError,
  51. LPSTR CallerInfo OPTIONAL
  52. )
  53. /*++
  54. Routine Description:
  55. This function maps the Jet database errors to Windows errors.
  56. Arguments:
  57. JetError - An error from a JET function call.
  58. Return Value:
  59. Windows Error.
  60. --*/
  61. {
  62. DWORD Error = 0;
  63. if (JetError == JET_errSuccess) {
  64. return (ERROR_SUCCESS);
  65. }
  66. if (JetError < 0) {
  67. Error = JetError;
  68. switch (JetError) {
  69. case JET_errNoCurrentRecord:
  70. Error = ERROR_NO_MORE_ITEMS;
  71. break;
  72. case JET_errRecordNotFound:
  73. break;
  74. case JET_errKeyDuplicate:
  75. break;
  76. default:
  77. break;
  78. }
  79. return (Error);
  80. }
  81. return (ERROR_SUCCESS);
  82. }
  83. DWORD
  84. WZCCreateDatabase(
  85. JET_SESID JetServerSession,
  86. CHAR * Connect,
  87. JET_DBID * pJetDatabaseHandle,
  88. JET_GRBIT JetBits
  89. )
  90. /*++
  91. Routine Description:
  92. This routine creates wzc database and initializes it.
  93. Arguments:
  94. JetServerSession - Server session id.
  95. Connect - Database type. NULL specifies the default engine (blue).
  96. pJetDatabaseHandle - Pointer to database handle returned.
  97. JetBits - Create flags.
  98. Return Value:
  99. JET errors.
  100. --*/
  101. {
  102. JET_ERR JetError = JET_errSuccess;
  103. DWORD Error = 0;
  104. char DBFilePath[MAX_PATH];
  105. char * pc = NULL;
  106. memset(DBFilePath, 0, sizeof(CHAR)*MAX_PATH);
  107. //
  108. // Create database file name.
  109. //
  110. pc = getenv(DBFILENAMEPREFIX);
  111. if (pc != NULL) {
  112. if (lstrlenA(pc) >
  113. MAX_PATH - lstrlenA(DBFILENAMESUFFIX) - lstrlenA(DBFILENAME) -1)
  114. {
  115. Error = ERROR_FILENAME_EXCED_RANGE;
  116. BAIL_ON_WIN32_ERROR(Error);
  117. }
  118. strcpy(DBFilePath, pc);
  119. strcat(DBFilePath, DBFILENAMESUFFIX);
  120. }
  121. else {
  122. strcpy(DBFilePath, DBFILENAMESUFFIX);
  123. }
  124. strcat(DBFilePath, DBFILENAME);
  125. //
  126. // Convert name to ANSI.
  127. //
  128. OemToCharA(DBFilePath, DBFilePath);
  129. //
  130. // Create database.
  131. //
  132. JetError = JetCreateDatabase(
  133. JetServerSession,
  134. DBFilePath,
  135. Connect,
  136. pJetDatabaseHandle,
  137. JetBits
  138. );
  139. Error = WZCMapJetError(JetError, "JetCreateDatabase");
  140. BAIL_ON_WIN32_ERROR(Error);
  141. error:
  142. return (Error);
  143. }
  144. DWORD
  145. WZCOpenDatabase(
  146. JET_SESID JetServerSession,
  147. CHAR * Connect,
  148. JET_DBID * pJetDatabaseHandle,
  149. JET_GRBIT JetBits
  150. )
  151. /*++
  152. Routine Description:
  153. This routine attaches to wzc database and opens it.
  154. Arguments:
  155. JetServerSession - Server session id.
  156. Connect - Database type. NULL specifies the default engine (blue).
  157. pJetDatabaseHandle - Pointer to database handle returned.
  158. JetBits - Create flags.
  159. Return Value:
  160. JET errors.
  161. --*/
  162. {
  163. JET_ERR JetError = JET_errSuccess;
  164. DWORD Error = 0;
  165. char DBFilePath[MAX_PATH];
  166. char * pc = NULL;
  167. memset(DBFilePath, 0, sizeof(CHAR)*MAX_PATH);
  168. //
  169. // Create database file name.
  170. //
  171. pc = getenv(DBFILENAMEPREFIX);
  172. if (pc != NULL) {
  173. if (lstrlenA(pc) >
  174. MAX_PATH - lstrlenA(DBFILENAMESUFFIX) - lstrlenA(DBFILENAME) -1)
  175. {
  176. Error = ERROR_FILENAME_EXCED_RANGE;
  177. BAIL_ON_WIN32_ERROR(Error);
  178. }
  179. strcpy(DBFilePath, pc);
  180. strcat(DBFilePath, DBFILENAMESUFFIX);
  181. }
  182. else {
  183. strcpy(DBFilePath, DBFILENAMESUFFIX);
  184. }
  185. strcat(DBFilePath, DBFILENAME);
  186. //
  187. // Convert name to ANSI.
  188. //
  189. OemToCharA(DBFilePath, DBFilePath);
  190. //
  191. // Attach to database.
  192. //
  193. JetError = JetAttachDatabase(
  194. JetServerSession,
  195. DBFilePath,
  196. JetBits
  197. );
  198. Error = WZCMapJetError(JetError, "JetAttachDatabase");
  199. BAIL_ON_WIN32_ERROR(Error);
  200. JetError = JetOpenDatabase(
  201. JetServerSession,
  202. DBFilePath,
  203. Connect,
  204. pJetDatabaseHandle,
  205. JetBits
  206. );
  207. Error = WZCMapJetError(JetError, "JetOpenDatabase");
  208. BAIL_ON_WIN32_ERROR(Error);
  209. error:
  210. return (Error);
  211. }
  212. DWORD
  213. WZCInitializeDatabase(
  214. JET_SESID * pJetServerSession
  215. )
  216. /*++
  217. Routine Description:
  218. This function initializes the wzc logging database.
  219. Arguments:
  220. pJetServerSession - Pointer to server session id.
  221. Return Value:
  222. Windows Error.
  223. --*/
  224. {
  225. JET_ERR JetError = JET_errSuccess;
  226. DWORD Error = 0;
  227. char DBFilePath[MAX_PATH];
  228. char * pc = NULL;
  229. BOOL bInitJetInstance = FALSE;
  230. memset(DBFilePath, 0, sizeof(CHAR)*MAX_PATH);
  231. *pJetServerSession = 0;
  232. gJetInstance = 0;
  233. //
  234. // Create database file name.
  235. //
  236. pc = getenv(DBFILENAMEPREFIX);
  237. if (pc != NULL) {
  238. if (lstrlenA(pc) >
  239. MAX_PATH - lstrlenA(DBFILENAMESUFFIX) - lstrlenA(DBFILENAME) -1)
  240. {
  241. Error = ERROR_FILENAME_EXCED_RANGE;
  242. BAIL_ON_WIN32_ERROR(Error);
  243. }
  244. strcpy(DBFilePath, pc);
  245. strcat(DBFilePath, DBFILENAMESUFFIX);
  246. }
  247. else {
  248. strcpy(DBFilePath, DBFILENAMESUFFIX);
  249. }
  250. //
  251. // Convert name to ANSI.
  252. //
  253. OemToCharA(DBFilePath, DBFilePath);
  254. //
  255. // create a Jet instance.
  256. //
  257. JetError = JetCreateInstance(
  258. &gJetInstance,
  259. cszWLANMonInstanceName
  260. );
  261. Error = WZCMapJetError(JetError, "JetCreateInstance");
  262. BAIL_ON_WIN32_ERROR(Error);
  263. bInitJetInstance = TRUE;
  264. //
  265. // Set parameters to circularly use DB logging files.
  266. //
  267. JetError = JetSetSystemParameter(
  268. &gJetInstance,
  269. (JET_SESID)0,
  270. JET_paramCircularLog,
  271. TRUE,
  272. NULL
  273. );
  274. Error = WZCMapJetError(JetError, "JetSetSystemParameter");
  275. BAIL_ON_WIN32_ERROR(Error);
  276. //
  277. // Set max size of log file for DB as MAX_CHECK_POINT_DEPTH.
  278. //
  279. JetError = JetSetSystemParameter(
  280. &gJetInstance,
  281. (JET_SESID)0,
  282. JET_paramCheckpointDepthMax,
  283. MAX_CHECK_POINT_DEPTH,
  284. NULL
  285. );
  286. Error = WZCMapJetError(JetError, "JetSetSystemParameter");
  287. BAIL_ON_WIN32_ERROR(Error);
  288. //
  289. // Set system, temperary and log file path to where the .mdb file is.
  290. //
  291. JetError = JetSetSystemParameter(
  292. &gJetInstance,
  293. (JET_SESID)0,
  294. JET_paramSystemPath,
  295. TRUE,
  296. DBFilePath
  297. );
  298. Error = WZCMapJetError(JetError, "JetSetSystemParameter");
  299. BAIL_ON_WIN32_ERROR(Error);
  300. JetError = JetSetSystemParameter(
  301. &gJetInstance,
  302. (JET_SESID)0,
  303. JET_paramLogFilePath,
  304. TRUE,
  305. DBFilePath
  306. );
  307. Error = WZCMapJetError(JetError, "JetSetSystemParameter");
  308. BAIL_ON_WIN32_ERROR(Error);
  309. JetError = JetSetSystemParameter(
  310. &gJetInstance,
  311. (JET_SESID)0,
  312. JET_paramTempPath,
  313. TRUE,
  314. DBFilePath
  315. );
  316. Error = WZCMapJetError(JetError, "JetSetSystemParameter");
  317. BAIL_ON_WIN32_ERROR(Error);
  318. //
  319. // Create path if it does not exist.
  320. //
  321. JetError = JetSetSystemParameter(
  322. &gJetInstance,
  323. (JET_SESID)0,
  324. JET_paramCreatePathIfNotExist,
  325. TRUE,
  326. NULL
  327. );
  328. Error = WZCMapJetError(JetError, "JetSetSystemParameter");
  329. BAIL_ON_WIN32_ERROR(Error);
  330. JetError = JetInit(&gJetInstance);
  331. Error = WZCMapJetError(JetError, "JetInit");
  332. BAIL_ON_WIN32_ERROR(Error);
  333. JetError = JetBeginSession(
  334. gJetInstance,
  335. pJetServerSession,
  336. "admin",
  337. ""
  338. );
  339. Error = WZCMapJetError(JetError, "JetBeginSession");
  340. BAIL_ON_WIN32_ERROR(Error);
  341. return (Error);
  342. error:
  343. if (*pJetServerSession != 0) {
  344. JetError = JetEndSession(*pJetServerSession, 0);
  345. WZCMapJetError(JetError, "JetEndSession");
  346. *pJetServerSession = 0;
  347. }
  348. if (bInitJetInstance) {
  349. JetError = JetTerm2(gJetInstance, JET_bitTermComplete);
  350. gJetInstance = 0;
  351. WZCMapJetError(JetError, "JetTerm/JetTerm2");
  352. }
  353. return (Error);
  354. }
  355. VOID
  356. WZCTerminateJet(
  357. JET_SESID * pJetServerSession
  358. )
  359. /*++
  360. Routine Description:
  361. This routine ends the jet session and terminates the jet engine.
  362. Arguments:
  363. pJetServerSession - Pointer to the server session id.
  364. Return Value:
  365. None.
  366. --*/
  367. {
  368. JET_ERR JetError = JET_errSuccess;
  369. if (*pJetServerSession != 0) {
  370. JetError = JetEndSession(*pJetServerSession, 0);
  371. WZCMapJetError(JetError, "JetEndSession");
  372. *pJetServerSession = 0;
  373. }
  374. JetError = JetTerm2(gJetInstance, JET_bitTermComplete);
  375. gJetInstance = 0;
  376. WZCMapJetError(JetError, "JetTerm/JetTerm2");
  377. return;
  378. }
  379. DWORD
  380. WZCJetBeginTransaction(
  381. JET_SESID JetServerSession
  382. )
  383. /*++
  384. Routine Description:
  385. This functions starts an wzc database transaction.
  386. Arguments:
  387. JetServerSession - Server session id.
  388. Return Value:
  389. The status of the operation.
  390. --*/
  391. {
  392. JET_ERR JetError = JET_errSuccess;
  393. DWORD Error = 0;
  394. JetError = JetBeginTransaction(JetServerSession);
  395. Error = WZCMapJetError(JetError, "WZCJetBeginTransaction");
  396. return (Error);
  397. }
  398. DWORD
  399. WZCJetRollBack(
  400. JET_SESID JetServerSession
  401. )
  402. /*++
  403. Routine Description:
  404. This functions rolls back an wzc database transaction.
  405. Arguments:
  406. JetServerSession - Server session id.
  407. Return Value:
  408. The status of the operation.
  409. --*/
  410. {
  411. JET_ERR JetError = JET_errSuccess;
  412. DWORD Error = 0;
  413. //
  414. // Rollback the last transaction.
  415. //
  416. JetError = JetRollback(JetServerSession, 0);
  417. Error = WZCMapJetError(JetError, "WZCJetRollBack");
  418. return(Error);
  419. }
  420. DWORD
  421. WZCJetCommitTransaction(
  422. JET_SESID JetServerSession,
  423. JET_TABLEID JetTableHandle
  424. )
  425. /*++
  426. Routine Description:
  427. This functions commits an wzc database transaction.
  428. Arguments:
  429. JetServerSession - Server session id.
  430. JetTableHandle - Table handle.
  431. Return Value:
  432. The status of the operation.
  433. --*/
  434. {
  435. JET_ERR JetError = JET_errSuccess;
  436. DWORD Error = 0;
  437. JetError = JetCommitTransaction(
  438. JetServerSession,
  439. JET_bitCommitLazyFlush
  440. );
  441. Error = WZCMapJetError(JetError, "WZCJetCommitTransaction");
  442. return (Error);
  443. }
  444. DWORD
  445. WZCJetPrepareUpdate(
  446. JET_SESID JetServerSession,
  447. JET_TABLEID JetTableHandle,
  448. char * ColumnName,
  449. PVOID Key,
  450. DWORD KeySize,
  451. BOOL NewRecord
  452. )
  453. /*++
  454. Routine Description:
  455. This function prepares the database for the creation of a new record,
  456. or updating an existing record.
  457. Arguments:
  458. JetServerSession - Server session id.
  459. JetTableHandle - Table handle.
  460. ColumnName - The column name of an index column.
  461. Key - The key to update/create.
  462. KeySize - The size of the specified key, in bytes.
  463. NewRecord - TRUE to create the key, FALSE to update an existing key.
  464. Return Value:
  465. The status of the operation.
  466. --*/
  467. {
  468. JET_ERR JetError = JET_errSuccess;
  469. DWORD Error = 0;
  470. if (!NewRecord) {
  471. JetError = JetSetCurrentIndex(
  472. JetServerSession,
  473. JetTableHandle,
  474. ColumnName
  475. );
  476. Error = WZCMapJetError(JetError, "JetPrepareUpdate: JetSetCurrentIndex");
  477. if (Error != ERROR_SUCCESS) {
  478. WZCMapJetError(JetError, ColumnName);
  479. return (Error);
  480. }
  481. JetError = JetMakeKey(
  482. JetServerSession,
  483. JetTableHandle,
  484. Key,
  485. KeySize,
  486. JET_bitNewKey
  487. );
  488. Error = WZCMapJetError(JetError, "JetPrepareUpdate: JetMakeKey");
  489. if (Error != ERROR_SUCCESS) {
  490. WZCMapJetError(JetError, ColumnName);
  491. return (Error);
  492. }
  493. JetError = JetSeek(
  494. JetServerSession,
  495. JetTableHandle,
  496. JET_bitSeekEQ
  497. );
  498. Error = WZCMapJetError(JetError, "JetPrepareUpdate: JetSeek");
  499. if (Error != ERROR_SUCCESS) {
  500. WZCMapJetError(JetError, ColumnName);
  501. return (Error);
  502. }
  503. }
  504. JetError = JetPrepareUpdate(
  505. JetServerSession,
  506. JetTableHandle,
  507. NewRecord ? JET_prepInsert : JET_prepReplace
  508. );
  509. Error = WZCMapJetError(JetError, "JetPrepareUpdate: JetPrepareUpdate");
  510. return (Error);
  511. }
  512. DWORD
  513. WZCJetCommitUpdate(
  514. JET_SESID JetServerSession,
  515. JET_TABLEID JetTableHandle
  516. )
  517. /*++
  518. Routine Description:
  519. This function commits an update to the database. The record specified
  520. by the last call to WZCJetPrepareUpdate() is committed.
  521. Arguments:
  522. JetServerSession - Server session id.
  523. JetTableHandle - Table handle.
  524. Return Value:
  525. The status of the operation.
  526. --*/
  527. {
  528. JET_ERR JetError = JET_errSuccess;
  529. DWORD Error = 0;
  530. JetError = JetUpdate(
  531. JetServerSession,
  532. JetTableHandle,
  533. NULL,
  534. 0,
  535. NULL
  536. );
  537. Error = WZCMapJetError(JetError, "WZCJetCommitUpdate");
  538. return (Error);
  539. }
  540. DWORD
  541. WZCJetSetValue(
  542. JET_SESID JetServerSession,
  543. JET_TABLEID JetTableHandle,
  544. JET_COLUMNID KeyColumnId,
  545. PVOID Data,
  546. DWORD DataSize
  547. )
  548. /*++
  549. Routine Description:
  550. This function updates the value of an entry in the current record.
  551. Arguments:
  552. JetServerSession - Server session id.
  553. JetTableHandle - Table handle.
  554. KeyColumnId - The Id of the column (value) to update.
  555. Data - A pointer to the new value for the column.
  556. DataSize - The size of the data, in bytes.
  557. Return Value:
  558. Winerror code.
  559. --*/
  560. {
  561. JET_ERR JetError = JET_errSuccess;
  562. DWORD Error = 0;
  563. JetError = JetSetColumn(
  564. JetServerSession,
  565. JetTableHandle,
  566. KeyColumnId,
  567. Data,
  568. DataSize,
  569. 0,
  570. NULL
  571. );
  572. Error = WZCMapJetError(JetError, "JetSetValue: JetSetcolumn");
  573. return (Error);
  574. }
  575. DWORD
  576. WZCJetPrepareSearch(
  577. JET_SESID JetServerSession,
  578. JET_TABLEID JetTableHandle,
  579. char * ColumnName,
  580. BOOL SearchFromStart,
  581. PVOID Key,
  582. DWORD KeySize
  583. )
  584. /*++
  585. Routine Description:
  586. This function prepares for a search of the client database.
  587. Arguments:
  588. JetServerSession - Server session id.
  589. JetTableHandle - Table handle.
  590. ColumnName - The column name to use as the index column.
  591. SearchFromStart - If TRUE, search from the first record in the
  592. database. If FALSE, search from the specified key.
  593. Key - The key to start the search.
  594. KeySize - The size, in bytes, of key.
  595. Return Value:
  596. Winerror code.
  597. --*/
  598. {
  599. JET_ERR JetError = JET_errSuccess;
  600. DWORD Error = 0;
  601. JetError = JetSetCurrentIndex(
  602. JetServerSession,
  603. JetTableHandle,
  604. ColumnName
  605. );
  606. Error = WZCMapJetError(JetError, "JetPrepareSearch: JetSetCurrentIndex");
  607. if (Error != ERROR_SUCCESS) {
  608. WZCMapJetError(JetError, ColumnName);
  609. return (Error);
  610. }
  611. if (SearchFromStart) {
  612. JetError = JetMove(
  613. JetServerSession,
  614. JetTableHandle,
  615. JET_MoveFirst,
  616. 0
  617. );
  618. }
  619. else {
  620. JetError = JetMakeKey(
  621. JetServerSession,
  622. JetTableHandle,
  623. Key,
  624. KeySize,
  625. JET_bitNewKey
  626. );
  627. Error = WZCMapJetError(JetError, "JetPrepareSearch: JetMakeKey");
  628. if (Error != ERROR_SUCCESS) {
  629. WZCMapJetError(JetError, ColumnName);
  630. return (Error);
  631. }
  632. JetError = JetSeek(
  633. JetServerSession,
  634. JetTableHandle,
  635. JET_bitSeekGT
  636. );
  637. }
  638. Error = WZCMapJetError(JetError, "JetPrepareSearch: JetMove / JetSeek");
  639. return (Error);
  640. }
  641. DWORD
  642. WZCJetNextRecord(
  643. JET_SESID JetServerSession,
  644. JET_TABLEID JetTableHandle
  645. )
  646. /*++
  647. Routine Description:
  648. This function advances to the next record in a search.
  649. Arguments:
  650. JetServerSession - Server session id.
  651. JetTableHandle - Table handle.
  652. Return Value:
  653. The status of the operation.
  654. --*/
  655. {
  656. JET_ERR JetError = JET_errSuccess;
  657. DWORD Error = 0;
  658. JetError = JetMove(
  659. JetServerSession,
  660. JetTableHandle,
  661. JET_MoveNext,
  662. 0
  663. );
  664. Error = WZCMapJetError(JetError, "JetNextRecord");
  665. return (Error);
  666. }
  667. DWORD
  668. WZCCreateTableData(
  669. JET_SESID JetServerSession,
  670. JET_DBID JetDatabaseHandle,
  671. JET_TABLEID * pJetTableHandle
  672. )
  673. /*++
  674. Routine Description:
  675. This function creates a table in the database.
  676. Arguments:
  677. JetServerSession - Server session id.
  678. JetDatabaseHandle - Database handle.
  679. pJetTableHandle - Pointer to return table handle.
  680. Return Value:
  681. The status of the operation.
  682. --*/
  683. {
  684. JET_ERR JetError = JET_errSuccess;
  685. DWORD Error = 0;
  686. JET_COLUMNDEF ColumnDef;
  687. CHAR * IndexKey = NULL;
  688. DWORD i = 0;
  689. memset(&ColumnDef, 0, sizeof(JET_COLUMNDEF));
  690. //
  691. // Create table.
  692. //
  693. JetError = JetCreateTable(
  694. JetServerSession,
  695. JetDatabaseHandle,
  696. LOG_RECORD_TABLE,
  697. DB_TABLE_SIZE,
  698. DB_TABLE_DENSITY,
  699. pJetTableHandle
  700. );
  701. Error = WZCMapJetError(JetError, "JetCreateTable");
  702. BAIL_ON_WIN32_ERROR(Error);
  703. //
  704. // Create columns.
  705. // Init fields of columndef that do not change between addition of
  706. // columns.
  707. //
  708. ColumnDef.cbStruct = sizeof(ColumnDef);
  709. ColumnDef.columnid = 0;
  710. ColumnDef.wCountry = 1;
  711. ColumnDef.langid = DB_LANGID;
  712. ColumnDef.cp = DB_CP;
  713. ColumnDef.wCollate = 0;
  714. ColumnDef.cbMax = 0;
  715. ColumnDef.grbit = 0;
  716. for (i = 0; i < RECORD_TABLE_NUM_COLS; i++) {
  717. ColumnDef.coltyp = gLogRecordTable[i].ColType;
  718. ColumnDef.grbit = gLogRecordTable[i].dwJetBit;
  719. JetError = JetAddColumn(
  720. JetServerSession,
  721. *pJetTableHandle,
  722. gLogRecordTable[i].ColName,
  723. &ColumnDef,
  724. NULL,
  725. 0,
  726. &gLogRecordTable[i].ColHandle
  727. );
  728. Error = WZCMapJetError(JetError, "JetAddColumn");
  729. BAIL_ON_WIN32_ERROR(Error);
  730. }
  731. //
  732. // Finally create index.
  733. //
  734. IndexKey = "+" RECORD_IDX_STR "\0";
  735. JetError = JetCreateIndex(
  736. JetServerSession,
  737. *pJetTableHandle,
  738. gLogRecordTable[RECORD_IDX_IDX].ColName,
  739. 0,
  740. IndexKey,
  741. strlen(IndexKey) + 2, // for two termination chars.
  742. 50
  743. );
  744. Error = WZCMapJetError(JetError, "JetCreateIndex");
  745. BAIL_ON_WIN32_ERROR(Error);
  746. IndexKey = "+" RECORD_ID_STR "\0";
  747. JetError = JetCreateIndex(
  748. JetServerSession,
  749. *pJetTableHandle,
  750. gLogRecordTable[RECORD_ID_IDX].ColName,
  751. 0,
  752. IndexKey,
  753. strlen(IndexKey) + 2, // for two termination chars.
  754. 50
  755. );
  756. Error = WZCMapJetError(JetError, "JetCreateIndex");
  757. BAIL_ON_WIN32_ERROR(Error);
  758. IndexKey = "+" TIMESTAMP_STR "\0";
  759. JetError = JetCreateIndex(
  760. JetServerSession,
  761. *pJetTableHandle,
  762. gLogRecordTable[TIMESTAMP_IDX].ColName,
  763. 0,
  764. IndexKey,
  765. strlen(IndexKey) + 2, // for two termination chars.
  766. 50
  767. );
  768. Error = WZCMapJetError(JetError, "JetCreateIndex");
  769. BAIL_ON_WIN32_ERROR(Error);
  770. IndexKey = "+" INTERFACE_MAC_STR "\0";
  771. JetError = JetCreateIndex(
  772. JetServerSession,
  773. *pJetTableHandle,
  774. gLogRecordTable[INTERFACE_MAC_IDX].ColName,
  775. 0,
  776. IndexKey,
  777. strlen(IndexKey) + 2, // for two termination chars.
  778. 50
  779. );
  780. Error = WZCMapJetError(JetError, "JetCreateIndex");
  781. BAIL_ON_WIN32_ERROR(Error);
  782. IndexKey = "+" DEST_MAC_STR "\0";
  783. JetError = JetCreateIndex(
  784. JetServerSession,
  785. *pJetTableHandle,
  786. gLogRecordTable[DEST_MAC_IDX].ColName,
  787. 0,
  788. IndexKey,
  789. strlen(IndexKey) + 2, // for two termination chars.
  790. 50
  791. );
  792. Error = WZCMapJetError(JetError, "JetCreateIndex");
  793. BAIL_ON_WIN32_ERROR(Error);
  794. IndexKey = "+" SSID_STR "\0";
  795. JetError = JetCreateIndex(
  796. JetServerSession,
  797. *pJetTableHandle,
  798. gLogRecordTable[SSID_IDX].ColName,
  799. 0,
  800. IndexKey,
  801. strlen(IndexKey) + 2, // for two termination chars.
  802. 50
  803. );
  804. Error = WZCMapJetError(JetError, "JetCreateIndex");
  805. BAIL_ON_WIN32_ERROR(Error);
  806. error:
  807. return (Error);
  808. }
  809. DWORD
  810. WZCOpenTableData(
  811. JET_SESID JetServerSession,
  812. JET_DBID JetDatabaseHandle,
  813. JET_TABLEID * pJetTableHandle
  814. )
  815. /*++
  816. Routine Description:
  817. This function opens a table in the database.
  818. Arguments:
  819. JetServerSession - Server session id.
  820. JetDatabaseHandle - Database handle.
  821. pJetTableHandle - Pointer to return table handle.
  822. Return Value:
  823. The status of the operation.
  824. --*/
  825. {
  826. JET_ERR JetError = JET_errSuccess;
  827. DWORD Error = 0;
  828. JET_COLUMNDEF ColumnDef;
  829. CHAR * IndexKey = NULL;
  830. DWORD i = 0;
  831. memset(&ColumnDef, 0, sizeof(JET_COLUMNDEF));
  832. //
  833. // Open table.
  834. //
  835. JetError = JetOpenTable(
  836. JetServerSession,
  837. JetDatabaseHandle,
  838. LOG_RECORD_TABLE,
  839. NULL,
  840. 0,
  841. 0,
  842. pJetTableHandle
  843. );
  844. Error = WZCMapJetError(JetError, "JetOpenTable");
  845. BAIL_ON_WIN32_ERROR(Error);
  846. for (i = 0; i < RECORD_TABLE_NUM_COLS; i++) {
  847. ColumnDef.coltyp = gLogRecordTable[i].ColType;
  848. JetError = JetGetTableColumnInfo(
  849. JetServerSession,
  850. *pJetTableHandle,
  851. gLogRecordTable[i].ColName,
  852. &ColumnDef,
  853. sizeof(ColumnDef),
  854. 0
  855. );
  856. Error = WZCMapJetError(JetError, "JetGetTableColumnInfo");
  857. BAIL_ON_WIN32_ERROR(Error);
  858. gLogRecordTable[i].ColHandle = ColumnDef.columnid;
  859. }
  860. error:
  861. return (Error);
  862. }
  863. DWORD
  864. WZCJetGetValue(
  865. JET_SESID JetServerSession,
  866. JET_TABLEID JetTableHandle,
  867. JET_COLUMNID ColumnId,
  868. PVOID pvData,
  869. DWORD dwSize,
  870. PDWORD pdwRequiredSize
  871. )
  872. /*++
  873. Routine Description:
  874. This function reads the value of an entry in the current record.
  875. Arguments:
  876. JetServerSession - Server session id.
  877. JetDatabaseHandle - Database handle.
  878. ColumnId - The Id of the column (value) to read.
  879. Data - Pointer to a location where the data that is read from the
  880. database returned, or pointer to a location where data is.
  881. DataSize - If the pointed value is non-zero then the Data points to
  882. a buffer otherwise this function allocates buffer for
  883. return data and returns buffer pointer in Data.
  884. pdwRequiredSize - Pointer to hold the required size.
  885. Return Value:
  886. The status of the operation.
  887. --*/
  888. {
  889. JET_ERR JetError = JET_errSuccess;
  890. DWORD Error = 0;
  891. JetError = JetRetrieveColumn(
  892. JetServerSession,
  893. JetTableHandle,
  894. ColumnId,
  895. pvData,
  896. dwSize,
  897. pdwRequiredSize,
  898. 0,
  899. NULL
  900. );
  901. Error = WZCMapJetError(JetError, "JetGetValue: JetRetrieveColumn");
  902. BAIL_ON_WIN32_ERROR(Error);
  903. error:
  904. return (Error);
  905. }
  906. BOOL
  907. IsDBOpened(
  908. )
  909. {
  910. return (gbDBOpened);
  911. }