home *** CD-ROM | disk | FTP | other *** search
/ PC Format (South-Africa) 2001 May / PCFMay2001.iso / Xenon / C++ / FreeCommandLineTools.exe / Include / dbsets.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-01-31  |  7.1 KB  |  243 lines

  1. /***********************************************************************
  2. **      D B S E T S . H                                                *
  3. **                                                                     *
  4. ************************************************************************
  5. ** Copyright (C) 1996 - 1999 Microsoft Corporation                         *
  6. **                 All Rights Reserved                                 *
  7. ************************************************************************/
  8. /*
  9.  
  10.         DBSETS.H
  11.  
  12.         Database recordset class definitions for Microsoft Guide
  13.  
  14.  
  15.  
  16. */
  17.  
  18.  
  19.  
  20. #ifndef _DBSETS_H_
  21. #pragma option push -b -a8 -pc -A- /*P_O_Push*/
  22. #define _DBSETS_H_
  23.  
  24. #include "mstv.h"
  25.  
  26. #ifdef DBSETS_STATIC
  27. #undef COMMMSTVEXPORT
  28. #define COMMMSTVEXPORT
  29. #endif
  30.  
  31. /*
  32.  
  33. The following classes provide an encapsulation of the dbDAO classes that
  34. offers a simplified interface to the database tables.
  35.  
  36. CDatabaseConnection and CDatabaseRecordset are the root classes from
  37. which individual Recordset classes are derived.
  38.  
  39. A Recordset class provides a means to open a recordset, fetch, update,
  40. insert, and delete records, and close the recordset.  The records
  41. produced are of the object type associated with the table.  The
  42. Recordset object itself may be repeatedly opened and closed without
  43. the need for deleting and re-instantiating a new object.
  44.  
  45. For example, the Episode table is accessed using the CEpisodeRecordset class.
  46. It is opened with a where clause parameter that specifies the set of records.
  47. Getting a record produces a CEpisode object, on a one-to-one basis.  The user
  48. is responsible for deleting the object, and appropriate manipulation of the
  49. object is done using the CEpisode methods.
  50.  
  51. Only the current record of an open recordset may be updated or deleted.
  52.  
  53. It is important to note that recordsets are opened by the Jet database engine
  54. as either a Dynaset or Snapshot.  A Dynaset is essentially a list of pointers
  55. to the records in the table.  Data is read from the database only when the
  56. record is actually fetched.  A Snapshot reads all records in the set into a
  57. RAM cache.  Large sets will cause caching to disk and subsequent poorer
  58. performance.  Recordsets will be opened as Dynasets unless the optional lType
  59. parameter specifies otherwise.
  60.  
  61. The record count is not defined on opening a recordset.  Calling
  62. GetRecordCount requires "moving to the last record", which may be slow for
  63. larger recordsets.  Recordsets generated with an ORDER BY clause appear to
  64. correctly set the initial record count.
  65.  
  66.  
  67. */
  68.  
  69. COMMMSTVEXPORT void __stdcall SetJet ( CdbDBEngine* pEngine, CdbWorkspace* pWorkspace, CdbDatabase* pDatabase ); 
  70. COMMMSTVEXPORT CdbDatabase * __stdcall GetDatabase(VOID);
  71. COMMMSTVEXPORT BOOL __stdcall GetDatabaseConnected(VOID);
  72.  
  73.  
  74. class COMMMSTVEXPORT CDatabaseConnection
  75. {
  76.  
  77. //  This class provides the root encapsulation of the Jet engine and
  78. //  the EPG database.
  79.  
  80.  
  81. public:
  82.  
  83.  
  84.     BOOL    StartEngine( const CString &csViewer, const CString &csPassword,
  85.                                              const CString &systemFile);
  86.     BOOL    ConnectToDatabase( const CString &csViewer, const CString &csPassword,
  87.                              const CString &systemFile, const CString &databaseFile, CString csWorkspaceName = "");
  88.  
  89.     BOOL    DisconnectFromDatabase( VOID);
  90.  
  91.     BOOL    CompactDatabase( VOID);
  92.  
  93.     CString  GetWorkspaceName( VOID);
  94.  
  95.     LPUNKNOWN GetWorkspaceUnknown( VOID);
  96.  
  97. protected:
  98.  
  99.     VOID    HandleDBException( CdbException* pException, LPCTSTR SourceOfException);
  100.  
  101.     BOOL     RepairDB( const CString &databaseFile );
  102.  
  103.     BOOL    DataBaseInNeedOfRepair();
  104. };
  105.  
  106.  
  107.  
  108.  
  109.  
  110.     enum // FindType is one of
  111.     {   dbFindFirst = 1,
  112.         dbFindLast,
  113.         dbFindNext,
  114.         dbFindPrevious
  115.     };
  116.  
  117.  
  118.  
  119. class COMMMSTVEXPORT CDatabaseRecordset : public CDatabaseConnection
  120. {
  121.  
  122. // This class provides the root encapsulation for recordset manipulation
  123.  
  124.  
  125. // lType is one of: dbOpenSnapshot or default dbOpenDynaset
  126.                 
  127.  
  128. public:
  129.                 CDatabaseRecordset(VOID);
  130.                ~CDatabaseRecordset(VOID);
  131.  
  132.         virtual BOOL    OpenRecordset( LPCTSTR WhereBy, LONG lType=-1);
  133.  
  134.         BOOL    OpenRecordsetQueryDef( LPCTSTR QueryName, LONG lType=-1);
  135.  
  136.         virtual VOID    CloseRecordset( VOID);
  137.  
  138.         CString GetQueryPrefix( VOID);
  139.  
  140.         LONG    GetRecordCount( VOID);
  141.  
  142.         VOID*   GetRecord( LONG RecordNumber);
  143.  
  144.         BOOL    GotoRecord( LONG RecordNumber);
  145.  
  146.         LONG    FindRecord( LONG FindType, LPCTSTR Criteria);
  147.  
  148.         BOOL    InsertRecord( VOID* cRecordsetObject);
  149.  
  150.         BOOL    UpdateRecord( VOID* cRecordsetObject);
  151.  
  152.         BOOL    DeleteRecord( VOID);
  153.  
  154.         void OpenIndexed(int iKeyID, int nOpenType,
  155.                                         LPCTSTR lpszSQL, int nOptions);
  156.         HRESULT SeekAddRS(CObject &coo);
  157.         bool UpdateRS(CObject &coo);
  158.         bool StartUpdateRS(CObject &coo);
  159.         void EndUpdateRS();
  160.  
  161.         void Edit(void);
  162.         void Update(void);
  163.         void MoveFirst(void);
  164.         void MovePrevious(void);
  165.         void MoveNext(void);
  166.         void MoveLast(void);
  167.         BOOL GetEOF(void);
  168.  
  169.         COleVariant GetField(LPCTSTR pstrIndex);
  170.         LONG GetLongField(LPCTSTR pstrIndex);
  171.         COleVariant GetField(LONG lIndex);
  172.         VOID SetField(LPCTSTR pstrIndex, COleVariant cov);
  173.         ULONG GetFieldSize(LPCTSTR pstrIndex);
  174.  
  175.                 // implemented by child recordset
  176.  
  177. virtual CString GetTableName( VOID) = 0;
  178.  
  179.  
  180.  
  181. protected:      // implemented by child recordset
  182.  
  183. virtual BOOLEAN Seek(LPCTSTR lpszComparison, CObject &coo);
  184.  
  185. virtual VOID*   GetRecordsetObject( VOID) = 0;
  186.  
  187. virtual BOOL    SetRecordsetObject( VOID* cRecordsetObject) = 0;
  188.  
  189.  
  190.  
  191. protected:          // accessed by child recordset
  192.  
  193.     CdbRecordset    m_cRecordset;
  194.  
  195.  
  196. protected:
  197.  
  198.     time_t          m_ConnectTime;
  199.  
  200.     LONG            m_lRecordCount;
  201.     LONG            m_lRecordNumber;
  202.     BOOL            m_bRecordsetOpen;
  203.  
  204. };
  205.  
  206.  
  207. #define AFX_RFX_LONG_PSEUDO_NULL (0x4a4d4120L)    // from afxdb.h
  208.  
  209.  
  210. // Conversion macros - Variant
  211.  
  212. // These macros are used by the GetRecordsetObject routines to convert the
  213. // Variant returned by dbdao to the local data type.
  214. // Note there is no checking for nulls or incorrect data type,
  215. // therefore use these macros at your own risk!
  216.  
  217. #define VAR2BOOL(v)           (v).bVal
  218. #define VAR2BYTE(v)           (v).bVal
  219. #define VAR2SHORT(v)          (v).iVal
  220. #define VAR2LONG(v)           (v).lVal
  221. #define VAR2FLOAT(v)          (v).fltVal
  222. #define VAR2DOUBLE(v)         (v).dblVal
  223. #define VAR2DATE(v)           (v)
  224. #define VAR2CURRENCY(v)       (v)
  225. #define VAR2CSTR(v)  (LPCTSTR)(v).bstrVal
  226.  
  227. // These macros are used in SetRecordsetObject routines to convert the local
  228. // data type to COleVariant for dbdao
  229.  
  230. #define BOOL2OLEVAR(a)      COleVariant((BYTE)(a))
  231. #define BYTE2OLEVAR(a)      COleVariant((a))
  232. #define SHORT2OLEVAR(a)     COleVariant((a))
  233. #define LONG2OLEVAR(a)      COleVariant((a))
  234. #define FLOAT2OLEVAR(a)     COleVariant((a))
  235. #define DOUBLE2OLEVAR(a)    COleVariant((a))
  236. #define DATE2OLEVAR(a)      COleVariant((a))
  237. #define CURRENCY2OLEVAR(a)  COleVariant((a))
  238. #define CSTR2OLEVAR(a)      COleVariant((LPCTSTR)(a),VT_BSTRT)
  239.  
  240. #pragma option pop /*P_O_Pop*/
  241. #endif
  242.  
  243.