1 /*************** Tabodbc H Declares Source Code File (.H) **************/ 2 /* Name: TABODBC.H Version 1.9 */ 3 /* */ 4 /* (C) Copyright to the author Olivier BERTRAND 2000-2017 */ 5 /* */ 6 /* This file contains the TDBODBC classes declares. */ 7 /***********************************************************************/ 8 #include "colblk.h" 9 #include "resource.h" 10 11 typedef class ODBCDEF *PODEF; 12 typedef class TDBODBC *PTDBODBC; 13 typedef class ODBCCOL *PODBCCOL; 14 typedef class TDBXDBC *PTDBXDBC; 15 typedef class XSRCCOL *PXSRCCOL; 16 typedef class TDBOIF *PTDBOIF; 17 typedef class OIFCOL *POIFCOL; 18 typedef class TDBSRC *PTDBSRC; 19 20 /***********************************************************************/ 21 /* ODBC table. */ 22 /***********************************************************************/ 23 class DllExport ODBCDEF : public EXTDEF { /* Logical table description */ 24 friend class TDBODBC; 25 friend class TDBXDBC; 26 friend class TDBDRV; 27 friend class TDBOTB; 28 friend class TDBOCL; 29 public: 30 // Constructor 31 ODBCDEF(void); 32 33 // Implementation GetType(void)34 virtual const char *GetType(void) {return "ODBC";} GetConnect(void)35 PSZ GetConnect(void) {return Connect;} GetCatver(void)36 int GetCatver(void) {return Catver;} 37 38 // Methods Indexable(void)39 virtual int Indexable(void) {return 2;} 40 virtual bool DefineAM(PGLOBAL g, LPCSTR am, int poff); 41 virtual PTDB GetTable(PGLOBAL g, MODE m); 42 43 protected: 44 // Members 45 PSZ Connect; /* ODBC connection string */ 46 int Catver; /* ODBC version for catalog functions */ 47 bool UseCnc; /* Use SQLConnect (!SQLDriverConnect) */ 48 }; // end of ODBCDEF 49 50 #if !defined(NODBC) 51 #include "odbconn.h" 52 53 /***********************************************************************/ 54 /* This is the ODBC Access Method class declaration for files from */ 55 /* other DB drivers to be accessed via ODBC. */ 56 /***********************************************************************/ 57 class TDBODBC : public TDBEXT { 58 friend class ODBCCOL; 59 friend class ODBConn; 60 public: 61 // Constructor 62 TDBODBC(PODEF tdp = NULL); 63 TDBODBC(PTDBODBC tdbp); 64 65 // Implementation GetAmType(void)66 virtual AMT GetAmType(void) {return TYPE_AM_ODBC;} Duplicate(PGLOBAL g)67 virtual PTDB Duplicate(PGLOBAL g) 68 {return (PTDB)new(g) TDBODBC(this);} 69 70 // Methods 71 virtual PTDB Clone(PTABS t); 72 virtual bool SetRecpos(PGLOBAL g, int recpos); 73 virtual PCSZ GetFile(PGLOBAL g); 74 virtual void SetFile(PGLOBAL g, PCSZ fn); 75 virtual void ResetSize(void); GetServer(void)76 virtual PCSZ GetServer(void) {return "ODBC";} Indexable(void)77 virtual int Indexable(void) {return 2;} 78 79 // Database routines 80 virtual PCOL MakeCol(PGLOBAL g, PCOLDEF cdp, PCOL cprec, int n); 81 virtual int Cardinality(PGLOBAL g); 82 virtual bool OpenDB(PGLOBAL g); 83 virtual int ReadDB(PGLOBAL g); 84 virtual int WriteDB(PGLOBAL g); 85 virtual int DeleteDB(PGLOBAL g, int irc); 86 virtual void CloseDB(PGLOBAL g); 87 virtual bool ReadKey(PGLOBAL g, OPVAL op, const key_range *kr); 88 89 protected: 90 // Internal functions 91 bool MakeInsert(PGLOBAL g); 92 bool BindParameters(PGLOBAL g); 93 94 // Members 95 ODBConn *Ocp; // Points to an ODBC connection class 96 ODBCCOL *Cnp; // Points to count(*) column 97 ODBCPARM Ops; // Additional parameters 98 char *Connect; // Points to connection string 99 int Catver; // Catalog ODBC version 100 bool UseCnc; // Use SQLConnect (!SQLDriverConnect) 101 }; // end of class TDBODBC 102 103 /***********************************************************************/ 104 /* Class ODBCCOL: ODBC access method column descriptor. */ 105 /* This A.M. is used for ODBC tables. */ 106 /***********************************************************************/ 107 class ODBCCOL : public EXTCOL { 108 friend class TDBODBC; 109 public: 110 // Constructors 111 ODBCCOL(PCOLDEF cdp, PTDB tdbp, PCOL cprec, int i, PCSZ am = "ODBC"); 112 ODBCCOL(ODBCCOL *colp, PTDB tdbp); // Constructor used in copy process 113 114 // Implementation GetAmType(void)115 virtual int GetAmType(void) {return TYPE_AM_ODBC;} GetStrLen(void)116 SQLLEN *GetStrLen(void) {return StrLen;} 117 118 // Methods 119 //virtual bool SetBuffer(PGLOBAL g, PVAL value, bool ok, bool check); 120 virtual void ReadColumn(PGLOBAL g); 121 virtual void WriteColumn(PGLOBAL g); 122 void AllocateBuffers(PGLOBAL g, int rows); 123 void *GetBuffer(DWORD rows); 124 SWORD GetBuflen(void); 125 126 protected: 127 // Constructor for count(*) column 128 ODBCCOL(void); 129 130 // Members 131 TIMESTAMP_STRUCT *Sqlbuf; // To get SQL_TIMESTAMP's 132 SQLLEN *StrLen; // As returned by ODBC 133 SQLLEN Slen; // Used with Fetch 134 }; // end of class ODBCCOL 135 136 /***********************************************************************/ 137 /* This is the ODBC Access Method class declaration that send */ 138 /* commands to be executed by other DB ODBC drivers. */ 139 /***********************************************************************/ 140 class TDBXDBC : public TDBODBC { 141 friend class XSRCCOL; 142 friend class ODBConn; 143 public: 144 // Constructors 145 TDBXDBC(PODEF tdp = NULL); 146 TDBXDBC(PTDBXDBC tdbp); 147 148 // Implementation GetAmType(void)149 virtual AMT GetAmType(void) {return TYPE_AM_XDBC;} Duplicate(PGLOBAL g)150 virtual PTDB Duplicate(PGLOBAL g) 151 {return (PTDB)new(g) TDBXDBC(this);} 152 153 // Methods 154 virtual PTDB Clone(PTABS t); 155 156 // Database routines 157 virtual PCOL MakeCol(PGLOBAL g, PCOLDEF cdp, PCOL cprec, int n); 158 virtual int GetMaxSize(PGLOBAL g); 159 virtual bool OpenDB(PGLOBAL g); 160 virtual int ReadDB(PGLOBAL g); 161 virtual int WriteDB(PGLOBAL g); 162 virtual int DeleteDB(PGLOBAL g, int irc); 163 164 protected: 165 // Internal functions 166 PCMD MakeCMD(PGLOBAL g); 167 168 // Members 169 PCMD Cmdlist; // The commands to execute 170 char *Cmdcol; // The name of the Xsrc command column 171 int Mxr; // Maximum errors before closing 172 int Nerr; // Number of errors so far 173 }; // end of class TDBXDBC 174 175 /***********************************************************************/ 176 /* Used by table in source execute mode. */ 177 /***********************************************************************/ 178 class XSRCCOL : public ODBCCOL { 179 friend class TDBXDBC; 180 public: 181 // Constructors 182 XSRCCOL(PCOLDEF cdp, PTDB tdbp, PCOL cprec, int i, PCSZ am = "ODBC"); 183 XSRCCOL(XSRCCOL *colp, PTDB tdbp); // Constructor used in copy process 184 185 // Implementation 186 187 // Methods 188 virtual void ReadColumn(PGLOBAL g); 189 virtual void WriteColumn(PGLOBAL g); 190 191 protected: 192 // Members 193 char *Buffer; // To get returned message 194 int Flag; // Column content desc 195 }; // end of class XSRCCOL 196 197 /***********************************************************************/ 198 /* This is the class declaration for the Drivers catalog table. */ 199 /***********************************************************************/ 200 class TDBDRV : public TDBCAT { 201 public: 202 // Constructor TDBDRV(PODEF tdp)203 TDBDRV(PODEF tdp) : TDBCAT(tdp) {Maxres = tdp->Maxres;} 204 205 protected: 206 // Specific routines 207 virtual PQRYRES GetResult(PGLOBAL g); 208 209 // Members 210 int Maxres; // Returned lines limit 211 }; // end of class TDBDRV 212 213 /***********************************************************************/ 214 /* This is the class declaration for the Data Sources catalog table. */ 215 /***********************************************************************/ 216 class TDBSRC : public TDBDRV { 217 public: 218 // Constructor TDBSRC(PODEF tdp)219 TDBSRC(PODEF tdp) : TDBDRV(tdp) {} 220 221 protected: 222 // Specific routines 223 virtual PQRYRES GetResult(PGLOBAL g); 224 225 // No additional Members 226 }; // end of class TDBSRC 227 228 /***********************************************************************/ 229 /* This is the class declaration for the tables catalog table. */ 230 /***********************************************************************/ 231 class TDBOTB : public TDBDRV { 232 public: 233 // Constructor 234 TDBOTB(PODEF tdp); 235 236 protected: 237 // Specific routines 238 virtual PQRYRES GetResult(PGLOBAL g); 239 240 // Members 241 PCSZ Dsn; // Points to connection string 242 PCSZ Schema; // Points to schema name or NULL 243 PCSZ Tab; // Points to ODBC table name or pattern 244 PCSZ Tabtyp; // Points to ODBC table type 245 ODBCPARM Ops; // Additional parameters 246 }; // end of class TDBOTB 247 248 /***********************************************************************/ 249 /* This is the class declaration for the columns catalog table. */ 250 /***********************************************************************/ 251 class TDBOCL : public TDBOTB { 252 public: 253 // Constructor 254 TDBOCL(PODEF tdp); 255 256 protected: 257 // Specific routines 258 virtual PQRYRES GetResult(PGLOBAL g); 259 260 // Members 261 char *Colpat; // Points to column pattern 262 }; // end of class TDBOCL 263 264 #endif // !NODBC 265