home *** CD-ROM | disk | FTP | other *** search
- // PXEWIN - (C) Copyright 1992 by Beam Engineering, INC.
-
- // PXTBL.CPP //
-
- // Contents ----------------------------------------------------------------
- //
- // This module contains members of the PXTbl class for interfacing with
- // Paradox tables.
- //
- // End ---------------------------------------------------------------------
-
- // External Reference Name for this Header ---------------------------------
-
- #ifndef PXTBL_CPP
- #define PXTBL_CPP
-
- // End ---------------------------------------------------------------------
-
- // Interface Dependencies --------------------------------------------------
-
- #ifndef PXTBL_HPP
- #include "pxtbl.hpp"
- #endif // PXTBL_HPP //
-
- // End ---------------------------------------------------------------------
-
- // member Empty of PXTbl //
-
- inline int PXTbl::Empty(Pchar name)
- {
- if((EngDataPtr->Errors.pxerr = PXTblEmpty(name)) != PXSUCCESS)
- PXError(ENG_ERROR);
- return EngDataPtr->Errors.pxerr;
- }
-
- // Summary -----------------------------------------------------------------
- //
- // Removes all records from a table.
- //
- // Parameter
- //
- // name. Is the name of the table.
- //
- // Return Value
- //
- // pxerr. Is the PDOX error code.
- //
- // End ---------------------------------------------------------------------
-
- // member Exists fo PXTbl //
-
- inline int PXTbl::Exists(void)
- {
- if((EngDataPtr->Errors.pxerr = PXTblExist(EngDataPtr->name,&exist))
- != PXSUCCESS)
- PXError(ENG_ERROR);
- return EngDataPtr->Errors.pxerr;
- }
-
- // Summary -----------------------------------------------------------------
- //
- // Check and see if a table is empty or not.
- //
- // Return Value
- //
- // pxerr. Returns PDOX error status.
- //
- // End ---------------------------------------------------------------------
-
- // constructor PXTbl //
-
- inline PXTbl::PXTbl(PPXEngObject my_object)
- {
- close_status = CLOSED;
-
- // Point to the engine data structure
-
- EngDataPtr = my_object->EngDataPtr;
- }
-
- // Summary -----------------------------------------------------------------
- //
- // Set the table close status to CLOSED. Set the Engine Data Pointer to
- // the parent object.
- //
- // End ---------------------------------------------------------------------
-
- // destructor PXTbl //
-
- inline PXTbl::~PXTbl(void)
- {
- if(close_status == OPENED)
- {
- if((EngDataPtr->Errors.pxerr =
- PXTblClose(EngDataPtr->tblHandle)) != PXSUCCESS)
- PXError(ENG_ERROR);
- }
- }
-
- // Summary -----------------------------------------------------------------
- //
- // If table is opened, close it.
- //
- // End ---------------------------------------------------------------------
-
- // member build of PXTbl //
-
- PTStreamable PXTbl::build()
- {
- return new PXTbl(streamableInit);
- }
-
- TStreamableClass RegPXTbl("PXTbl",PXTbl::build,
- __DELTA(PXTbl));
-
- // Description -------------------------------------------------------------
- //
- // When the streamable constructor is called, TStreamable dispatches
- // the build member to construct the object. To do this, it must
- // know where to find this member functions for the specific class.
- // This is the reason for the stream registration.
- //
- // End ---------------------------------------------------------------------
-
- // member read of PXTbl //
-
- inline Pvoid PXTbl::read(Ripstream)
- {
- return this;
- }
-
- // Description -------------------------------------------------------------
- //
- // Nothing taken from the stream.
- //
- // End ---------------------------------------------------------------------
-
- // member write of PXTbl //
-
- inline void PXTbl::write(Ropstream)
- {
-
- }
-
- // Description -------------------------------------------------------------
- //
- // Nothing put on the stream.
- //
- // End ---------------------------------------------------------------------
-
- // member NumRecs of PXTbl //
-
- inline int PXTbl::NumRecs()
- {
- if((EngDataPtr->Errors.pxerr = PXTblNRecs(EngDataPtr->tblHandle,
- &EngDataPtr->num_recs)) != PXSUCCESS)
- PXError(ENG_ERROR);
- return EngDataPtr->Errors.pxerr;
- }
-
- // Summary -----------------------------------------------------------------
- //
- // Get the number of records in the table.
- //
- // Return Value
- //
- // pxerr. Returns PDOX error status.
- //
- // End ---------------------------------------------------------------------
-
- // member NumFlds of PXTbl //
-
- inline int PXTbl::NumFlds()
- {
- if((EngDataPtr->Errors.pxerr = PXRecNFlds(EngDataPtr->tblHandle,
- &EngDataPtr->num_fields)) != PXSUCCESS)
- PXError(ENG_ERROR);
- return EngDataPtr->Errors.pxerr;
- }
-
- // Summary -----------------------------------------------------------------
- //
- // Get the number of fields in the table.
- //
- // Return Value
- //
- // pxerr. Returns the number of fields in the database.
- //
- // End ---------------------------------------------------------------------
-
- // member Open of PXtbl //
-
- int PXTbl::Open(int index,int mode,int op)
- {
-
- // Make a copy of all the parameters
-
- inx = index;
- md = mode;
- operation = op;
-
- // Check and see if table exists. If not, set error and return.
-
- if(Exists() != PXSUCCESS)
- return EngDataPtr->Errors.pxerr;
-
- // If table does not exist, return
-
- if(!exist)
- {
- EngDataPtr->Errors.pxerr = PXEWERR_TBLNOTEXIST;
- PXError(EWIN_ERROR);
- return EngDataPtr->Errors.pxerr;
- }
-
- // If OVERWRITE, empty table
-
- if(op == OVERWRITE)
- {
- if(Empty(EngDataPtr->name) != PXSUCCESS)
- return EngDataPtr->Errors.pxerr;
- }
-
- // Open the table
-
- if((EngDataPtr->Errors.pxerr = PXTblOpen(EngDataPtr->name,
- &EngDataPtr->tblHandle,inx,md)) != PXSUCCESS)
- PXError(ENG_ERROR);
- else
- close_status = OPENED;
- return EngDataPtr->Errors.pxerr;
- }
-
- // Summary -----------------------------------------------------------------
- //
- // member opens a table with correct index, mode and operation.
- //
- // Parameters
- //
- // name. This is the name of the table you wish to operate on. You
- // don't need the file extension but you must spec out your path.
- //
- // index. This is the number cooresponding to the index you wish to use
- // on the table.
- //
- // mode. This parameter specifies whether you wish to save every change
- // to the disk imediately or have it buffered.
- //
- // op. This specifies which operation you wish to perform. You can
- // open a table in the following predefined modes:
- //
- // EXISTS. Open if table already exists and you wish to work
- // on it.
- //
- // OVERWRITE. If table exists, open it and empty it.
- //
- // Return Values
- //
- // Returns Paradox error code.
- //
- // Functional Description
- //
- // 1. First check to see if table exist.
- //
- // 2. If you need to OVERWRITE it, empty it first.
- //
- // 3. Open the table.
- //
- // End ---------------------------------------------------------------------
-
- // member Open of PXTbl //
-
- int PXTbl::Open(int nfields,PPchar fields,PPchar types,
- int index,int mode)
- {
-
- // Initialize parameters
-
- inx = index;
- md = mode;
- operation = CREATE;
-
- // Check to see if table exists first
-
- if(Exists())
- return EngDataPtr->Errors.pxerr;
-
- // If table exists, return
-
- if(exist)
- {
- EngDataPtr->Errors.pxerr = PXEWERR_TBLEXIST;
- {
- PXError(EWIN_ERROR);
- return EngDataPtr->Errors.pxerr;
- }
- }
-
- // Create the table
-
- if((EngDataPtr->Errors.pxerr = PXTblCreate(EngDataPtr->name,nfields,
- fields,types)) != PXSUCCESS)
- {
- PXError(ENG_ERROR);
- return EngDataPtr->Errors.pxerr;
- }
-
- // Open the table
-
- if((EngDataPtr->Errors.pxerr = PXTblOpen(EngDataPtr->name,
- &EngDataPtr->tblHandle,inx,md)) != PXSUCCESS)
- PXError(ENG_ERROR);
- return EngDataPtr->Errors.pxerr;
- }
-
- // Summary -----------------------------------------------------------------
- //
- // This member is used to create a new Paradox table and open it.
- //
- // Parameters
- //
- // name. Is the name of the table you wish to create.
- //
- // nfields. Is the number of fields in the database.
- //
- // fields. Is the name of each field.
- //
- // type. Is the type of each field.
- //
- // index. Type of index you wish to use.
- //
- // mode. Mode you wish to open table with.
- //
- // Return Value
- //
- // This member returns the pxerr code.
- //
- // Functional Descrition ---------------------------------------------------
- //
- // Copy parameters. Check to see if the database exists first. If it
- // does, exit. If it does not, create the table and open the table
- // using the parameters.
- //
- // End ---------------------------------------------------------------------
-
- // member PXError of PXTbl //
-
- void PXTbl::PXError(int org)
- {
- // Call base class error handler
-
- PXEngObject::PXError(org);
-
- // Pass the error off to the parent:
-
- EngDataPtr->PXEObjPtr->EngDataPtr->Errors.pxerr =
- EngDataPtr->Errors.pxerr;
- EngDataPtr->PXEObjPtr->PXError(EngDataPtr->Errors.Origin);
- }
-
- // Summary -----------------------------------------------------------------
- //
- // This member handles incomming error messages. The error is passed
- // to the parent object for dispatching it elsewhere. This creates a
- // centralize error interface.
- //
- // End ---------------------------------------------------------------------
-
- #endif // PXTBL_CPP //