| 1 | /**************** Table H Declares Source Code File (.H) ***************/ |
| 2 | /* Name: TABLE.H Version 2.4 */ |
| 3 | /* */ |
| 4 | /* (C) Copyright to the author Olivier BERTRAND 1999-2017 */ |
| 5 | /* */ |
| 6 | /* This file contains the TBX, OPJOIN and TDB class definitions. */ |
| 7 | /***********************************************************************/ |
| 8 | #if !defined(TABLE_DEFINED) |
| 9 | #define TABLE_DEFINED |
| 10 | |
| 11 | |
| 12 | /***********************************************************************/ |
| 13 | /* Include required application header files */ |
| 14 | /* block.h is header containing Block global declarations. */ |
| 15 | /***********************************************************************/ |
| 16 | #include "assert.h" |
| 17 | #include "block.h" |
| 18 | #include "colblk.h" |
| 19 | //#include "m_ctype.h" |
| 20 | #include "reldef.h" |
| 21 | |
| 22 | typedef class CMD *PCMD; |
| 23 | typedef struct st_key_range key_range; |
| 24 | |
| 25 | // Commands executed by XDBC and MYX tables |
| 26 | class CMD : public BLOCK { |
| 27 | public: |
| 28 | // Constructor |
| 29 | CMD(PGLOBAL g, char *cmd) {Cmd = PlugDup(g, cmd); Next = NULL;} |
| 30 | |
| 31 | // Members |
| 32 | PCMD Next; |
| 33 | char *Cmd; |
| 34 | }; // end of class CMD |
| 35 | |
| 36 | typedef class EXTCOL *PEXTCOL; |
| 37 | typedef class CONDFIL *PCFIL; |
| 38 | typedef class TDBCAT *PTDBCAT; |
| 39 | typedef class CATCOL *PCATCOL; |
| 40 | |
| 41 | /***********************************************************************/ |
| 42 | /* Definition of class TDB with all its method functions. */ |
| 43 | /***********************************************************************/ |
| 44 | class DllExport TDB: public BLOCK { // Table Descriptor Block. |
| 45 | public: |
| 46 | // Constructors |
| 47 | TDB(PTABDEF tdp = NULL); |
| 48 | TDB(PTDB tdbp); |
| 49 | |
| 50 | // Implementation |
| 51 | static void SetTnum(int n) {Tnum = n;} |
| 52 | inline PTABDEF GetDef(void) {return To_Def;} |
| 53 | inline PTDB GetOrig(void) {return To_Orig;} |
| 54 | inline TUSE GetUse(void) {return Use;} |
| 55 | inline PCFIL GetCondFil(void) {return To_CondFil;} |
| 56 | inline LPCSTR GetName(void) {return Name;} |
| 57 | inline PTABLE GetTable(void) {return To_Table;} |
| 58 | inline PCOL GetColumns(void) {return Columns;} |
| 59 | inline int GetDegree(void) {return Degree;} |
| 60 | inline MODE GetMode(void) {return Mode;} |
| 61 | inline PFIL GetFilter(void) {return To_Filter;} |
| 62 | inline PCOL GetSetCols(void) {return To_SetCols;} |
| 63 | inline void SetSetCols(PCOL colp) {To_SetCols = colp;} |
| 64 | inline void SetOrig(PTDB txp) {To_Orig = txp;} |
| 65 | inline void SetUse(TUSE n) {Use = n;} |
| 66 | inline void SetCondFil(PCFIL cfp) {To_CondFil = cfp;} |
| 67 | inline void SetNext(PTDB tdbp) {Next = tdbp;} |
| 68 | inline void SetName(LPCSTR name) {Name = name;} |
| 69 | inline void SetTable(PTABLE tablep) {To_Table = tablep;} |
| 70 | inline void SetColumns(PCOL colp) {Columns = colp;} |
| 71 | inline void SetDegree(int degree) {Degree = degree;} |
| 72 | inline void SetMode(MODE mode) {Mode = mode;} |
| 73 | inline const Item *GetCond(void) {return Cond;} |
| 74 | inline void SetCond(const Item *cond) {Cond = cond;} |
| 75 | |
| 76 | // Properties |
| 77 | virtual AMT GetAmType(void) {return TYPE_AM_ERROR;} |
| 78 | virtual bool IsRemote(void) {return false;} |
| 79 | virtual bool IsIndexed(void) {return false;} |
| 80 | virtual void SetFilter(PFIL fp) {To_Filter = fp;} |
| 81 | virtual int GetTdb_No(void) {return Tdb_No;} |
| 82 | virtual PTDB GetNext(void) {return Next;} |
| 83 | virtual PCATLG GetCat(void) {return NULL;} |
| 84 | virtual void SetAbort(bool) {;} |
| 85 | virtual PKXBASE GetKindex(void) {return NULL;} |
| 86 | |
| 87 | // Methods |
| 88 | virtual bool IsSame(PTDB tp) {return tp == this;} |
| 89 | virtual bool IsSpecial(PSZ name); |
| 90 | virtual bool IsReadOnly(void) {return Read_Only;} |
| 91 | virtual bool IsView(void) {return FALSE;} |
| 92 | virtual PCSZ GetPath(void); |
| 93 | virtual RECFM GetFtype(void) {return RECFM_NAF;} |
| 94 | virtual bool GetBlockValues(PGLOBAL) { return false; } |
| 95 | virtual int Cardinality(PGLOBAL) {return 0;} |
| 96 | virtual int GetRecpos(void) = 0; |
| 97 | virtual bool SetRecpos(PGLOBAL g, int recpos); |
| 98 | virtual int GetMaxSize(PGLOBAL) = 0; |
| 99 | virtual int GetProgMax(PGLOBAL) = 0; |
| 100 | virtual int GetProgCur(void) {return GetRecpos();} |
| 101 | virtual PCSZ GetFile(PGLOBAL) {return "Not a file" ;} |
| 102 | virtual void SetFile(PGLOBAL, PCSZ) {} |
| 103 | virtual void ResetDB(void) {} |
| 104 | virtual void ResetSize(void) {MaxSize = -1;} |
| 105 | virtual int RowNumber(PGLOBAL g, bool b = false); |
| 106 | virtual bool CanBeFiltered(void) {return true;} |
| 107 | virtual PTDB Duplicate(PGLOBAL) {return NULL;} |
| 108 | virtual PTDB Clone(PTABS) {return this;} |
| 109 | virtual PTDB Copy(PTABS t); |
| 110 | virtual void PrintAM(FILE *f, char *m) |
| 111 | {fprintf(f, "%s AM(%d)\n" , m, GetAmType());} |
| 112 | virtual void Printf(PGLOBAL g, FILE *f, uint n); |
| 113 | virtual void Prints(PGLOBAL g, char *ps, uint z); |
| 114 | virtual PCSZ GetServer(void) = 0; |
| 115 | virtual int GetBadLines(void) {return 0;} |
| 116 | virtual CHARSET_INFO *data_charset(void); |
| 117 | |
| 118 | // Database routines |
| 119 | virtual PCOL ColDB(PGLOBAL g, PSZ name, int num); |
| 120 | virtual PCOL MakeCol(PGLOBAL, PCOLDEF, PCOL, int) |
| 121 | {assert(false); return NULL;} |
| 122 | virtual PCOL InsertSpecialColumn(PCOL colp); |
| 123 | virtual PCOL InsertSpcBlk(PGLOBAL g, PCOLDEF cdp); |
| 124 | virtual void MarkDB(PGLOBAL g, PTDB tdb2); |
| 125 | virtual bool OpenDB(PGLOBAL) = 0; |
| 126 | virtual int ReadDB(PGLOBAL) = 0; |
| 127 | virtual int WriteDB(PGLOBAL) = 0; |
| 128 | virtual int DeleteDB(PGLOBAL, int) = 0; |
| 129 | virtual void CloseDB(PGLOBAL) = 0; |
| 130 | virtual int CheckWrite(PGLOBAL) {return 0;} |
| 131 | virtual bool ReadKey(PGLOBAL, OPVAL, const key_range *) = 0; |
| 132 | |
| 133 | protected: |
| 134 | // Members |
| 135 | PTDB To_Orig; // Pointer to original if it is a copy |
| 136 | PTABDEF To_Def; // Points to catalog description block |
| 137 | TUSE Use; |
| 138 | PFIL To_Filter; |
| 139 | PCFIL To_CondFil; // To condition filter structure |
| 140 | const Item *Cond; // The condition used to make filters |
| 141 | static int Tnum; // Used to generate Tdb_no's |
| 142 | const int Tdb_No; // GetTdb_No() is always 0 for OPJOIN |
| 143 | PTDB Next; // Next in linearized queries |
| 144 | PTABLE To_Table; // Points to the XTAB object |
| 145 | LPCSTR Name; // Table name |
| 146 | PCOL Columns; // Points to the first column of the table |
| 147 | PCOL To_SetCols; // Points to updated columns |
| 148 | MODE Mode; // 10 Read, 30 Update, 40 Insert, 50 Delete |
| 149 | int Degree; // Number of columns |
| 150 | int Cardinal; // Table number of rows |
| 151 | int MaxSize; // Max size in number of lines |
| 152 | bool Read_Only; // True for read only tables |
| 153 | const CHARSET_INFO *m_data_charset; |
| 154 | const char *csname; // Table charset name |
| 155 | }; // end of class TDB |
| 156 | |
| 157 | /***********************************************************************/ |
| 158 | /* This is the base class for all query tables (except decode). */ |
| 159 | /***********************************************************************/ |
| 160 | class DllExport TDBASE : public TDB { |
| 161 | friend class INDEXDEF; |
| 162 | friend class XINDEX; |
| 163 | friend class XINDXS; |
| 164 | public: |
| 165 | // Constructor |
| 166 | TDBASE(PTABDEF tdp = NULL); |
| 167 | TDBASE(PTDBASE tdbp); |
| 168 | |
| 169 | // Implementation |
| 170 | inline int GetKnum(void) {return Knum;} |
| 171 | inline void SetKey_Col(PCOL *cpp) {To_Key_Col = cpp;} |
| 172 | inline void SetXdp(PIXDEF xdp) {To_Xdp = xdp;} |
| 173 | inline void SetKindex(PKXBASE kxp) {To_Kindex = kxp;} |
| 174 | |
| 175 | // Properties |
| 176 | virtual PKXBASE GetKindex(void) {return To_Kindex;} |
| 177 | void ResetKindex(PGLOBAL g, PKXBASE kxp); |
| 178 | PCOL Key(int i) {return (To_Key_Col) ? To_Key_Col[i] : NULL;} |
| 179 | |
| 180 | // Methods |
| 181 | virtual bool IsUsingTemp(PGLOBAL) {return false;} |
| 182 | virtual PCATLG GetCat(void); |
| 183 | virtual void PrintAM(FILE *f, char *m); |
| 184 | virtual int GetProgMax(PGLOBAL g) {return GetMaxSize(g);} |
| 185 | virtual void RestoreNrec(void) {} |
| 186 | virtual int ResetTableOpt(PGLOBAL g, bool dop, bool dox); |
| 187 | virtual PCSZ GetServer(void) {return "Current" ;} |
| 188 | |
| 189 | // Database routines |
| 190 | virtual int MakeIndex(PGLOBAL g, PIXDEF, bool) |
| 191 | {strcpy(g->Message, "Remote index" ); return RC_INFO;} |
| 192 | virtual bool ReadKey(PGLOBAL, OPVAL, const key_range *) |
| 193 | {assert(false); return true;} |
| 194 | |
| 195 | protected: |
| 196 | virtual bool PrepareWriting(PGLOBAL g) {strcpy(g->Message, |
| 197 | "This function should not be called for this table" ); return true;} |
| 198 | |
| 199 | // Members |
| 200 | PXOB *To_Link; // Points to column of previous relations |
| 201 | PCOL *To_Key_Col; // Points to key columns in current file |
| 202 | PKXBASE To_Kindex; // Points to table key index |
| 203 | PIXDEF To_Xdp; // To the index definition block |
| 204 | RECFM Ftype; // File type: 0-var 1-fixed 2-binary (VCT) |
| 205 | int Knum; // Size of key arrays |
| 206 | }; // end of class TDBASE |
| 207 | |
| 208 | /***********************************************************************/ |
| 209 | /* The abstract base class declaration for the catalog tables. */ |
| 210 | /***********************************************************************/ |
| 211 | class DllExport TDBCAT : public TDBASE { |
| 212 | friend class CATCOL; |
| 213 | public: |
| 214 | // Constructor |
| 215 | TDBCAT(PTABDEF tdp); |
| 216 | |
| 217 | // Implementation |
| 218 | virtual AMT GetAmType(void) {return TYPE_AM_CAT;} |
| 219 | |
| 220 | // Methods |
| 221 | virtual int GetRecpos(void) {return N;} |
| 222 | virtual int GetProgCur(void) {return N;} |
| 223 | virtual int RowNumber(PGLOBAL, bool = false) {return N + 1;} |
| 224 | virtual bool SetRecpos(PGLOBAL g, int recpos); |
| 225 | |
| 226 | // Database routines |
| 227 | virtual PCOL MakeCol(PGLOBAL g, PCOLDEF cdp, PCOL cprec, int n); |
| 228 | virtual int Cardinality(PGLOBAL) {return 10;} // To avoid assert |
| 229 | virtual int GetMaxSize(PGLOBAL g); |
| 230 | virtual bool OpenDB(PGLOBAL g); |
| 231 | virtual int ReadDB(PGLOBAL g); |
| 232 | virtual int WriteDB(PGLOBAL g); |
| 233 | virtual int DeleteDB(PGLOBAL g, int irc); |
| 234 | virtual void CloseDB(PGLOBAL g); |
| 235 | |
| 236 | protected: |
| 237 | // Specific routines |
| 238 | virtual PQRYRES GetResult(PGLOBAL g) = 0; |
| 239 | bool Initialize(PGLOBAL g); |
| 240 | bool InitCol(PGLOBAL g); |
| 241 | |
| 242 | // Members |
| 243 | PQRYRES Qrp; |
| 244 | int N; // Row number |
| 245 | bool Init; |
| 246 | }; // end of class TDBCAT |
| 247 | |
| 248 | /***********************************************************************/ |
| 249 | /* Class CATCOL: ODBC info column. */ |
| 250 | /***********************************************************************/ |
| 251 | class DllExport CATCOL : public COLBLK { |
| 252 | friend class TDBCAT; |
| 253 | public: |
| 254 | // Constructors |
| 255 | CATCOL(PCOLDEF cdp, PTDB tdbp, int n); |
| 256 | |
| 257 | // Implementation |
| 258 | virtual int GetAmType(void) {return TYPE_AM_ODBC;} |
| 259 | |
| 260 | // Methods |
| 261 | virtual void ReadColumn(PGLOBAL g); |
| 262 | |
| 263 | protected: |
| 264 | CATCOL(void) {} // Default constructor not to be used |
| 265 | |
| 266 | // Members |
| 267 | PTDBCAT Tdbp; // Points to ODBC table block |
| 268 | PCOLRES Crp; // The column data array |
| 269 | int Flag; |
| 270 | }; // end of class CATCOL |
| 271 | |
| 272 | #endif // TABLE_DEFINED |
| 273 | |