home *** CD-ROM | disk | FTP | other *** search
/ Borland Programmer's Resource / Borland_Programmers_Resource_CD_1995.iso / code / kdbf / bcursor.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-19  |  14.0 KB  |  450 lines

  1. /*********************************************************************
  2. **
  3. **                          BCURSOR.H
  4. **
  5. ** This file defines the interface to the BCursor class. This class
  6. ** encapsulates the notion of a table cursor, an active connection
  7. ** to a Paradox table that allows iteration through its records.
  8. ** More than one cursor can be open on a table at the same time.              
  9. **
  10. *********************************************************************/
  11.  
  12. // DBF - (C) Copyright 1994 by Borland International
  13.  
  14. #ifndef BCURSOR_H 
  15. #define BCURSOR_H
  16.  
  17. #include "envdef.h"
  18. #include "bdbobjec.h"
  19.  
  20. class BCursor : public BDbObject {
  21.  
  22.     friend class BDatabase;
  23.     friend class BRecord;
  24.  
  25. public:
  26.  
  27.     // Generic Record for this cursor used internally for some custom record
  28.     // transfer operations. Application programs are free to use this object
  29.     // for the cursor's current record operations.
  30.  
  31.     BRecord *genericRec;
  32.     Retcode lastError;
  33.     BOOL    isOpen;
  34.  
  35. public:
  36.  
  37.     // Constructor. Make a BCursor object without opening any Paradox tables.
  38.  
  39.     BCursor();
  40.  
  41.     // Constructor; make a BCursor object and open the specified Paradox table.
  42.  
  43.     BCursor(BDatabase *db,
  44.             const char *tableName,
  45.             int indexID = 0,
  46.             BOOL saveEveryChange = FALSE,
  47.             DBIOpenMode openMode = dbiREADWRITE,
  48.             DBIShareMode shareMode = dbiOPENSHARED,
  49.             XLTMode xltMode = xltFIELD);
  50.  
  51.     // Constructor; make a BCursor object and open the specified table of the
  52.     // specified type
  53.  
  54.     BCursor(BDatabase *db,
  55.             const char *tableName,
  56.             const char *tableType,
  57.             int indexID,
  58.             DBIOpenMode openMode = dbiREADWRITE,
  59.             DBIShareMode shareMode = dbiOPENSHARED,
  60.             XLTMode xltMode = xltFIELD);
  61.  
  62.     // Constructor; make a BCursor object and open the specified table of the
  63.     // specified type. Use the indexName to identify the index. Note that for
  64.     // dBASE tables, the indexName is used as the indexTagName and the
  65.     // <tablename>.MDX is used as the indexname (idnetifying the production
  66.     // index). 
  67.  
  68.     BCursor(BDatabase *db,
  69.             const char *tableName,
  70.             const char *indexName,
  71.             DBIOpenMode openMode = dbiREADWRITE,
  72.             DBIShareMode shareMode = dbiOPENSHARED,
  73.             XLTMode xltMode = xltFIELD);
  74.  
  75.     // Constructor; make a BCursor object and open the specified table of the
  76.     // specified type. Use the indexName and indexTagName to identify the
  77.     // index. Needed for dBASE tables
  78.  
  79.     BCursor(BDatabase *db,
  80.             const char *tableName,
  81.             const char *indexName,
  82.             const char *indexTagName,
  83.             DBIOpenMode openMode = dbiREADWRITE,
  84.             DBIShareMode shareMode = dbiOPENSHARED,
  85.             XLTMode xltMode = xltFIELD);
  86.  
  87.     // Destructor; closes the engine if it's open.
  88.  
  89.     virtual ~BCursor();
  90.  
  91.     // Open a cursor on the specified table. indexID specifies the
  92.     // index to use.
  93.  
  94.     virtual Retcode open(BDatabase *db,
  95.                          const char *tableName,
  96.                          int indexID = 0,
  97.                          BOOL saveEveryChange = FALSE,
  98.                          DBIOpenMode openMode = dbiREADWRITE,
  99.                          DBIShareMode shareMode = dbiOPENSHARED,
  100.                          XLTMode xltMode = xltFIELD);
  101.   
  102.     // Open a cursor on the specified table. indexID specifies the 
  103.     // index to use.
  104.   
  105.     virtual Retcode open(BDatabase *db,
  106.                          const char *tableName,
  107.                          const char *tableType,
  108.                          int indexID,
  109.                          DBIOpenMode openMode = dbiREADWRITE,
  110.                          DBIShareMode shareMode = dbiOPENSHARED,
  111.                          XLTMode xltMode = xltFIELD);
  112.  
  113.     // Open a cursor on the specified table. Use the indexName to identify
  114.     // the index. Note that for dBASE tables, the indexName is used as the
  115.     // indexTagName and the <tablename>.MDX is used as the indexname
  116.     // (identifying the production index).
  117.  
  118.     virtual Retcode open(BDatabase *db,
  119.                          const char *tableName,
  120.                          const char *indexName,
  121.                          DBIOpenMode openMode = dbiREADWRITE,
  122.                          DBIShareMode shareMode = dbiOPENSHARED,
  123.                          XLTMode xltMode = xltFIELD);
  124.  
  125.     // Open a cursor on the specified table. Use the indexName
  126.     // and the indexTagName to specify the index
  127.   
  128.     virtual Retcode open(BDatabase *db,
  129.                          const char *tableName,
  130.                          const char *indexName,
  131.                          const char *indexTagName,
  132.                          DBIOpenMode openMode = dbiREADWRITE,
  133.                          DBIShareMode shareMode = dbiOPENSHARED,
  134.                          XLTMode xltMode = xltFIELD);
  135.   
  136.     // Attach the cursor to an existing TABLEHANDLE
  137.     
  138.     Retcode attach(BDatabase *db, TABLEHANDLE tableHandle);
  139.                
  140.     // Close the cursor if it's open.
  141.  
  142.     virtual Retcode close();
  143.   
  144.     // Append a record to the end of table. The record can be a 
  145.     // generic or custom record.
  146.   
  147.     virtual Retcode appendRec(BRecord *rec);
  148.   
  149.     // Append a record to the end of table using raw I/O mode 
  150.     // the Paradox Engine. 
  151.     
  152.     virtual Retcode appendRec(const void far *buffer, int size);
  153.  
  154.     // Insert the generic record
  155.     
  156.     virtual Retcode insertRec();
  157.  
  158.     // Insert a record at the current cursor position. The record
  159.     // can be a generic or custom record.
  160.   
  161.     virtual Retcode insertRec(BRecord *rec);
  162.   
  163.     // Insert a record at the current cursor position using raw I/O. 
  164.   
  165.     virtual Retcode insertRec(const void far *buffer, int size);
  166.   
  167.     // Delete the current record of the cursor.
  168.   
  169.     virtual Retcode deleteRec();
  170.  
  171.     // Update the current record using the generic record
  172.  
  173.     virtual Retcode updateRec();
  174.  
  175.     // Update the current record of the cursor. The record can be
  176.     // a generic or custom record.
  177.   
  178.     virtual Retcode updateRec(BRecord *rec);
  179.  
  180.     // Update the current of the cursor using the Paradox
  181.     // Engine's raw I/O mode.
  182.  
  183.     virtual Retcode updateRec(const void far *buffer, int size);
  184.   
  185.     virtual Retcode clearRec(BRecord* rec);
  186.     virtual Retcode clearRec();
  187.  
  188.     // Position the cursor before the first record of the table.
  189.   
  190.     Retcode gotoBegin();
  191.   
  192.     // Position past the last record of the table.
  193.   
  194.     Retcode gotoEnd();
  195.  
  196.     // Go to a specific record number in the table.
  197.   
  198.     Retcode gotoRec(RECORDNUMBER recNum);
  199.   
  200.     // Go to the next record of the table.
  201.   
  202.     Retcode gotoNext();
  203.   
  204.     // Go to the previous record of the table.
  205.   
  206.     Retcode gotoPrev();
  207.   
  208.     // Get the record number of the current record. 
  209.   
  210.     RECORDNUMBER getCurRecNum();
  211.   
  212.     // Get the current record of the cursor, which can be a generic
  213.     // record or a custom record.
  214.  
  215.     virtual Retcode getRecord(BRecord *rec);
  216.  
  217.     // Get the current record of the cursor in its genericRec record variable.
  218.  
  219.     virtual Retcode getRecord();
  220.  
  221.     // Get the next record of the cursor, which can be a generic
  222.     // record or a custom record.
  223.  
  224.     virtual Retcode getNextRecord(BRecord *rec);
  225.  
  226.     // Get the next record of the cursor in its genericRec record variable.
  227.  
  228.     virtual Retcode getNextRecord();
  229.  
  230.     // Get the next record of the cursor, which can be a generic
  231.     // record or a custom record.
  232.  
  233.     virtual Retcode getPreviousRecord(BRecord *rec);
  234.  
  235.     // Get the next record of the cursor in its genericRec record variable.
  236.  
  237.     virtual Retcode getPreviousRecord();
  238.  
  239.     // Get the current record of the cursor using raw I/O.
  240.   
  241.     virtual Retcode getRecord(void far *buffer, int size);
  242.   
  243.     // Lock the table in a shared environment in the requested lock mode.  
  244.   
  245.     Retcode lockTable(PXLockMode lockMode);
  246.  
  247.     // Release a previously acquired lock on a table.
  248.   
  249.     Retcode unlockTable(PXLockMode lockMode);
  250.   
  251.     // Get a lock for the current record of the cursor. 
  252.   
  253.     LOCKHANDLE lockRecord();
  254.   
  255.     // Release the previously acquired lock on a record.
  256.   
  257.     Retcode unlockRecord(LOCKHANDLE lckH);
  258.  
  259.     // Release the lock on the current record.
  260.     
  261.     Retcode unlockRecord();
  262.  
  263.     // Determine whether the current record is locked by another user.
  264.   
  265.     BOOL isLocked();
  266.   
  267.     // Determine if the table of the cursor was changed by another
  268.     // user on the network since the last refresh of the buffers.
  269.   
  270.     BOOL hasChanged();
  271.   
  272.     // Switch the current record which the table is sorted on to the
  273.     // specified index
  274.     
  275.     Retcode switchToIndex(const char *indexName,
  276.                           const char *tagName = NULL);
  277.   
  278.     // Switch the current record which the table is sorted on to the
  279.     // specified index
  280.   
  281.     Retcode switchToIndex(int indexID);
  282.   
  283.     // Refresh the cursor's buffer to reflect changes that
  284.     // may have occurred.
  285.   
  286.     Retcode refresh();
  287.   
  288.     // Find the number of records in the cursor (or table).
  289.   
  290.     RECORDNUMBER getRecCount();
  291.   
  292.     //  Clone a cursor with its associated properties and return 
  293.     //  the new cursor.
  294.   
  295.     virtual BCursor *clone(BOOL stayCurrent = TRUE);
  296.   
  297.     // Position the cursor on the same record as the current record
  298.     // of another cursor on the same table.
  299.   
  300.     Retcode setToCursor(BCursor *otherCursor);
  301.  
  302.     // Search the table for the record that matches key values in keyRec. 
  303.     // The currently open index determines the order of records for the search. 
  304.   
  305.     Retcode searchIndex(const BRecord *keyRec,
  306.                         PXSearchMode mode, int fldCnt = 1);
  307.  
  308.     // Search the table for a record that matches key values supplied as 
  309.     // parameters in the argument list. 
  310.   
  311.     Retcode searchIndex(PXSearchMode mode, int fldCnt, ...);
  312.  
  313.     // Limit the result set of the table using a range
  314.  
  315.     Retcode setRange(BRecord &highRecord, BRecord &lowRecord,
  316.                      BOOL incHigh = TRUE, BOOL incLow = TRUE);
  317.   
  318.     // Remove any ranges that are set on the Cursor
  319.     
  320.     Retcode resetRange();
  321.   
  322.     // Limit the result set of the table using a filter
  323.   
  324.     Retcode addFilter(pCANExpr canExpr, hDBIFilter &filterHandle);
  325.   
  326.     // Activate the specified filter
  327.   
  328.     Retcode activateFilter(hDBIFilter filterHandle);
  329.   
  330.     // Deactivate the specified filter.
  331.     
  332.     Retcode deactivateFilter(hDBIFilter filterHandle);
  333.   
  334.     // Drop the specified filter
  335.  
  336.     Retcode dropFilter(hDBIFilter filterHandle);
  337.   
  338.     // Link the cursor to another cursor
  339.     
  340.     Retcode linkToCursor(BCursor &masterCursor, pUINT16 masterFields,
  341.                          pUINT16 detailFields);
  342.   
  343.     // Unlink the cursor from the master cursor
  344.     
  345.     Retcode unlinkFromCursor();
  346.     
  347.     // Set a property of the Cursor
  348.   
  349.     Retcode setProp(UINT32 prop, UINT32 value);
  350.   
  351.     // Get a property of the Cursor
  352.  
  353.     Retcode getProp(UINT32 prop, pVOID value, UINT16 maxLen,
  354.                     UINT16 &retLen);
  355.  
  356.     // Get the properties of the table
  357.  
  358.     Retcode getProperties(CURProps &curProps);
  359.     
  360.     // Store the current location in the table
  361.   
  362.     Retcode getBookMark(BOOKMARK& bookMark);
  363.   
  364.     // Set the cursor to a stored location in the table
  365.   
  366.     Retcode setToBookMark(BOOKMARK bookMark);
  367.  
  368.     // Compare two bookMarks
  369.  
  370.     Retcode compareBookMarks(BOOKMARK bookMark1, BOOKMARK bookMark2,
  371.                              CMPBkMkRslt &rslt);
  372.  
  373.     // Free memory allocated for the bookMark
  374.  
  375.     Retcode freeBookMark(BOOKMARK bookMark);
  376.  
  377.     // Limit the number of fields that are displayed
  378.     // NOTE: Need to changed this function to take a FieldMap as the
  379.     // parameter.
  380.  
  381.     Retcode setFieldMap(UINT16 numberOfFields, FLDDesc *fieldDesc);
  382.  
  383.     // Remove any Field Mappings
  384.  
  385.     Retcode dropFieldMap();
  386.  
  387.     // dBASE only. If the current record is marked as Deleted,
  388.     //  will undelete that record.
  389.  
  390.     Retcode undeleteRecord();
  391.  
  392.     // dBASE only. Remove undeleted records. Regenerate
  393.     //  maintained indexes.
  394.  
  395.     Retcode BCursor::packTable(BOOL regenIndexes = TRUE);
  396.  
  397.     // Get the handle to the Cursor. WARNING: Be carefull when using
  398.     // the handle outside of the class.
  399.  
  400.     TABLEHANDLE getHandle();
  401.  
  402.     // Get the status of the curosr
  403.  
  404.     virtual PXCursorStatus getCurStatus();
  405.  
  406.     // Function called whenever the underlying cursor has changed.
  407.     //   For example, if the current record has changed.
  408.  
  409.     virtual Retcode curChange();
  410.  
  411.     // Redefine pure virtuals from the BDbObject class.
  412.  
  413.     virtual char *nameOf() const;
  414.     virtual void printOn( ostream& os);
  415.  
  416. protected:
  417.     char              *tabname;
  418.     char              tabtype[DBIMAXNAMELEN+1];
  419.     TABLEHANDLE       tabH;              // Table handle for cursor.
  420.     TABLEHANDLE       *masterTabH;       // Handle used for Linked Cursors
  421.     PXCursorStatus    curStatus;         // At Begin, End, Crack, or
  422.                                          // on a record.
  423.   
  424. protected:
  425.  
  426.     // Don't allow the copy constructor to be called unless specifically
  427.     //   defined
  428.     BCursor(BCursor ©Cur);
  429.     // Don't allow the assignment opperator to be called unless specifically
  430.     //   defined
  431.     BCursor& operator=(BCursor ©Cur);
  432.  
  433.     // Get the IDAPI handle to a Table - only called from BCursor methods
  434.     virtual Retcode openTable(BDatabase *db,
  435.                               const char *tableName,
  436.                               const char *tblType,
  437.                               int indexID,
  438.                               DBIOpenMode openMode = dbiREADWRITE,
  439.                               DBIShareMode shareMode = dbiOPENSHARED,
  440.                               XLTMode xltMode = xltFIELD);
  441.  
  442. private:
  443.     void            *curobj;             // Variable used to keep track of
  444.                                          // cursor's objects.
  445.     TIMESTAMP       lastChange;
  446. };
  447.  
  448. #endif
  449.  
  450.