1 /*************** TabDos H Declares Source Code File (.H) ***************/ 2 /* Name: TABDOS.H Version 3.3 */ 3 /* */ 4 /* (C) Copyright to the author Olivier BERTRAND 1999-2015 */ 5 /* */ 6 /* This file contains the DOS classes declares. */ 7 /***********************************************************************/ 8 9 #ifndef __TABDOS_H 10 #define __TABDOS_H 11 12 #include "xtable.h" // Table base class declares 13 #include "colblk.h" // Column base class declares 14 #include "xindex.h" 15 #include "filter.h" 16 17 //pedef struct _tabdesc *PTABD; // For friend setting 18 typedef class TXTFAM *PTXF; 19 typedef class BLOCKFILTER *PBF; 20 typedef class BLOCKINDEX *PBX; 21 22 /***********************************************************************/ 23 /* DOS table. */ 24 /***********************************************************************/ 25 class DllExport DOSDEF : public TABDEF { /* Logical table description */ 26 friend class OEMDEF; 27 friend class TDBDOS; 28 friend class TDBFIX; 29 friend class TXTFAM; 30 friend class DBFBASE; 31 friend class UNZIPUTL; 32 friend class JSONCOL; 33 friend class TDBDCL; 34 public: 35 // Constructor 36 DOSDEF(void); 37 38 // Implementation 39 virtual AMT GetDefType(void) {return TYPE_AM_DOS;} 40 virtual const char *GetType(void) {return "DOS";} 41 virtual PIXDEF GetIndx(void) {return To_Indx;} 42 virtual void SetIndx(PIXDEF xdp) {To_Indx = xdp;} 43 virtual bool IsHuge(void) {return Huge;} 44 PCSZ GetFn(void) {return Fn;} 45 PCSZ GetOfn(void) {return Ofn;} 46 PCSZ GetEntry(void) {return Entry;} 47 bool GetMul(void) {return Mulentries;} 48 bool GetAppend(void) {return Append;} 49 void SetBlock(int block) { Block = block; } 50 int GetBlock(void) {return Block;} 51 int GetLast(void) {return Last;} 52 void SetLast(int last) {Last = last;} 53 int GetLrecl(void) {return Lrecl;} 54 void SetLrecl(int lrecl) {Lrecl = lrecl;} 55 bool GetPadded(void) {return Padded;} 56 bool GetEof(void) {return Eof;} 57 int GetBlksize(void) {return Blksize;} 58 int GetEnding(void) {return Ending;} 59 bool IsOptimized(void) {return (Optimized == 1);} 60 void SetOptimized(int opt) {Optimized = opt;} 61 void SetAllocBlks(int blks) {AllocBlks = blks;} 62 int GetAllocBlks(void) {return AllocBlks;} 63 int *GetTo_Pos(void) {return To_Pos;} 64 65 // Methods 66 virtual int Indexable(void) 67 {return (!Multiple && !Mulentries && Compressed != 1) ? 1 : 0;} 68 virtual bool DeleteIndexFile(PGLOBAL g, PIXDEF pxdf); 69 virtual bool DefineAM(PGLOBAL g, LPCSTR am, int poff); 70 virtual PTDB GetTable(PGLOBAL g, MODE mode); 71 bool InvalidateIndex(PGLOBAL g); 72 bool GetOptFileName(PGLOBAL g, char *filename); 73 void RemoveOptValues(PGLOBAL g); 74 75 protected: 76 //virtual bool Erase(char *filename); 77 78 // Members 79 PCSZ Fn; /* Path/Name of corresponding file */ 80 PCSZ Ofn; /* Base Path/Name of matching index files*/ 81 PCSZ Entry; /* Zip entry name or pattern */ 82 PCSZ Pwd; /* Zip password */ 83 PIXDEF To_Indx; /* To index definitions blocks */ 84 bool Mapped; /* 0: disk file, 1: memory mapped file */ 85 bool Zipped; /* true for zipped table file */ 86 bool Mulentries; /* true for multiple entries */ 87 bool Append; /* Used when creating zipped table */ 88 bool Padded; /* true for padded table file */ 89 bool Huge; /* true for files larger than 2GB */ 90 bool Accept; /* true if wrong lines are accepted */ 91 bool Eof; /* true if an EOF (0xA) character exists */ 92 int *To_Pos; /* To array of block starting positions */ 93 int Optimized; /* 0: No, 1:Yes, 2:Redo optimization */ 94 int AllocBlks; /* Number of suballocated opt blocks */ 95 int Compressed; /* 0: No, 1: gz, 2:zlib compressed file */ 96 int Lrecl; /* Size of biggest record */ 97 int AvgLen; /* Average size of records */ 98 int Block; /* Number de blocks of FIX/VCT tables */ 99 int Last; /* Number of elements of last block */ 100 int Blksize; /* Size of padded blocks */ 101 int Maxerr; /* Maximum number of bad records (DBF) */ 102 int ReadMode; /* Specific to DBF */ 103 int Ending; /* Length of end of lines */ 104 char Teds; /* Binary table default endian setting */ 105 }; // end of DOSDEF 106 107 /***********************************************************************/ 108 /* This is the DOS/UNIX Access Method class declaration for files */ 109 /* that are standard files with columns starting at fixed offset. */ 110 /* The last column (and record) is of variable length. */ 111 /***********************************************************************/ 112 class DllExport TDBDOS : public TDBASE { 113 friend class XINDEX; 114 friend class DOSCOL; 115 friend class MAPCOL; 116 friend class TXTFAM; 117 friend class DOSFAM; 118 friend class VCTCOL; 119 friend RCODE CntDeleteRow(PGLOBAL, PTDB, bool); 120 public: 121 // Constructors 122 TDBDOS(PDOSDEF tdp, PTXF txfp); 123 TDBDOS(PGLOBAL g, PTDBDOS tdbp); 124 125 // Inline functions 126 inline void SetTxfp(PTXF txfp) {Txfp = txfp; Txfp->SetTdbp(this);} 127 inline PTXF GetTxfp(void) {return Txfp;} 128 inline char *GetLine(void) {return To_Line;} 129 inline int GetCurBlk(void) {return Txfp->GetCurBlk();} 130 inline void SetLine(char *toline) {To_Line = toline;} 131 inline void IncLine(int inc) {To_Line += inc;} 132 inline bool IsRead(void) {return Txfp->IsRead;} 133 inline PXOB *GetLink(void) {return To_Link;} 134 135 // Implementation 136 virtual AMT GetAmType(void) {return Txfp->GetAmType();} 137 virtual PCSZ GetFile(PGLOBAL) {return Txfp->To_File;} 138 virtual void SetFile(PGLOBAL, PCSZ fn) {Txfp->To_File = fn;} 139 virtual void SetAbort(bool b) {Abort = b;} 140 virtual RECFM GetFtype(void) {return Ftype;} 141 virtual bool SkipHeader(PGLOBAL) {return false;} 142 virtual void RestoreNrec(void) {Txfp->SetNrec(1);} 143 virtual PTDB Duplicate(PGLOBAL g) 144 {return (PTDB)new(g) TDBDOS(g, this);} 145 146 // Methods 147 virtual PTDB Clone(PTABS t); 148 virtual void ResetDB(void) {Txfp->Reset();} 149 virtual bool IsUsingTemp(PGLOBAL g); 150 virtual bool IsIndexed(void) {return Indxd;} 151 virtual void ResetSize(void) {MaxSize = Cardinal = -1;} 152 virtual int ResetTableOpt(PGLOBAL g, bool dop, bool dox); 153 virtual int MakeBlockValues(PGLOBAL g); 154 virtual bool SaveBlockValues(PGLOBAL g); 155 virtual bool GetBlockValues(PGLOBAL g); 156 virtual PBF InitBlockFilter(PGLOBAL g, PFIL filp); 157 //virtual PBX InitBlockIndex(PGLOBAL g); 158 virtual int TestBlock(PGLOBAL g); 159 virtual void PrintAM(FILE *f, char *m); 160 161 // Database routines 162 virtual PCOL MakeCol(PGLOBAL g, PCOLDEF cdp, PCOL cprec, int n); 163 virtual char *GetOpenMode(PGLOBAL, char*) {return NULL;} 164 virtual int GetFileLength(PGLOBAL g) {return Txfp->GetFileLength(g);} 165 virtual int GetProgMax(PGLOBAL g); 166 virtual int GetProgCur(void); 167 //virtual int GetAffectedRows(void) {return Txfp->GetDelRows();} 168 virtual int GetRecpos(void) {return Txfp->GetPos();} 169 virtual bool SetRecpos(PGLOBAL g, int recpos) 170 {return Txfp->SetPos(g, recpos);} 171 virtual int RowNumber(PGLOBAL g, bool b = false); 172 virtual int Cardinality(PGLOBAL g); 173 virtual int GetMaxSize(PGLOBAL g); 174 virtual bool OpenDB(PGLOBAL g); 175 virtual int ReadDB(PGLOBAL g); 176 virtual int WriteDB(PGLOBAL g); 177 virtual int DeleteDB(PGLOBAL g, int irc); 178 virtual void CloseDB(PGLOBAL g); 179 virtual int ReadBuffer(PGLOBAL g) {return Txfp->ReadBuffer(g);} 180 181 // Specific routine 182 virtual int EstimatedLength(void); 183 184 // Optimization routines 185 virtual int MakeIndex(PGLOBAL g, PIXDEF pxdf, bool add); 186 bool InitialyzeIndex(PGLOBAL g, PIXDEF xdp, bool sorted); 187 void ResetBlockFilter(PGLOBAL g); 188 bool GetDistinctColumnValues(PGLOBAL g, int nrec); 189 190 protected: 191 virtual bool PrepareWriting(PGLOBAL g); 192 PBF CheckBlockFilari(PGLOBAL g, PXOB *arg, int op, bool *cnv); 193 194 // Members 195 PTXF Txfp; // To the File access method class 196 //PBX To_BlkIdx; // To index test block 197 PBF To_BlkFil; // To evaluation block filter 198 PFIL SavFil; // Saved hidden filter 199 char *To_Line; // Points to current processed line 200 bool Abort; // TRUE when aborting UPDATE/DELETE 201 bool Indxd; // TRUE for indexed UPDATE/DELETE 202 int Lrecl; // Logical Record Length 203 int AvgLen; // Logical Record Average Length 204 //int Xeval; // BlockTest return value 205 int Beval; // BlockEval return value 206 }; // end of class TDBDOS 207 208 /***********************************************************************/ 209 /* Class DOSCOL: DOS access method column descriptor. */ 210 /* This A.M. is used for text file tables under operating systems */ 211 /* DOS, OS2, UNIX, WIN16 and WIN32. */ 212 /***********************************************************************/ 213 class DllExport DOSCOL : public COLBLK { 214 friend class TDBDOS; 215 friend class TDBFIX; 216 public: 217 // Constructors 218 DOSCOL(PGLOBAL g, PCOLDEF cdp, PTDB tp, PCOL cp, int i, PCSZ am = "DOS"); 219 DOSCOL(DOSCOL *colp, PTDB tdbp); // Constructor used in copy process 220 221 // Implementation 222 virtual int GetAmType(void) {return TYPE_AM_DOS;} 223 virtual void SetTo_Val(PVAL valp) {To_Val = valp;} 224 virtual int GetClustered(void) {return Clustered;} 225 virtual int IsClustered(void) {return (Clustered && 226 ((PDOSDEF)(((PTDBDOS)To_Tdb)->To_Def))->IsOptimized());} 227 virtual int IsSorted(void) {return Sorted;} 228 virtual PVBLK GetMin(void) {return Min;} 229 virtual PVBLK GetMax(void) {return Max;} 230 virtual int GetNdv(void) {return Ndv;} 231 virtual int GetNbm(void) {return Nbm;} 232 virtual PVBLK GetBmap(void) {return Bmap;} 233 virtual PVBLK GetDval(void) {return Dval;} 234 235 // Methods 236 virtual bool VarSize(void); 237 virtual bool SetBuffer(PGLOBAL g, PVAL value, bool ok, bool check); 238 virtual void ReadColumn(PGLOBAL g); 239 virtual void WriteColumn(PGLOBAL g); 240 241 protected: 242 virtual bool SetMinMax(PGLOBAL g); 243 virtual bool SetBitMap(PGLOBAL g); 244 bool CheckSorted(PGLOBAL g); 245 bool AddDistinctValue(PGLOBAL g); 246 247 // Default constructor not to be used 248 DOSCOL(void) {} 249 250 // Members 251 PVBLK Min; // Array of block min values 252 PVBLK Max; // Array of block max values 253 PVBLK Bmap; // Array of block bitmap values 254 PVBLK Dval; // Array of column distinct values 255 PVAL To_Val; // To value used for Update/Insert 256 PVAL OldVal; // The previous value of the object. 257 char *Buf; // Buffer used in read/write operations 258 char Dsp; // The decimal separator 259 bool Ldz; // True if field contains leading zeros 260 bool Nod; // True if no decimal point 261 int Dcm; // Last Dcm digits are decimals 262 int Deplac; // Offset in dos_buf 263 int Clustered; // 0:No 1:Yes 264 int Sorted; // 0:No 1:Asc (2:Desc - NIY) 265 int Ndv; // Number of distinct values 266 int Nbm; // Number of uint in bitmap 267 }; // end of class DOSCOL 268 269 #endif // __TABDOS_H 270