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

  1. /*********************************************************************
  2. **
  3. **                          BRECORD.H                                        
  4. **
  5. ** This file defines the interface for the BRecord class. This class 
  6. ** encapsulates the notion of a generic table's record. A record
  7. ** is created in the context of a cursor; multiple record objects 
  8. ** can exist in memory corresponding to one or more records of the 
  9. ** cursor.
  10. **
  11. *********************************************************************/
  12.  
  13. // DBF - (C) Copyright 1994 by Borland International
  14.  
  15. #ifndef BRECORD_H 
  16. #define BRECORD_H 
  17.  
  18. #include "envdef.h" 
  19. #include "bdbobjec.h"
  20.  
  21. class BRecord : public BDbObject {
  22.  
  23.   friend class BCursor; 
  24.  
  25. public: 
  26.  
  27.   Retcode   lastError;
  28.   BOOL      bLastNull;
  29.  
  30. public:
  31.  
  32.   // Constructor for making a generic record object for an open cursor.
  33.  
  34.   BRecord(BCursor *cursor = NULL);      
  35.  
  36.   // Destructor; will close the record buffer associated with the record.   
  37.  
  38.   virtual ~BRecord();  
  39.  
  40.   // Close the record buffer associated with the object and delete the  
  41.   // record's association with its cursor.  
  42.  
  43.   virtual Retcode detach(); 
  44.  
  45.   // Establish an association with an open cursor.
  46.  
  47.   virtual Retcode attach(BCursor *cur); 
  48.  
  49.   // Clear the record buffer; set fields to "empty" values.
  50.  
  51.   virtual Retcode clear(); 
  52.  
  53.   // Return the field number for a given field name.   
  54.  
  55.   virtual FIELDNUMBER getFieldNumber(const char *fldName); 
  56.  
  57.   // For a given field number in the record, return the field number in 
  58.   // the table it is derived from. For generic records, both these numbers
  59.   // will be the same. For custom records they can be different.
  60.  
  61.   virtual FIELDNUMBER getTblFieldNumber(FIELDNUMBER fldnbr) ;
  62.  
  63.   // Return the count of fields in the record. 
  64.  
  65.   virtual int getFieldCount(); 
  66.  
  67.   // Given a field number, return its field descriptor.
  68.  
  69.   virtual Retcode getFieldDesc(FIELDNUMBER fldnbr, FieldDesc& desc);  
  70.  
  71.   // Given a field number, return its type, subtype and length. 
  72.  
  73.   virtual Retcode getFieldDesc(FIELDNUMBER fldnbr,
  74.                                PXFieldType &fldType,
  75.                                PXFieldSubtype &fldSubtype, int &fldLen);
  76.  
  77.   // Copy the contents of the record one field at a time in an assignment
  78.   // compatible way to another record.
  79.  
  80.   virtual Retcode copyTo(BRecord *destRec);
  81.  
  82.   // Copy the contents of srcRec one field at a time in an assignment 
  83.   // compatible way to this record. 
  84.  
  85.   virtual Retcode copyFrom(BRecord *srcRec); 
  86.  
  87.   // Obtaining values for a given field in the record, specified by number
  88.   // or name. Data conversion will be applied as is necessary. Void pointer
  89.   // returns value in a format native to the field type in the table.    
  90.  
  91.   virtual Retcode getField(FIELDNUMBER fldnbr, char *buf, 
  92.                            int bufLen, BOOL& fNull); 
  93.  
  94.   virtual Retcode getField(FIELDNUMBER fldnbr, void *buf, 
  95.                            int bufLen, BOOL& fNull); 
  96.  
  97.   virtual Retcode getField(FIELDNUMBER fldnbr, double& val, BOOL& fNull);
  98.  
  99.   virtual Retcode getField(FIELDNUMBER fldnbr, INT16& val, BOOL& fNull);
  100.  
  101.   virtual Retcode getField(FIELDNUMBER fldnbr, INT32& val, BOOL& fNull);
  102.  
  103.   virtual Retcode getField(FIELDNUMBER fldnbr, UINT16& val, BOOL& fNull);
  104.  
  105.   virtual Retcode getField(FIELDNUMBER fldnbr, UINT32& val, BOOL& fNull);
  106.  
  107.   virtual Retcode getField(FIELDNUMBER fldnbr, FMTBcd& val, BOOL& fNull);
  108.  
  109.   virtual Retcode getField(FIELDNUMBER fldnbr, BDate& val, BOOL& fNull);
  110.  
  111.   virtual Retcode getField(FIELDNUMBER fldnbr, BTime& val, BOOL& fNull);
  112.  
  113.   virtual Retcode getField(FIELDNUMBER fldnbr, BTimeStamp& val, BOOL& fNull);
  114.  
  115.   virtual Retcode getField(char *fldName, char *buf, int bufLen,
  116.                            BOOL& fNull);
  117.  
  118.   virtual Retcode getField(char *fldName, void *buf, int bufLen, 
  119.                            BOOL& fNull);
  120.  
  121.   virtual Retcode getField(char *fldName, double& val, BOOL& fNull);
  122.  
  123.   virtual Retcode getField(char *fldName, INT16& val, BOOL& fNull);
  124.  
  125.   virtual Retcode getField(char *fldName, INT32& val, BOOL& fNull);
  126.  
  127.   virtual Retcode getField(char *fldName, UINT16& val, BOOL& fNull);
  128.  
  129.   virtual Retcode getField(char *fldName, UINT32& val, BOOL& fNull);
  130.  
  131.   virtual Retcode getField(char *fldName, FMTBcd& val, BOOL& fNull);
  132.  
  133.   virtual Retcode getField(char *fldName, BDate& val, BOOL& fNull);
  134.  
  135.   virtual Retcode getField(char *fldName, BTime& val, BOOL& fNull);
  136.  
  137.   virtual Retcode getField(char *fldName, BTimeStamp& val, BOOL& fNull);
  138.   
  139.  
  140.   // Put field values in a record, providing the counterpart
  141.   // operations of getField functions. 
  142.  
  143.   virtual Retcode putField(FIELDNUMBER fldnbr, const char *buf);
  144.  
  145.   virtual Retcode putField(FIELDNUMBER fldnbr, const void *buf);
  146.  
  147.   virtual Retcode putField(FIELDNUMBER fldnbr, double val);
  148.  
  149.   virtual Retcode putField(FIELDNUMBER fldnbr, INT16 val);
  150.  
  151.   virtual Retcode putField(FIELDNUMBER fldnbr, INT32 val);
  152.  
  153.   virtual Retcode putField(FIELDNUMBER fldnbr, UINT16 val);
  154.  
  155.   virtual Retcode putField(FIELDNUMBER fldnbr, UINT32 val);
  156.  
  157.   virtual Retcode putField(FIELDNUMBER fldnbr, FMTBcd val);
  158.  
  159.   virtual Retcode putField(FIELDNUMBER fldnbr, const BDate& val);
  160.  
  161.   virtual Retcode putField(FIELDNUMBER fldnbr, const BTime& val);
  162.  
  163.   virtual Retcode putField(FIELDNUMBER fldnbr, const BTimeStamp& val);
  164.  
  165.   virtual Retcode putField(char *fldName, const char *buf);
  166.  
  167.   virtual Retcode putField(char *fldName, const void *buf);
  168.  
  169.   virtual Retcode putField(char *fldName, double val);
  170.  
  171.   virtual Retcode putField(char *fldName, INT16 val);
  172.  
  173.   virtual Retcode putField(char *fldName, INT32 val);
  174.  
  175.   virtual Retcode putField(char *fldName, UINT16 val);
  176.  
  177.   virtual Retcode putField(char *fldName, UINT32 val);
  178.  
  179.   virtual Retcode putField(char *fldName, FMTBcd val);
  180.  
  181.   virtual Retcode putField(char *fldName, const BDate& val);
  182.  
  183.   virtual Retcode putField(char *fldName, const BTime& val);
  184.  
  185.   virtual Retcode putField(char *fldName, const BTimeStamp& val);
  186.  
  187.   // Test if the field specified by number is null.
  188.  
  189.   virtual BOOL isNull(FIELDNUMBER fldnbr);
  190.  
  191.   // Test if the field specified by name is null.
  192.  
  193.   virtual BOOL isNull(const char *fldname);
  194.  
  195.   // Set the field specified by number to null.
  196.  
  197.   virtual Retcode setNull(FIELDNUMBER fldnbr); 
  198.  
  199.   // Set the field specified by name to null.
  200.  
  201.   virtual Retcode setNull(const char *fldName); 
  202.  
  203.   // Clear the field's null flag; used in custom records only.
  204.  
  205.   virtual Retcode clearNull(FIELDNUMBER fldnbr); 
  206.  
  207.   // Clear the field's null flag; used in custom records only.
  208.  
  209.   virtual Retcode clearNull(const char *fldName); 
  210.  
  211.   // Get the handle to the record. WARNING: be carefull when using the
  212.   // handle outside the class.
  213.   
  214.   RECORDHANDLE getHandle();
  215.  
  216.   // Open a Blob field for subsequent read operations.
  217.  
  218.   Retcode openBlobRead(FIELDNUMBER fldnbr,
  219.                        BOOL usePrivateCopy = FALSE);
  220.  
  221.   // Open a Blob field for subsequent write operations. Retain the first   
  222.   // size bytes of the current BLOB. 
  223.  
  224.   Retcode openBlobWrite(FIELDNUMBER fldnbr,
  225.                         long size, BOOL copyOld); 
  226.  
  227.   // Get the header of the BLOB field. 
  228.  
  229.   Retcode getBlobHeader(FIELDNUMBER fldnbr, int size,
  230.                         void *buffer, int& bytesRead);
  231.  
  232.   // Get the size of an open BLOB. 
  233.  
  234.   unsigned long getBlobSize(FIELDNUMBER fldnbr); 
  235.  
  236.   // Read a segment of an open BLOB.
  237.  
  238.   Retcode getBlob(FIELDNUMBER fldnbr, unsigned int size,
  239.                   long offset, void far *buffer);
  240.  
  241.   // Close an open BLOB.
  242.  
  243.   Retcode closeBlob(FIELDNUMBER fldnbr, BOOL accept = TRUE);
  244.  
  245.   // Write a segment into an open BLOB.
  246.  
  247.   Retcode putBlob(FIELDNUMBER fldnbr, unsigned long size,
  248.                   unsigned long offset, void far *buffer);
  249.  
  250.   // Drop a Blob field from a Record.
  251.  
  252.   Retcode dropBlob(FIELDNUMBER fldnbr);
  253.  
  254.   virtual Retcode getField(FIELDNUMBER fldnbr, char *buf,
  255.                            int bufLen);
  256.   virtual Retcode getField(FIELDNUMBER fldnbr, void *buf,
  257.                            int bufLen);
  258.   virtual Retcode getField(FIELDNUMBER fldnbr, double& val);
  259.   virtual Retcode getField(FIELDNUMBER fldnbr, INT16& val);
  260.   virtual Retcode getField(FIELDNUMBER fldnbr, INT32& val);
  261.   virtual Retcode getField(FIELDNUMBER fldnbr, UINT16& val);
  262.   virtual Retcode getField(FIELDNUMBER fldnbr, UINT32& val);
  263.   virtual Retcode getField(FIELDNUMBER fldnbr, FMTBcd& val);
  264.   virtual Retcode getField(FIELDNUMBER fldnbr, BDate& val);
  265.   virtual Retcode getField(FIELDNUMBER fldnbr, BTime& val);
  266.   virtual Retcode getField(FIELDNUMBER fldnbr, BTimeStamp& val);
  267.   virtual Retcode getField(const char *fldName, char *buf, int bufLen);
  268.   virtual Retcode getField(const char *fldName, void *buf, int bufLen);
  269.   virtual Retcode getField(const char *fldName, double& val);
  270.   virtual Retcode getField(const char *fldName, INT16& val);
  271.   virtual Retcode getField(const char *fldName, INT32& val);
  272.   virtual Retcode getField(const char *fldName, UINT16& val);
  273.   virtual Retcode getField(const char *fldName, UINT32& val);
  274.   virtual Retcode getField(const char *fldName, FMTBcd& val);
  275.   virtual Retcode getField(const char *fldName, BDate& val);
  276.   virtual Retcode getField(const char *fldName, BTime& val);
  277.   virtual Retcode getField(const char *fldName, BTimeStamp& val);
  278.  
  279.   virtual Retcode openBlobRead(const char* psFldName,
  280.                                BOOL bUsePrivateCopy);
  281.  
  282.   virtual Retcode openBlobWrite(const char* psFldName,
  283.                                 long nSize,
  284.                                 BOOL bCopyOld);
  285.  
  286.   virtual Retcode getBlobHeader(const char* psFldName,
  287.                                 int nSize,
  288.                                 void* pvBuffer,
  289.                                 int& rnBytesRead);
  290.  
  291.   virtual unsigned long getBlobSize(const char* psFldName);
  292.  
  293.   virtual Retcode getBlob(const char* psFldName,
  294.                           unsigned int nSize,
  295.                           long nOffset,
  296.                           void far *pvBuffer);
  297.  
  298.   virtual Retcode closeBlob(const char* psFldName,
  299.                             BOOL bAccept);
  300.  
  301.   virtual Retcode putBlob(const char* psFldName,
  302.                           unsigned long nSize,
  303.                           unsigned long nOffset,
  304.                           void far *pvBuffer);
  305.  
  306.   virtual Retcode dropBlob(const char* psFldName);
  307.  
  308.  
  309.   // Place holder for user-defined preprocessing routine in a
  310.   // custom record. Insert, update, and append routines will 
  311.   // call this routine before calling the Paradox Engine. 
  312.  
  313.   virtual Retcode preprocess(); 
  314.  
  315.   // Place holder for user-defined postprocessing routine in 
  316.   // a custom record and called by getCurrent function after 
  317.   // fetching a record from a Paradox table. 
  318.  
  319.   virtual Retcode postprocess();
  320.  
  321.   // Redefine pure virtuals from the BDbObject class. 
  322.  
  323.   virtual char *nameOf() const;
  324.   virtual void printOn( ostream& os);
  325.  
  326. protected:
  327.     BCursor         *curH;                // Cursor for this record.
  328.     RECORDHANDLE    recH;                 // IDAPI record handle.
  329.     UINT16          iRecBufSize;
  330.  
  331.     // Don't allow the copy constructor to be called unless specifically
  332.     //   defined
  333.     BRecord(BRecord ©Cur);
  334.     // Don't allow the assignment opperator to be called unless specifically
  335.     //   defined
  336.     BRecord& operator=(BRecord ©Rec);
  337.  
  338. private:
  339.   void        *recobj;          // Variable used to keep track of
  340.                                 // a record's objects.
  341. };
  342.  
  343. #endif
  344.  
  345.