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.

1153 lines
22 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Copyright (c) 1997-1999 Microsoft Corporation
  4. //
  5. // File:
  6. //
  7. // Contents:
  8. //
  9. // History:
  10. //
  11. //---------------------------------------------------------------------------
  12. #ifndef __JETBLUE_H__
  13. #define __JETBLUE_H__
  14. #include "JBDef.h"
  15. #include "locks.h"
  16. #define JETBLUE_EDBLOG _TEXT("edb*.log")
  17. #define JETBLUE_RESLOG _TEXT("res?.log")
  18. class JBError;
  19. class JBSession;
  20. class JBDatabase;
  21. class JBTable;
  22. class JBColumn;
  23. // class JBIndex;
  24. // class JBRecordSet;
  25. //
  26. /////////////////////////////////////////////////////////////////////
  27. //
  28. class JBInstance : public JBError {
  29. friend class JBSession;
  30. friend operator==(const JBInstance& jbInst1, const JBInstance& jbInst2);
  31. friend operator!=(const JBInstance& jbInst1, const JBInstance& jbInst2);
  32. private:
  33. JET_INSTANCE m_JetInstance;
  34. // DWORD m_NumSession;
  35. CSafeCounter m_NumSession;
  36. BOOL m_bInit;
  37. private:
  38. JET_SESID
  39. BeginJetSession(
  40. LPCTSTR pszUserName=NULL,
  41. LPCTSTR pszPwd=NULL
  42. );
  43. BOOL
  44. EndJetSession(
  45. JET_SESID JetSessionID,
  46. JET_GRBIT grbit = 0
  47. );
  48. BOOL
  49. EndSession(
  50. JET_SESID sesId,
  51. JET_GRBIT grbit
  52. );
  53. public:
  54. JBInstance();
  55. ~JBInstance();
  56. BOOL
  57. SetSystemParameter(
  58. JET_SESID SesId,
  59. unsigned long lParamId,
  60. ULONG_PTR lParam,
  61. PBYTE sz
  62. );
  63. BOOL
  64. GetSystemParameter(
  65. JET_SESID SesId,
  66. unsigned long lParamId,
  67. ULONG_PTR* plParam,
  68. PBYTE sz,
  69. unsigned long cbMax
  70. );
  71. const JET_INSTANCE
  72. GetInstanceID() const {
  73. return m_JetInstance;
  74. }
  75. BOOL
  76. JBInitJetInstance();
  77. BOOL
  78. JBTerminate(
  79. JET_GRBIT grbit = JET_bitTermComplete,
  80. BOOL bDeleteLogFile = FALSE
  81. );
  82. BOOL
  83. IsValid() const
  84. {
  85. return m_bInit;
  86. }
  87. };
  88. //--------------------------------------------------------------------
  89. inline BOOL
  90. operator==(
  91. const JBInstance& jbInst1,
  92. const JBInstance& jbInst2
  93. )
  94. {
  95. return jbInst1.GetInstanceID() == jbInst2.GetInstanceID();
  96. }
  97. inline BOOL
  98. operator!=(
  99. const JBInstance& jbInst1,
  100. const JBInstance& jbInst2
  101. )
  102. {
  103. return !(jbInst1 == jbInst2);
  104. }
  105. //
  106. /////////////////////////////////////////////////////////////////////
  107. //
  108. class JBSession : public JBError {
  109. friend class JBDatabase;
  110. private:
  111. JBInstance& m_JetInstance;
  112. JET_SESID m_JetSessionID;
  113. // JetBlue Transaction is session base
  114. int m_TransactionLevel;
  115. // DWORD m_JetDBInitialized;
  116. CSafeCounter m_JetDBInitialized;
  117. // CCriticalSection m_JetSessionLock;
  118. private:
  119. JET_DBID
  120. OpenJetDatabase(
  121. LPCTSTR szDatabase,
  122. LPCTSTR szConnect=NULL,
  123. JET_GRBIT grbit=0
  124. );
  125. BOOL
  126. CloseJetDatabase(
  127. JET_DBID jdbId,
  128. JET_GRBIT grbit=0
  129. );
  130. JET_DBID
  131. CreateJetDatabase(
  132. LPCTSTR szFileName,
  133. LPCTSTR szConnect=NULL,
  134. JET_GRBIT grbit=0
  135. );
  136. BOOL
  137. DuplicateSession(
  138. JET_SESID sesID
  139. );
  140. JBInstance&
  141. GetJetInstance() {
  142. return m_JetInstance;
  143. }
  144. BOOL
  145. CloseDatabase(
  146. JET_DBID jdbId,
  147. JET_GRBIT grbit=0
  148. );
  149. public:
  150. JBSession(JBSession& JetSession); // JetDupSession()
  151. JBSession(
  152. JBInstance& JetInstance,
  153. JET_SESID JetSessID=JET_sesidNil
  154. );
  155. ~JBSession();
  156. BOOL
  157. IsValid() const {
  158. return m_JetInstance.IsValid() &&
  159. m_JetSessionID != JET_sesidNil;
  160. }
  161. BOOL
  162. BeginSession(
  163. LPCTSTR szUserName=NULL,
  164. LPCTSTR szPwd=NULL
  165. );
  166. BOOL
  167. EndSession(
  168. JET_GRBIT grbit = JET_bitTermComplete
  169. );
  170. const JBInstance&
  171. GetJetInstance() const {
  172. return m_JetInstance;
  173. }
  174. const JET_SESID
  175. GetJetSessionID() const {
  176. return m_JetSessionID;
  177. }
  178. BOOL
  179. SetSystemParameter(
  180. unsigned long lParamId,
  181. ULONG_PTR lParam,
  182. const PBYTE sz
  183. );
  184. BOOL
  185. GetSystemParameter(
  186. unsigned long lParamId,
  187. ULONG_PTR* plParam,
  188. PBYTE sz,
  189. unsigned long cbMax
  190. );
  191. //
  192. // make JetBlue aware of database
  193. //
  194. BOOL
  195. AttachDatabase(
  196. LPCTSTR szFileName,
  197. JET_GRBIT grbit=0
  198. );
  199. BOOL
  200. DetachDatabase(
  201. LPCTSTR szFileName
  202. );
  203. //
  204. // Transaction
  205. //
  206. BOOL
  207. BeginTransaction();
  208. BOOL
  209. CommitTransaction(JET_GRBIT grbit=0);
  210. BOOL
  211. RollbackTransaction(JET_GRBIT grbit=JET_bitRollbackAll);
  212. int
  213. GetTransactionLevel() const {
  214. return m_TransactionLevel;
  215. }
  216. BOOL
  217. EndAllTransaction(
  218. BOOL bCommit=FALSE,
  219. JET_GRBIT grbit=0
  220. );
  221. BOOL
  222. Compatible(const JBSession& jbSess) const {
  223. return GetJetInstance() == jbSess.GetJetInstance();
  224. }
  225. //CCriticalSection&
  226. //GetSessionLock()
  227. //{
  228. // return m_JetSessionLock;
  229. //}
  230. };
  231. //
  232. /////////////////////////////////////////////////////////////////////
  233. //
  234. class JBDatabase : public JBError {
  235. friend class JBTable;
  236. private:
  237. JBSession& m_JetSession;
  238. TCHAR m_szDatabaseFile[MAX_PATH+1];
  239. CSafeCounter m_TableOpened;
  240. // DWORD m_TableOpened;
  241. JET_DBID m_JetDbId;
  242. private:
  243. JET_TABLEID
  244. OpenJetTable(
  245. LPCTSTR pszTableName,
  246. void* pvParam=NULL,
  247. unsigned long cbParam=0,
  248. JET_GRBIT grbit=JET_bitTableUpdatable
  249. );
  250. JET_TABLEID
  251. DuplicateJetCursor(
  252. // JET_SESID sesId,
  253. JET_TABLEID tableid,
  254. JET_GRBIT grbit=0 // must be zero
  255. );
  256. JET_TABLEID
  257. CreateJetTable(
  258. LPCTSTR pszTableName,
  259. unsigned long lPage=0,
  260. unsigned long lDensity=20
  261. );
  262. BOOL
  263. CloseJetTable(
  264. // JET_SESID sesId,
  265. JET_TABLEID tableid
  266. );
  267. JET_TABLEID
  268. CreateJetTableEx(
  269. LPCTSTR pszTableName,
  270. const PTLSJBTable table_attribute,
  271. const PTLSJBColumn columns,
  272. const DWORD num_columns,
  273. const PTLSJBIndex index,
  274. const DWORD num_index
  275. );
  276. BOOL
  277. CloseTable(
  278. JET_TABLEID tableid
  279. );
  280. public:
  281. JBDatabase(
  282. JBSession& jbSession,
  283. JET_DBID jdbId=JET_dbidNil,
  284. LPCTSTR pszDatabase=NULL
  285. );
  286. ~JBDatabase();
  287. BOOL
  288. IsValid() const {
  289. return m_JetSession.IsValid() && m_JetDbId != JET_dbidNil;
  290. }
  291. const JBSession&
  292. GetJetSession() const {
  293. return m_JetSession;
  294. }
  295. const JET_SESID
  296. GetJetSessionID() const {
  297. return m_JetSession.GetJetSessionID();
  298. }
  299. const JET_DBID
  300. GetJetDatabaseID() const {
  301. return m_JetDbId;
  302. }
  303. BOOL
  304. Compatible(const JBDatabase& jbDatabase) const {
  305. return GetJetSession().Compatible(jbDatabase.GetJetSession());
  306. }
  307. LPCTSTR
  308. GetDatabaseName() const {
  309. return m_szDatabaseFile;
  310. }
  311. BOOL
  312. OpenDatabase(
  313. LPCTSTR szDatabase,
  314. LPCTSTR szConnect=NULL,
  315. JET_GRBIT grbit=0
  316. );
  317. BOOL
  318. CreateDatabase(
  319. LPCTSTR szDatabase,
  320. LPCTSTR szConnect=NULL,
  321. JET_GRBIT grbit=0
  322. );
  323. BOOL
  324. CloseDatabase(
  325. JET_GRBIT grbit=0
  326. );
  327. BOOL
  328. DeleteTable(
  329. LPCTSTR pszTableName
  330. );
  331. //
  332. // tableid return from JetCreateTable is not usable
  333. //
  334. JET_TABLEID
  335. CreateTable(
  336. LPCTSTR pszTableName,
  337. unsigned long lPage=0,
  338. unsigned long lDensity=20
  339. );
  340. JET_TABLEID
  341. CreateTableEx(
  342. LPCTSTR pszTableName,
  343. const PTLSJBTable table_attribute,
  344. const PTLSJBColumn columns,
  345. DWORD num_columns,
  346. const PTLSJBIndex index,
  347. DWORD num_index
  348. );
  349. //JBTable*
  350. //CreateTable(
  351. // LPCTSTR pszTableName,
  352. // unsigned long lPage=0,
  353. // unsigned long lDensity=20
  354. //);
  355. //JBTable*
  356. //CreateTableEx(
  357. // LPCTSTR pszTableName,
  358. // const PTLSJBTable table_attribute,
  359. // const PTLSJBColumn columns,
  360. // DWORD num_columns,
  361. // const PTLSJBIndex index,
  362. // DWORD num_index
  363. //);
  364. //
  365. // Transaction
  366. //
  367. BOOL
  368. BeginTransaction() {
  369. return m_JetSession.BeginTransaction();
  370. }
  371. BOOL
  372. CommitTransaction(JET_GRBIT grbit=0) {
  373. return m_JetSession.CommitTransaction(grbit);
  374. }
  375. BOOL
  376. RollbackTransaction(JET_GRBIT grbit=JET_bitRollbackAll) {
  377. return m_JetSession.RollbackTransaction(grbit);
  378. }
  379. int
  380. GetTransactionLevel() const {
  381. return m_JetSession.GetTransactionLevel();
  382. }
  383. //CCriticalSection&
  384. //GetSessionLock() {
  385. // return m_JetSession.GetSessionLock();
  386. //}
  387. };
  388. //
  389. /////////////////////////////////////////////////////////////////////
  390. //
  391. // Pure virtual base struct for index
  392. //
  393. struct JBKeyBase {
  394. BOOL m_EmptyValue;
  395. JBKeyBase() : m_EmptyValue(TRUE) {}
  396. void
  397. SetEmptyValue(BOOL bEmpty) { m_EmptyValue = bEmpty; }
  398. virtual JET_GRBIT
  399. GetJetGrbit() {
  400. return JET_bitIndexIgnoreNull;
  401. }
  402. virtual unsigned long
  403. GetJetDensity() {
  404. return TLS_TABLE_INDEX_DEFAULT_DENSITY;
  405. }
  406. virtual BOOL
  407. IsEmptyValue() {
  408. return m_EmptyValue;
  409. }
  410. virtual DWORD
  411. GetKeyLength() {
  412. LPCTSTR pszIndexKey = GetIndexKey();
  413. DWORD keylength;
  414. // calculate index key length, terminated with double 0
  415. keylength = 2;
  416. while(pszIndexKey[keylength-1] != _TEXT('\0') ||
  417. pszIndexKey[keylength-2] != _TEXT('\0'))
  418. {
  419. if(keylength >= TLS_JETBLUE_MAX_INDEXKEY_LENGTH)
  420. {
  421. DebugBreak(); // error
  422. return TLS_JETBLUE_MAX_INDEXKEY_LENGTH;
  423. }
  424. keylength++;
  425. }
  426. return keylength;
  427. }
  428. // ----------------------------------------------------
  429. // Virtual function must be implemented
  430. // ----------------------------------------------------
  431. virtual BOOL
  432. GetSearchKey(
  433. DWORD dwComponentIndex,
  434. PVOID* pbData,
  435. unsigned long* cbData,
  436. JET_GRBIT* grbit,
  437. DWORD dwSearchType
  438. )=0;
  439. virtual LPCTSTR
  440. GetIndexName()=0;
  441. virtual LPCTSTR
  442. GetIndexKey() = 0;
  443. virtual DWORD
  444. GetNumKeyComponents() = 0;
  445. };
  446. //
  447. /////////////////////////////////////////////////////////////////////
  448. //
  449. struct JBIndexStructBase {
  450. virtual LPCTSTR
  451. GetIndexName() = 0;
  452. virtual LPCTSTR
  453. GetIndexKey() = 0;
  454. virtual DWORD
  455. GetNumKeyComponent() = 0;
  456. virtual BOOL
  457. GetSearchKey(
  458. DWORD dwComponentIndex,
  459. PVOID* pbData,
  460. unsigned long* cbData,
  461. JET_GRBIT* grbit,
  462. DWORD dwSearchType
  463. ) = 0;
  464. };
  465. //
  466. /////////////////////////////////////////////////////////////////////
  467. //
  468. class JBTable : public JBError {
  469. friend class JBDatabase;
  470. private:
  471. static JBColumn m_ErrColumn;
  472. JBDatabase& m_JetDatabase;
  473. TCHAR m_szTableName[MAX_TABLENAME_LENGTH+1];
  474. JET_TABLEID m_JetTableId;
  475. typedef struct JetColumns {
  476. TCHAR pszColumnName[MAX_JETBLUE_NAME_LENGTH];
  477. JET_COLTYP colType;
  478. JET_COLUMNID colId;
  479. unsigned long cbMaxLength; // max length of column
  480. JET_GRBIT jbGrbit;
  481. } JetColumns, *PJetColumns;
  482. //PJetColumns m_Columns;
  483. //int m_NumColumns;
  484. JBColumn* m_JetColumns;
  485. int m_NumJetColumns;
  486. BOOL m_InEnumeration;
  487. BOOL m_InsertRepositionBookmark;
  488. private:
  489. JBDatabase&
  490. GetJetDatabase() {
  491. return m_JetDatabase;
  492. }
  493. JET_COLUMNID
  494. AddJetColumn(
  495. LPCTSTR pszColumnName,
  496. const JET_COLUMNDEF* pColumnDef,
  497. const PVOID pbDefaultValue=NULL,
  498. const unsigned long cbDefaultValue=0
  499. );
  500. BOOL
  501. LoadTableInfo();
  502. public:
  503. void
  504. SetInsertRepositionBookmark(
  505. BOOL bRepo
  506. )
  507. /*++
  508. --*/
  509. {
  510. m_InsertRepositionBookmark = bRepo;
  511. return;
  512. }
  513. typedef enum {
  514. ENUM_ERROR=0,
  515. ENUM_SUCCESS,
  516. ENUM_END,
  517. ENUM_CONTINUE
  518. } ENUM_RETCODE;
  519. int
  520. GetNumberOfColumns() {
  521. return m_NumJetColumns;
  522. }
  523. JBTable(
  524. JBDatabase& JetDatabase,
  525. LPCTSTR pszTableName=NULL,
  526. JET_TABLEID tableid=JET_tableidNil
  527. );
  528. JBTable(
  529. JBTable& jbTable
  530. );
  531. ~JBTable();
  532. BOOL
  533. IsValid() const {
  534. return m_JetTableId != JET_tableidNil && m_JetDatabase.IsValid();
  535. }
  536. const JBDatabase&
  537. GetJetDatabase() const {
  538. return m_JetDatabase;
  539. }
  540. const JET_TABLEID
  541. GetJetTableID() const {
  542. return m_JetTableId;
  543. }
  544. const JET_SESID
  545. GetJetSessionID() const {
  546. return m_JetDatabase.GetJetSessionID();
  547. }
  548. const JET_DBID
  549. GetJetDatabaseID() const {
  550. return m_JetDatabase.GetJetDatabaseID();
  551. }
  552. LPCTSTR
  553. GetTableName() const {
  554. return m_szTableName;
  555. }
  556. JBTable*
  557. DuplicateCursor(
  558. JET_GRBIT grbit=0
  559. );
  560. JBTable&
  561. operator=(const JBTable& srcTable);
  562. BOOL
  563. CloseTable();
  564. BOOL
  565. CreateOpenTable(
  566. LPCTSTR pszTableName,
  567. unsigned long lPage=0,
  568. unsigned long lDensity=20
  569. );
  570. BOOL
  571. OpenTable(
  572. LPCTSTR pszTableName,
  573. void* pvParam=NULL,
  574. unsigned long cbParam=0,
  575. JET_GRBIT grbit=0
  576. );
  577. BOOL
  578. AddIndex(
  579. JBKeyBase* key
  580. );
  581. int
  582. AddIndex(
  583. int numIndex,
  584. PTLSJBIndex pIndex
  585. );
  586. BOOL
  587. DoesIndexExist(
  588. LPCTSTR pszIndexName
  589. );
  590. int
  591. AddColumn(
  592. int numColumns,
  593. PTLSJBColumn pColumnDef
  594. );
  595. BOOL
  596. AddJetIndex(
  597. LPCTSTR pszIndexName,
  598. LPCTSTR pszKey,
  599. unsigned long cbKey,
  600. JET_GRBIT jetGrbit,
  601. unsigned long lDensity=20
  602. );
  603. // ----------------------------------------------
  604. // Transaction
  605. // ----------------------------------------------
  606. BOOL
  607. BeginTransaction() {
  608. return m_JetDatabase.BeginTransaction();
  609. }
  610. BOOL
  611. CommitTransaction(JET_GRBIT grbit=0) {
  612. return m_JetDatabase.CommitTransaction(grbit);
  613. }
  614. BOOL
  615. RollbackTransaction(JET_GRBIT grbit=JET_bitRollbackAll) {
  616. return m_JetDatabase.RollbackTransaction(grbit);
  617. }
  618. int
  619. GetTransactionLevel() const {
  620. return m_JetDatabase.GetTransactionLevel();
  621. }
  622. JBColumn*
  623. FindColumnByName(LPCTSTR pszColumnName);
  624. JBColumn*
  625. FindColumnByIndex(const int index);
  626. JBColumn*
  627. FindColumnByColumnId(const JET_COLUMNID);
  628. #if 1
  629. JBColumn&
  630. operator[](LPCTSTR pszColumnName) {
  631. JBColumn* jb = FindColumnByName(pszColumnName);
  632. return (jb) ? *jb : m_ErrColumn;
  633. }
  634. JBColumn&
  635. operator[](const int index) {
  636. JBColumn* jb = FindColumnByIndex(index);
  637. return (jb) ? *jb : m_ErrColumn;
  638. }
  639. JBColumn&
  640. operator[](const JET_COLUMNID jetid) {
  641. JBColumn* jb = FindColumnByColumnId(jetid);
  642. return (jb) ? *jb : m_ErrColumn;
  643. }
  644. #else
  645. JBColumn*
  646. operator[](LPCTSTR pszColumnName) {
  647. return FindColumn(pszColumnName);
  648. }
  649. JBColumn*
  650. operator[](const int index) {
  651. return FindColumn(index);
  652. }
  653. JBColumn*
  654. operator[](const JET_COLUMNID jetid) {
  655. return FindColumn(jetid);
  656. }
  657. #endif
  658. JET_COLUMNID
  659. GetJetColumnID(LPCTSTR pszColumnName);
  660. int
  661. GetJetColumnIndex(LPCTSTR pszColumnName);
  662. BOOL
  663. ReadLock();
  664. BOOL
  665. WriteLock();
  666. BOOL
  667. BeginUpdate(BOOL bUpdate = FALSE);
  668. BOOL
  669. EndUpdate(
  670. BOOL bDiscard = FALSE
  671. );
  672. BOOL
  673. SeekToKey(
  674. JBKeyBase* key,
  675. DWORD dwSearchType,
  676. JET_GRBIT jet_seek_grbit=JET_bitSeekGE
  677. );
  678. BOOL
  679. RetrieveKey(
  680. PVOID pbData,
  681. unsigned long cbData,
  682. unsigned long* pcbActual=NULL,
  683. JET_GRBIT grbit=0
  684. );
  685. //
  686. // Enumeration
  687. //
  688. BOOL
  689. EnumBegin(
  690. LPCTSTR pszIndexName=NULL, // enumeration thru primary index
  691. JET_GRBIT grbit=JET_bitMoveFirst
  692. );
  693. BOOL
  694. MoveToRecord(
  695. long crow=JET_MoveNext,
  696. JET_GRBIT grbit=0
  697. );
  698. BOOL
  699. EnumBegin(
  700. JBKeyBase* key,
  701. DWORD dwParam=0
  702. );
  703. ENUM_RETCODE
  704. EnumNext(
  705. JET_GRBIT crow=JET_MoveNext,
  706. JET_GRBIT grbit=0 //JET_bitMoveKeyNE // limit our traveral to index
  707. );
  708. void
  709. EnumEnd()
  710. {
  711. m_InEnumeration = FALSE;
  712. }
  713. //-----------------------------------------------------------
  714. BOOL
  715. SetCurrentIndex(
  716. LPCTSTR pszIndexName,
  717. JET_GRBIT grbit = JET_bitMoveFirst
  718. );
  719. //-----------------------------------------------------------
  720. BOOL
  721. GetCurrentIndex(
  722. LPTSTR pszIndexName,
  723. unsigned long* bufferSize
  724. );
  725. BOOL
  726. EndOfRecordSet() {
  727. return m_JetErr == JET_errNoCurrentRecord;
  728. }
  729. unsigned long
  730. GetIndexRecordCount(
  731. unsigned long max=0xFFFFFFFF
  732. );
  733. BOOL
  734. MakeKey(
  735. PVOID pbData,
  736. unsigned long cbData,
  737. JET_GRBIT grbit=JET_bitNewKey
  738. );
  739. BOOL
  740. SeekValue(JET_GRBIT grbit=JET_bitSeekEQ);
  741. BOOL
  742. SeekValueEx(
  743. PVOID pbData,
  744. unsigned long cbData,
  745. JET_GRBIT keyGrbit,
  746. JET_GRBIT seekGrbit
  747. )
  748. /*
  749. Only work for single component key
  750. */
  751. {
  752. if(MakeKey(pbData, cbData, keyGrbit) == FALSE)
  753. return FALSE;
  754. return SeekValue(seekGrbit);
  755. }
  756. BOOL
  757. DeleteRecord();
  758. BOOL
  759. GetBookmark(
  760. PVOID pbBookmark,
  761. PDWORD pcbBookmark
  762. );
  763. BOOL
  764. GotoBookmark(
  765. PVOID pbBookmark,
  766. DWORD cbBookmark
  767. );
  768. //CCriticalSection&
  769. //GetSessionLock() {
  770. // return m_JetDatabase.GetSessionLock();
  771. //}
  772. };
  773. //------------------------------------------------------------------------
  774. struct JBColumnBufferBase {
  775. virtual PVOID
  776. GetInputBuffer() = 0;
  777. virtual PVOID
  778. GetOutputBuffer() = 0;
  779. virtual DWORD
  780. GetInputBufferLength() = 0;
  781. virtual DWORD
  782. GetOutputBufferLength() = 0;
  783. };
  784. //------------------------------------------------------------------------
  785. class JBColumn : public JBError {
  786. friend class JBTable;
  787. private:
  788. JBTable* m_pJetTable;
  789. TCHAR m_szColumnName[MAX_JETBLUE_NAME_LENGTH+1];
  790. JET_COLUMNID m_JetColId;
  791. JET_COLTYP m_JetColType;
  792. unsigned long m_JetMaxColLength;
  793. JET_GRBIT m_JetGrbit;
  794. PVOID m_pbDefValue;
  795. int m_cbDefValue;
  796. unsigned long m_JetColCodePage;
  797. unsigned long m_JetColCountryCode;
  798. unsigned long m_JetColLangId;
  799. unsigned long m_cbActual;
  800. JET_RETINFO m_JetRetInfo;
  801. BOOL m_JetNullColumn;
  802. //-------------------------------------------------------------
  803. void Cleanup();
  804. BOOL
  805. LoadJetColumnInfoFromJet(
  806. const JET_COLUMNLIST* column
  807. );
  808. JET_ERR
  809. RetrieveColumnValue(
  810. JET_SESID sesid,
  811. JET_TABLEID tableid,
  812. JET_COLUMNID columnid,
  813. PVOID pbBuffer,
  814. unsigned long cbBuffer,
  815. unsigned long offset=0
  816. );
  817. void
  818. AttachToTable( JBTable* pJetTable ) {
  819. m_pJetTable = pJetTable;
  820. return;
  821. }
  822. public:
  823. JBColumn(JBTable* pJetTable=NULL);
  824. ~JBColumn() {}
  825. const unsigned long
  826. GetMaxColumnLength() const {
  827. return m_JetMaxColLength;
  828. }
  829. BOOL
  830. IsValid() const;
  831. const JET_COLTYP
  832. GetJetColumnType() const {
  833. return m_JetColType;
  834. }
  835. const JET_COLUMNID
  836. GetJetColumnID() const {
  837. return m_JetColId;
  838. }
  839. const JET_SESID
  840. GetJetSessionID() const {
  841. return (m_pJetTable) ? m_pJetTable->GetJetSessionID() : JET_sesidNil;
  842. }
  843. const JET_TABLEID
  844. GetJetTableID() const {
  845. return (m_pJetTable) ? m_pJetTable->GetJetTableID() : JET_tableidNil;
  846. }
  847. LPCTSTR
  848. GetJetColumnName() const {
  849. return (IsValid()) ? m_szColumnName : NULL;
  850. }
  851. const JBTable*
  852. GetJetTable() const {
  853. return m_pJetTable;
  854. }
  855. //
  856. // TODO - append to long binary column
  857. //
  858. BOOL
  859. InsertColumn(
  860. PVOID pbData,
  861. unsigned long cbData,
  862. unsigned long starting_offset=0
  863. );
  864. BOOL
  865. FetchColumn(
  866. PVOID pbData,
  867. unsigned long cbData,
  868. unsigned long starting_offset=0 // for future enhancement
  869. );
  870. void
  871. SetRetrieveOffset( unsigned long offset ) {
  872. m_JetRetInfo.ibLongValue = offset;
  873. }
  874. JBTable*
  875. GetWorkingTable() {
  876. return m_pJetTable;
  877. }
  878. unsigned long
  879. GetDataSize() {
  880. return m_cbActual;
  881. }
  882. //-----------------------------------------------
  883. BOOL
  884. FetchColumn(
  885. JBColumnBufferBase* pBuffer,
  886. DWORD offset=0
  887. )
  888. /*
  889. */
  890. {
  891. return FetchColumn(
  892. pBuffer->GetInputBuffer(),
  893. pBuffer->GetInputBufferLength(),
  894. offset
  895. );
  896. }
  897. BOOL
  898. InsertColumn(
  899. JBColumnBufferBase* pBuffer,
  900. DWORD offset=0
  901. )
  902. /*
  903. */
  904. {
  905. return FetchColumn(
  906. pBuffer->GetOutputBuffer(),
  907. pBuffer->GetOutputBufferLength(),
  908. offset
  909. );
  910. }
  911. };
  912. #endif