| 1 | /*************** Tabext H Declares Source Code File (.H) ***************/ |
| 2 | /* Name: TABEXT.H Version 1.0 */ |
| 3 | /* */ |
| 4 | /* (C) Copyright to the author Olivier BERTRAND 2017 */ |
| 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: |
| 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 |
| 62 | virtual const char *GetType(void) { return "EXT" ; } |
| 63 | inline PCSZ GetTabname(void) { return Tabname; } |
| 64 | inline PCSZ GetTabschema(void) { return Tabschema; } |
| 65 | inline PCSZ GetUsername(void) { return Username; }; |
| 66 | inline PCSZ GetPassword(void) { return Password; }; |
| 67 | inline PSZ GetTabcat(void) { return Tabcat; } |
| 68 | inline PSZ GetSrcdef(void) { return Srcdef; } |
| 69 | inline char GetSep(void) { return (Sep) ? *Sep : 0; } |
| 70 | inline int GetQuoted(void) { return Quoted; } |
| 71 | inline int GetOptions(void) { return Options; } |
| 72 | |
| 73 | // Methods |
| 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 |
| 117 | virtual bool IsRemote(void) { return true; } |
| 118 | |
| 119 | // Methods |
| 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 | int Decode(PCSZ utf, char *buf, size_t n); |
| 134 | |
| 135 | // Members |
| 136 | PQRYRES Qrp; // Points to storage result |
| 137 | PSTRG Query; // Constructed SQL query |
| 138 | PCSZ TableName; // Points to ODBC table name |
| 139 | PCSZ Schema; // Points to ODBC table Schema |
| 140 | PCSZ User; // User connect info |
| 141 | PCSZ Pwd; // Password connect info |
| 142 | char *Catalog; // Points to ODBC table Catalog |
| 143 | char *Srcdef; // The source table SQL definition |
| 144 | char *Count; // Points to count(*) SQL statement |
| 145 | //char *Where; // Points to local where clause |
| 146 | char *Quote; // The identifier quoting character |
| 147 | char *MulConn; // Used for multiple ODBC tables |
| 148 | char *DBQ; // The address part of Connect string |
| 149 | char *Qrystr; // The original query |
| 150 | char Sep; // The decimal separator |
| 151 | int Options; // Connect options |
| 152 | int Cto; // Connect timeout |
| 153 | int Qto; // Query timeout |
| 154 | int Quoted; // The identifier quoting level |
| 155 | int Fpos; // Position of last read record |
| 156 | int Curpos; // Cursor position of last fetch |
| 157 | int AftRows; // The number of affected rows |
| 158 | int Rows; // Rowset size |
| 159 | int CurNum; // Current buffer line number |
| 160 | int Rbuf; // Number of lines read in buffer |
| 161 | int BufSize; // Size of connect string buffer |
| 162 | int Nparm; // The number of statement parameters |
| 163 | int Memory; // 0: No 1: Alloc 2: Put 3: Get |
| 164 | int Ncol; // The column number (JDBC) |
| 165 | bool Scrollable; // Use scrollable cursor |
| 166 | bool Placed; // True for position reading |
| 167 | }; // end of class TDBEXT |
| 168 | |
| 169 | /***********************************************************************/ |
| 170 | /* Virtual class EXTCOL: external column. */ |
| 171 | /***********************************************************************/ |
| 172 | class DllExport EXTCOL : public COLBLK { |
| 173 | friend class TDBEXT; |
| 174 | public: |
| 175 | // Constructor |
| 176 | EXTCOL(PCOLDEF cdp, PTDB tdbp, PCOL cprec, int i, PCSZ am); |
| 177 | EXTCOL(PEXTCOL colp, PTDB tdbp); // Constructor used in copy process |
| 178 | |
| 179 | // Implementation |
| 180 | inline int GetRank(void) { return Rank; } |
| 181 | inline void SetRank(int k) { Rank = k; } |
| 182 | //inline PVBLK GetBlkp(void) {return Blkp;} |
| 183 | inline void SetCrp(PCOLRES crp) { Crp = crp; } |
| 184 | |
| 185 | // Methods |
| 186 | virtual bool SetBuffer(PGLOBAL g, PVAL value, bool ok, bool check); |
| 187 | virtual void ReadColumn(PGLOBAL) = 0; |
| 188 | virtual void WriteColumn(PGLOBAL) = 0; |
| 189 | |
| 190 | protected: |
| 191 | // Constructor for count(*) column |
| 192 | EXTCOL(void); |
| 193 | |
| 194 | // Members |
| 195 | PCOLRES Crp; // To storage result |
| 196 | void *Bufp; // To extended buffer |
| 197 | PVBLK Blkp; // To Value Block |
| 198 | PVAL To_Val; // To value used for Insert |
| 199 | int Rank; // Rank (position) number in the query |
| 200 | //int Flag; // ??? |
| 201 | }; // end of class EXTCOL |
| 202 | |
| 203 | #endif // __TABEXT_H |
| 204 | |