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.

1305 lines
29 KiB

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