summaryrefslogtreecommitdiff
path: root/storage/connect/tabext.h
blob: 6b67c2ab5edfff12b577a00723c2f9b004a4605d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
/*************** Tabext H Declares Source Code File (.H) ***************/
/*  Name: TABEXT.H  Version 1.0                                        */
/*                                                                     */
/*  (C) Copyright to the author Olivier BERTRAND          2017         */
/*                                                                     */
/*  This is the EXTDEF, TABEXT and EXTCOL classes definitions.         */
/***********************************************************************/

#ifndef __TABEXT_H
#define __TABEXT_H

#include "reldef.h"

typedef class ALIAS *PAL;

class ALIAS : public BLOCK {
 public:
	ALIAS(PAL x, PSZ n, PSZ a, bool h)
	     {Next = x, Name = n, Alias = a, Having = h;}

	PAL  Next;
	PSZ  Name;
	PSZ  Alias;
	bool Having;
}; // end of class ALIAS

// Condition filter structure
class CONDFIL : public BLOCK {
 public:
	// Constructor
	CONDFIL(uint idx, AMT type);

	// Functions
	int Init(PGLOBAL g, PHC hc);
	const char *Chk(const char *cln, bool *h);

	// Members
//const Item *Cond;
	AMT   Type;
	uint  Idx;
	OPVAL Op;
	PCMD  Cmds;
	PAL   Alist;
	bool  All;
	bool  Bd;
	bool  Hv;
	char *Body;
	char *Having;
}; // end of class CONDFIL

/***********************************************************************/
/*  This class corresponds to the data base description for external   */
/*  tables of type MYSQL, ODBC, JDBC...                                */
/***********************************************************************/
class DllExport EXTDEF : public TABDEF {                  /* EXT table */
	friend class TDBEXT;
public:
	// Constructor
	EXTDEF(void);                  // Constructor

	// Implementation
	virtual const char *GetType(void) { return "EXT"; }
	inline PCSZ GetTabname(void) { return Tabname; }
	inline PCSZ GetTabschema(void) { return Tabschema; }
	inline PCSZ GetUsername(void) { return Username; };
	inline PCSZ GetPassword(void) { return Password; };
	inline PSZ  GetTabcat(void) { return Tabcat; }
	inline PSZ  GetSrcdef(void) { return Srcdef; }
	inline char GetSep(void) { return (Sep) ? *Sep : 0; }
	inline int  GetQuoted(void) { return Quoted; }
	inline int  GetOptions(void) { return Options; }

	// Methods
	virtual int  Indexable(void) { return 2; }
	virtual bool DefineAM(PGLOBAL g, LPCSTR am, int poff);

protected:
	// Members
	PCSZ    Tabname;              /* External table name                 */
	PCSZ    Tabschema;            /* External table schema               */
	PCSZ    Username;             /* User connect name                   */
	PCSZ    Password;             /* Password connect info               */
	PSZ     Tabcat;               /* External table catalog              */
	PSZ     Tabtyp;               /* Catalog table type                  */
	PSZ     Colpat;               /* Catalog column pattern              */
	PSZ     Srcdef;               /* The source table SQL definition     */
	PSZ     Qchar;                /* Identifier quoting character        */
	PSZ     Qrystr;               /* The original query                  */
	PSZ     Sep;                  /* Decimal separator                   */
//PSZ     Alias;                /* Column alias list                   */
	PSZ     Phpos;                /* Place holer positions               */
	int     Options;              /* Open connection options             */
	int     Cto;                  /* Open connection timeout             */
	int     Qto;                  /* Query (command) timeout             */
	int     Quoted;               /* Identifier quoting level            */
	int     Maxerr;               /* Maxerr for an Exec table            */
	int     Maxres;               /* Maxres for a catalog table          */
	int     Memory;               /* Put result set in memory            */
	bool    Scrollable;           /* Use scrollable cursor               */
	bool    Xsrc;                 /* Execution type                      */
}; // end of EXTDEF

