home *** CD-ROM | disk | FTP | other *** search
- /* ------------------------------ BTC.HPP ------------------------------- */
-
- /*
- BTC V1.8 - The C++ Class Library for Novell's Btrieve Record Manager 5.10
- (C) 1993 John C. Leon. All Rights Reserved.
- This file last modified 1/25/94.
-
- Written with and fully tested only under Borland C++ 3.1 and Btrieve for
- DOS 5.10 ONLY, with all Btrieve patches available thru the date of this
- file applied.
-
- NOTE: Programs requiring this class library and its related functions
- should be created with project files. The source should
- #include "btc.hpp", and be linked with either BTCS.LIB (small model)
- or BTCL.LIB (large model).
-
- There is no need to include Novell's TURCBTRV.C file when using
- BTC, as the universal Btrieve call is included in the BTC libraries,
- and is declared in BTC.HPP.
-
- COMPILATION NOTES: WORD ALIGNMENT MUST BE OFF!
- "TREAT ENUMS AS INT" MUST BE CHECKED!
-
- */
-
- #ifndef BTC
- #define BTC
-
- extern "C" { int BTRV (int, void*, void*, int*, void*, int); }
-
- /* Misc Types */
- /* ------------------------------------------------------------------------ */
- typedef unsigned char byte;
- enum boolean {false, true};
- typedef char FNameStr[80]; //79 + null pad for a Btrieve filename
-
- /* Btrieve KEY ATTRIBUTES */
- /* ------------------------------------------------------------------------ */
- enum KEY_FLAGS {
- Duplicates = 1, Modifiable = 2, Binary = 4, Null = 8,
- Segmented = 16, AltCol = 32, Descending = 64,
- Supplemental = 128, ExtType = 256, Manual = 512
- };
-
- /* Btrieve KEY TYPES */
- /* ------------------------------------------------------------------------ */
- enum KEY_TYPES {
- BString = 0, BInteger, BFloat, BDate, BTime, BDecimal,
- BMoney, BLogical, BNumeric, BBFloat, BLString, BZString,
- BUnsBinary = 14, BAutoInc
- };
-
- /* Btrieve FILE OPEN MODES */
- /* ------------------------------------------------------------------------ */
- enum OPEN_MODE {
- Exclusive = -4, Verify, ReadOnly, Accel, Normal
- };
-
- /* Btrieve FILE FLAGS */
- /* ------------------------------------------------------------------------ */
- enum FILE_FLAGS {
- VarLength = 1, BlankTrunc, PreAllocate = 4, DataComp = 8,
- KeyOnly = 16, Free10 = 64, Free20 = 128, Free30 = 192
- };
-
- /* Btrieve OP CODES */
- /* ------------------------------------------------------------------------ */
- enum OP_CODE {
- BOpen, BClose, BInsert, BUpdate, BDelete, BGetEqual,
- BGetNext, BGetPrev, BGetGr, BGetGrEq, BGetLess, BGetLessEq,
- BGetFirst, BGetLast, BCreate, BStat, BExtend, BSetDosDir,
- BGetDosDir, BBegTran, BEndTran, BAbortTran, BGetPos, BGetDirect,
- BStepNext, BStop, BVersion, BUnlock, BReset, BSetOwner,
- BClearOwner, BCrSuppIdx, BDropSuppIdx, BStepFirst, BStepLast, BStepPrev,
- BGetNextExt, BGetPrevExt, BStepNextExt, BStepPrevExt, BInsertExt,
- BGetKey = 50
- };
-
- /* Owner-Name Related Types */
- /* ------------------------------------------------------------------------ */
- typedef char OwnerName[9]; //8 chars max plus null
- enum OwnerAccess {RQ, RO, RQENC, ROENC};
-
- /* Selected Btrieve ERROR CODES */
- /* ------------------------------------------------------------------------ */
- typedef enum BTC_ERR_CODES {
- FileNotOpen = 3, DataBufferLength = 22,
- InvalidKeyNumber = 6, RejectCount = 60,
- DiffKeyNumber = 7, IncorrectDesc = 62,
- InvalidPosition = 8, FilterLimit = 64,
- EndofFile = 9, IncorrectFldOff = 65,
- FileNotFound = 12, LostPosition = 82,
- BtrieveNotLoaded = 20
- };
-
- /* Btrieve EXTENDED OPS COMP CODES/BIAS */
- /* ------------------------------------------------------------------------ */
- extern const byte
- Equal = 1, UseAltColl = 32,
- GreaterThan = 2, UseField = 64,
- LessThan = 3, UseNoCase = 128,
- NotEqual = 4,
- GrOrEqual = 5,
- LessOrEqual = 6;
-
- /* Btrieve EXTENDED OPS LOGIC CONSTANTS */
- /* ------------------------------------------------------------------------ */
- extern const int NoFilter = 0;
- //Can't make next items an enum, as they're chars.
- extern const char LastTerm = 0, NextTermAnd = 1, NextTermOr = 2;
-
-
- /* Other BTC-specific Constants */
- /* ------------------------------------------------------------------------ */
- extern const int
- NotRequired = 0, //Dummy for BTRV calls where int not req'd.
- MaxFixedRecLength = 4090, //Btrieve limits fixed rec length for std
- MaxKBufferLength = 255, //files to 4090. Max key size is 255.
- None = 0, Drop = 1, Retain = 2, //These 3 used in CloneFile function.
- MaxExtDBufferLength = 32767, //May be used in future for ext. calls.
- MaxFileSpecLength = 665,
- MaxNumSegments = 24,
- KeySpecSize = 16;
- const int
- MaxDBufferLength = 32767;
-
- /* Other BTC-specific Variables */
- /* ------------------------------------------------------------------------ */
- extern int BStatus,
- VarNotRequired; //Dummy parameter
- extern byte VarPosBlk[128]; //Dummy used in ops that don't pass or
- //return a position block
-
-
- /* ------------------------------------------------------------------------ */
- /* BTC DATA TYPES */
- /* ------------------------------------------------------------------------ */
- /* ------------------------------------------------------------------------ */
-
- /* Data types for TRecMgr class */
- /* ------------------------------------------------------------------------ */
- struct TBTVersion {
- int Number;
- int Rev;
- char Product;
- };
-
- class TBTRecMgr {
- protected:
- boolean BtrieveLoaded;
- TBTVersion Version;
- char VerString[10];
- public:
- TBTRecMgr();
- char* GetVersion() { return VerString; };
- virtual int BT( OP_CODE OpCode, int Key = 0 );
- virtual ~TBTRecMgr() { };
- };
-
- /* Data types for BBase class */
- /* ------------------------------------------------------------------------ */
-
- // TACS and TAltColSeq are for alternate collating sequences
-
- //TACS is for the actual alternate collating sequence itself
- struct TACS {
- byte Header; //Header always equals 0xAC
- char Name[8]; //not DOS filename, but name embedded in file
- byte Table[256];
- };
-
- //TAltColSeq is the class
- class TAltColSeq {
- public:
- TACS Spec;
- TAltColSeq() { };
- TAltColSeq(FNameStr SpecName);
- virtual ~TAltColSeq() { };
- };
-
- union TKeySpec { // Data type for a Btrieve key spec; 'sent' Keyspec
- struct {
- int KeyPos;
- int KeyLen;
- int KeyFlags;
- byte NotUsed[4]; // Tho not used in a create call, these 4 bytes
- byte ExtKeyType; // return number of unique recs in key after a
- byte NullValue; // stat call.
- byte Reserved[4];
- } SKeySpec;
- struct {
- int Irrelevant[3]; //This struct gives ability, on return from a
- unsigned long NumUnique; //stat call, to directly read the number of
- } RKeySpec; //unique records for a key.
- byte Entire[16];
- };
-
- struct TKeyList {
- TKeySpec KeySpec;
- TKeyList *Next;
- };
-
- struct SFileSpec {
- unsigned int RecLen;
- int PageSize;
- int NumKeys;
- unsigned int NumRecs[2];// an array of int, w/high int second
- int FileFlags;
- byte Reserved[2];
- int PreAlloc; //On return from stat, this area holds UnusedPgs.
- TKeySpec KeyArray[24]; //Technically, the KeyArray and AltColSpec merely
- TACS AltColSpec; //allocate space in a buffer of this data type, as
- }; //it is unknown exactly how many key specs there
- //will be, or whether there will be an alternate
- //collating sequence.
-
- struct RFileSpec {
- byte Irrelevant[14];
- unsigned int UnusedPgs; //great after a stat call; corresponds to PreAlloc
- }; //field in struct SFileSpec
-
- union TFileSpec { //full definition of a Btrieve filespec
- SFileSpec FileSpec;
- RFileSpec ReturnFileSpec;
- byte Entire[665];
- };
-
- class CFileSpec { //Useful in programs that use the CreateFile fcn.
- public:
- TFileSpec *Specs;
- TKeyList *KeyList;
- CFileSpec();
- CFileSpec(unsigned int RecLen, int PageSize, int NumKeys,
- TKeyList* AKeyList=NULL, int FileFlags=0, int PreAlloc=0);
- ~CFileSpec();
- };
-
- class BBase {
- protected:
- byte PosBlk[128];
- public:
- TFileSpec Specs;
- FNameStr BFileName;
- int IsOpen;
- int SpecLength;
- long NumRecs;
- int NumSegs;
- boolean HasAltCol;
- boolean IsVariableLength;
- boolean HasOwner;
- OwnerName Owner;
- char AltColName[9]; //8 for largest name, 1 for null
- int DBufferLen;
- BBase() { };
- BBase(FNameStr UserFileName, OPEN_MODE OpenMode=Normal, OwnerName owner="");
- virtual int Open(OPEN_MODE OpenMode=Normal);
- virtual int Close();
- virtual int Stat();
- virtual int BT(OP_CODE OpCode, int Key=0) { return 0; };
- virtual ~BBase();
- };
-
- /* Data types for BFile class */
- /* ------------------------------------------------------------------------ */
- class BFile: public BBase {
- public:
- byte *DBuffer;
- byte *KBuffer;
- unsigned int DBufferSize;
- BFile();
- BFile(FNameStr UserFileName, OPEN_MODE OpenMode = Normal, OwnerName owner = "",
- unsigned int dBufferSize = MaxFixedRecLength);
- virtual int BT(OP_CODE OpCode, int Key = 0);
- virtual int AddSuppIndex(TKeyList* KeyList, FNameStr AltColFile="");
- virtual ~BFile();
- BFile& operator++(); //Overload prefix operators to do step
- BFile& operator++(int); //next(++) and step previous (--).
- BFile& operator--(); //Overload postfix operators to do
- BFile& operator--(int); //insert(++) and delete (--).
- BFile& operator=(BFile& bfixed); //Overload assignment operator to
- //copy data buffer to destination.
- //CloneFile() needs write access to *DBuffer and *KBuffer.
- friend int CloneBTFile(FNameStr CurrentFile, FNameStr NewFile, int Option,
- OwnerName Owner);
- };
-
-
- int CreateBTFile(FNameStr UserFileName, TFileSpec* UserFileSpec,
- FNameStr AltColFile="", OwnerName Owner="",
- OwnerAccess Access=RQ);
- int CloneBTFile(FNameStr CurrentFile, FNameStr NewFile, int Option=Retain,
- OwnerName Owner="");
- TKeyList* NewKeySpec(int KPos, int KLen, int KFlags, byte EType,
- TKeyList *NextKey=0);
- int BtrieveIsLoaded();
-
- #endif
- //end BTC.HPP
-