1 /*************** Tabext H Declares Source Code File (.H) ***************/ 2 /* Name: TABEXT.H Version 1.1 */ 3 /* */ 4 /* (C) Copyright to the author Olivier BERTRAND 2017 - 2019 */ 5 /* */ 6 /* This is the EXTDEF, TABEXT and EXTCOL classes definitions. */ 7 /***********************************************************************/ 8 9 #ifndef __TABEXT_H 10 #define __TABEXT_H 11 12 #include "reldef.h" 13 14 typedef class ALIAS *PAL; 15 16 class ALIAS : public BLOCK { 17 public: ALIAS(PAL x,PSZ n,PSZ a,bool h)18 ALIAS(PAL x, PSZ n, PSZ a, bool h) 19 {Next = x, Name = n, Alias = a, Having = h;} 20 21 PAL Next; 22 PSZ Name; 23 PSZ Alias; 24 bool Having; 25 }; // end of class ALIAS 26 27 // Condition filter structure 28 class CONDFIL : public BLOCK { 29 public: 30 // Constructor 31 CONDFIL(uint idx, AMT type); 32 33 // Functions 34 int Init(PGLOBAL g, PHC hc); 35 const char *Chk(const char *cln, bool *h); 36 37 // Members 38 //const Item *Cond; 39 AMT Type; 40 uint Idx; 41 OPVAL Op; 42 PCMD Cmds; 43 PAL Alist; 44 bool All; 45 bool Bd; 46 bool Hv; 47 char *Body; 48 char *Having; 49 }; // end of class CONDFIL 50 51 /***********************************************************************/ 52 /* This class corresponds to the data base description for external */ 53 /* tables of type MYSQL, ODBC, JDBC... */ 54 /***********************************************************************/ 55 class DllExport EXTDEF : public TABDEF { /* EXT table */ 56 friend class TDBEXT; 57 public: 58 // Constructor 59 EXTDEF(void); // Constructor 60 61 // Implementation GetType(void)62 virtual const char *GetType(void) { return "EXT"; } GetTabname(void)63 inline PCSZ GetTabname(void) { return Tabname; } GetTabschema(void)64 inline PCSZ GetTabschema(void) { return Tabschema; } GetUsername(void)65 inline PCSZ GetUsername(void) { return Username; }; GetPassword(void)66 inline PCSZ GetPassword(void) { return Password; }; GetTabcat(void)67 inline PSZ GetTabcat(void) { return Tabcat; } GetSrcdef(void)68 inline PSZ GetSrcdef(void) { return Srcdef; } GetSep(void)69 inline char GetSep(void) { return (Sep) ? *Sep : 0; } GetQuoted(void)70 inline int GetQuoted(void) { return Quoted; } GetOptions(void)71 inline int GetOptions(void) { return Options; } 72 73 // Methods Indexable(void)74 virtual int Indexable(void) { return 2; } 75 virtual bool DefineAM(PGLOBAL g, LPCSTR am, int poff); 76 77 protected: 78 // Members 79 PCSZ Tabname; /* External table name */ 80 PCSZ Tabschema; /* External table schema */ 81 PCSZ Username; /* User connect name */ 82 PCSZ Password; /* Password connect info */ 83 PSZ Tabcat; /* External table catalog */ 84 PSZ Tabtyp; /* Catalog table type */ 85 PSZ Colpat; /* Catalog column pattern */ 86 PSZ Srcdef; /* The source table SQL definition */ 87 PSZ Qchar; /* Identifier quoting character */ 88 PSZ Qrystr; /* The original query */ 89 PSZ Sep; /* Decimal separator */ 90 //PSZ Alias; /* Column alias list */ 91 PSZ Phpos; /* Place holer positions */ 92 int Options; /* Open connection options */ 93 int Cto; /* Open connection timeout */ 94 int Qto; /* Query (command) timeout */ 95 int Quoted; /* Identifier quoting level */ 96 int Maxerr; /* Maxerr for an Exec table */ 97 int Maxres; /* Maxres for a catalog table */ 98 int Memory; /* Put result set in memory */ 99 bool Scrollable; /* Use scrollable cursor */ 100 bool Xsrc; /* Execution type */ 101 }; // end of EXTDEF 102 103 /***********************************************************************/ 104 /* This is the base class for all external tables. */ 105 /***********************************************************************/ 106 class DllExport TDBEXT : public TDB { 107 friend class JAVAConn; 108 friend class JMgoConn; 109 public: 110 // Constructors 111 TDBEXT(EXTDEF *tdp); 112 TDBEXT(PTDBEXT tdbp); 113 114 // Implementation 115 116 // Properties IsRemote(void)117 virtual bool IsRemote(void) { return true; } 118 119 // Methods GetServer(void)120 virtual PCSZ GetServer(void) { return "Remote"; } 121 virtual int GetRecpos(void); 122 123 // Database routines 124 virtual int GetMaxSize(PGLOBAL g); 125 virtual int GetProgMax(PGLOBAL g); 126 127 protected: 128 // Internal functions 129 virtual bool MakeSrcdef(PGLOBAL g); 130 virtual bool MakeSQL(PGLOBAL g, bool cnt); 131 //virtual bool MakeInsert(PGLOBAL g); 132 virtual bool MakeCommand(PGLOBAL g); 133 void RemoveConst(PGLOBAL g, char *stmt); 134 int Decode(PCSZ utf, char *buf, size_t n); 135 136 // Members 137 PQRYRES Qrp; // Points to storage result 138 PSTRG Query; // Constructed SQL query 139 PCSZ TableName; // Points to ODBC table name 140 PCSZ Schema; // Points to ODBC table Schema 141 PCSZ User; // User connect info 142 PCSZ Pwd; // Password connect info 143 char *Catalog; // Points to ODBC table Catalog 144 char *Srcdef; // The source table SQL definition 145 char *Count; // Points to count(*) SQL statement 146 //char *Where; // Points to local where clause 147 char *Quote; // The identifier quoting character 148 char *MulConn; // Used for multiple ODBC tables 149 char *DBQ; // The address part of Connect string 150 char *Qrystr; // The original query 151 char Sep; // The decimal separator 152 int Options; // Connect options 153 int Cto; // Connect timeout 154 int Qto; // Query timeout 155 int Quoted; // The identifier quoting level 156 int Fpos; // Position of last read record 157 int Curpos; // Cursor position of last fetch 158 int AftRows; // The number of affected rows 159 int Rows; // Rowset size 160 int CurNum; // Current buffer line number 161 int Rbuf; // Number of lines read in buffer 162 int BufSize; // Size of connect string buffer 163 int Nparm; // The number of statement parameters 164 int Memory; // 0: No 1: Alloc 2: Put 3: Get 165 int Ncol; // The column number (JDBC) 166 bool Scrollable; // Use scrollable cursor 167 bool Placed; // True for position reading 168 }; // end of class TDBEXT 169 170 /***********************************************************************/ 171 /* Virtual class EXTCOL: external column. */ 172 /***********************************************************************/ 173 class DllExport EXTCOL : public COLBLK { 174 friend class TDBEXT; 175 public: 176 // Constructor 177 EXTCOL(PCOLDEF cdp, PTDB tdbp, PCOL cprec, int i, PCSZ am); 178 EXTCOL(PEXTCOL colp, PTDB tdbp); // Constructor used in copy process 179 180 // Implementation GetRank(void)181 inline int GetRank(void) { return Rank; } SetRank(int k)182 inline void SetRank(int k) { Rank = k; } 183 //inline PVBLK GetBlkp(void) {return Blkp;} SetCrp(PCOLRES crp)184 inline void SetCrp(PCOLRES crp) { Crp = crp; } 185 186 // Methods 187 virtual bool SetBuffer(PGLOBAL g, PVAL value, bool ok, bool check); 188 virtual void ReadColumn(PGLOBAL) = 0; 189 virtual void WriteColumn(PGLOBAL) = 0; 190 191 protected: 192 // Constructor for count(*) column 193 EXTCOL(void); 194 195 // Members 196 PCOLRES Crp; // To storage result 197 void *Bufp; // To extended buffer 198 PVBLK Blkp; // To Value Block 199 PVAL To_Val; // To value used for Insert 200 int Rank; // Rank (position) number in the query 201 //int Flag; // ??? 202 }; // end of class EXTCOL 203 204 #endif // __TABEXT_H 205