/***********************************************************************/
/*  This is the base class for all external tables.                    */
/***********************************************************************/
class DllExport TDBEXT : public TDB {
	friend class JAVAConn;
	friend class JMgoConn;
public:
	// Constructors
	TDBEXT(EXTDEF *tdp);
	TDBEXT(PTDBEXT tdbp);

	// Implementation

	// Properties
	virtual bool IsRemote(void) { return true; }

	// Methods
	virtual PCSZ GetServer(void) { return "Remote"; }
	virtual int  GetRecpos(void);

	// Database routines
	virtual int  GetMaxSize(PGLOBAL g);
	virtual int  GetProgMax(PGLOBAL g);

protected:
	// Internal functions
	virtual bool MakeSrcdef(PGLOBAL g);
	virtual bool MakeSQL(PGLOBAL g, bool cnt);
	//virtual bool MakeInsert(PGLOBAL g);
	virtual bool MakeCommand(PGLOBAL g);
	int Decode(PCSZ utf, char *buf, size_t n);

	// Members
	PQRYRES Qrp;                // Points to storage result
	PSTRG   Query;              // Constructed SQL query
	PCSZ    TableName;          // Points to ODBC table name
	PCSZ    Schema;             // Points to ODBC table Schema
	PCSZ    User;               // User connect info
	PCSZ    Pwd;                // Password connect info
	char   *Catalog;            // Points to ODBC table Catalog
	char   *Srcdef;             // The source table SQL definition
	char   *Count;              // Points to count(*) SQL statement
 //char   *Where;              // Points to local where clause
	char   *Quote;              // The identifier quoting character
	char   *MulConn;            // Used for multiple ODBC tables
	char   *DBQ;                // The address part of Connect string
	char   *Qrystr;             // The original query
	char    Sep;                // The decimal separator
	int     Options;            // Connect options
	int     Cto;                // Connect timeout
	int     Qto;                // Query timeout
	int     Quoted;             // The identifier quoting level
	int     Fpos;               // Position of last read record
	int     Curpos;             // Cursor position of last fetch
	int     AftRows;            // The number of affected rows
	int     Rows;               // Rowset size
	int     CurNum;             // Current buffer line number
	int     Rbuf;               // Number of lines read in buffer
	int     BufSize;            // Size of connect string buffer
	int     Nparm;              // The number of statement parameters
	int     Memory;             // 0: No 1: Alloc 2: Put 3: Get
	int     Ncol;							  // The column number (JDBC)
	bool    Scrollable;         // Use scrollable cursor
	bool    Placed;             // True for position reading
}; // end of class TDBEXT

/***********************************************************************/
/*  Virtual class EXTCOL: external column.                             */
/***********************************************************************/
class DllExport EXTCOL : public COLBLK {
	friend class TDBEXT;
public:
	// Constructor
	EXTCOL(PCOLDEF cdp, PTDB tdbp, PCOL cprec, int i, PCSZ am);
	EXTCOL(PEXTCOL colp, PTDB tdbp); // Constructor used in copy process

	// Implementation
	inline int   GetRank(void) { return Rank; }
	inline void  SetRank(int k) { Rank = k; }
	//inline PVBLK GetBlkp(void) {return Blkp;}
	inline void  SetCrp(PCOLRES crp) { Crp = crp; }

	// Methods
	virtual bool   SetBuffer(PGLOBAL g, PVAL value, bool ok, bool check);
	virtual void   ReadColumn(PGLOBAL) = 0;
	virtual void   WriteColumn(PGLOBAL) = 0;

protected:
	// Constructor for count(*) column
	EXTCOL(void);

	// Members
	PCOLRES Crp;                 // To storage result
	void   *Bufp;                // To extended buffer
	PVBLK   Blkp;                // To Value Block
	PVAL    To_Val;              // To value used for Insert
	int     Rank;                // Rank (position) number in the query
	//int     Flag;								 // ???
}; // end of class EXTCOL

#endif // __TABEXT_H