summaryrefslogtreecommitdiff
path: root/storage/connect/tabmysql.h
blob: 39fba87bcc96f513d00f4e65fa922dd40709762c (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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
// TDBMYSQL.H     Olivier Bertrand    2007-2017
#include "myconn.h"               // MySQL connection declares

typedef class MYSQLDEF *PMYDEF;
typedef class TDBMYSQL *PTDBMY;
typedef class MYSQLCOL *PMYCOL;
typedef class TDBMYEXC *PTDBMYX;
typedef class MYXCOL   *PMYXCOL;
typedef class MYSQLC   *PMYC;

/* ------------------------- MYSQL classes --------------------------- */

/***********************************************************************/
/*  MYSQL: table type that are MySQL tables.                           */
/*  Using embedded MySQL library (or optionally calling a MySQL server)*/
/***********************************************************************/

/***********************************************************************/
/*  MYSQL table.                                                       */
/***********************************************************************/
class MYSQLDEF : public EXTDEF           {/* Logical table description */
  friend class TDBMYSQL;
  friend class TDBMYEXC;
  friend class TDBMCL;
  friend class ha_connect;
 public:
  // Constructor
  MYSQLDEF(void);

  // Implementation
  virtual const char *GetType(void) {return "MYSQL";}
  inline  PSZ  GetHostname(void) {return Hostname;};
//inline  PSZ  GetDatabase(void) {return Tabschema;};
//inline  PSZ  GetTabname(void) {return Tabname;}
//inline  PSZ  GetSrcdef(void) {return Srcdef;}
//inline  PSZ  GetUsername(void) {return Username;};
//inline  PSZ  GetPassword(void) {return Password;};
  inline  int  GetPortnumber(void) {return Portnumber;}

  // Methods
//virtual int  Indexable(void) {return 2;}
  virtual bool DefineAM(PGLOBAL g, LPCSTR am, int poff);
  virtual PTDB GetTable(PGLOBAL g, MODE m);
          bool ParseURL(PGLOBAL g, char *url, bool b = true);
          bool GetServerInfo(PGLOBAL g, const char *server_name);

 protected:
  // Members
  PSZ     Hostname;           /* Host machine to use                   */
//PSZ     Tabschema;          /* Database to be used by server         */
//PSZ     Tabname;            /* External table name                   */
//PSZ     Srcdef;             /* The source table SQL definition       */
//PSZ     Username;           /* User logon name                       */
//PSZ     Password;           /* Password logon info                   */
  PSZ     Server;             /* PServerID                             */
//PSZ     Qrystr;             /* The original query                    */
  int     Portnumber;         /* MySQL port number (0 = default)       */
//int     Maxerr;             /* Maxerr for an Exec table              */
//int     Quoted;             /* Identifier quoting level              */
  bool    Isview;             /* true if this table is a MySQL view    */
  bool    Bind;               /* Use prepared statement on insert      */
  bool    Delayed;            /* Delayed insert                        */
//bool    Xsrc;               /* Execution type                        */
  bool    Huge;               /* True for big table                    */
  }; // end of MYSQLDEF

/***********************************************************************/
/*  This is the class declaration for the MYSQL table.                 */
/***********************************************************************/
class TDBMYSQL : public TDBEXT {
  friend class MYSQLCOL;
	friend class TDBTBM;
 public:
  // Constructor
  TDBMYSQL(PMYDEF tdp);
  TDBMYSQL(PTDBMY tdbp);

  // Implementation
  virtual AMT  GetAmType(void) {return TYPE_AM_MYSQL;}
  virtual PTDB Duplicate(PGLOBAL g) {return (PTDB)new(g) TDBMYSQL(this);}

  // Methods
  virtual PTDB Clone(PTABS t);
//virtual int  GetAffectedRows(void) {return AftRows;}
  virtual int  GetRecpos(void) {return N;}
  virtual int  GetProgMax(PGLOBAL g);
  virtual void ResetDB(void) {N = 0;}
  virtual int  RowNumber(PGLOBAL g, bool b = false);
  virtual bool IsView(void) {return Isview;}
  virtual PCSZ GetServer(void) {return Server;}
          void SetDatabase(LPCSTR db) {Schema = (char*)db;}

  // Schema routines
  virtual PCOL MakeCol(PGLOBAL g, PCOLDEF cdp, PCOL cprec, int n);
  virtual int  Cardinality(PGLOBAL g);
//virtual int  GetMaxSize(PGLOBAL g);
  virtual bool OpenDB(PGLOBAL g);
  virtual int  ReadDB(PGLOBAL g);
  virtual int  WriteDB(PGLOBAL g);
  virtual int  DeleteDB(PGLOBAL g, int irc);
  virtual void CloseDB(PGLOBAL g);
  virtual bool ReadKey(PGLOBAL g, OPVAL op, const key_range *kr);

  // Specific routines
          bool SetColumnRanks(PGLOBAL g);
          PCOL MakeFieldColumn(PGLOBAL g, char *name);
          PSZ  FindFieldColumn(char *name);

 protected:
  // Internal functions
  bool MakeSelect(PGLOBAL g, bool mx);
  bool MakeInsert(PGLOBAL g);
  int  BindColumns(PGLOBAL g __attribute__((unused)));
  virtual bool MakeCommand(PGLOBAL g);
//int  MakeUpdate(PGLOBAL g);  
//int  MakeDelete(PGLOBAL g);
  int  SendCommand(PGLOBAL g);

  // Members
  MYSQLC      Myc;            // MySQL connection class
  MYSQL_BIND *Bind;           // To the MySQL bind structure array
//PSTRG       Query;          // Constructed SQL query
  char       *Host;           // Host machine to use
//char       *User;           // User logon info
//char       *Pwd;            // Password logon info
//char       *Schema;         // Database to be used by server
//char       *TableName;      // External table name
//char       *Srcdef;         // The source table SQL definition
  char       *Server;         // The server ID
//char       *Qrystr;         // The original query
  bool        Fetched;        // True when fetch was done
  bool        Isview;         // True if this table is a MySQL view
  bool        Prep;           // Use prepared statement on insert
  bool        Delayed;        // Use delayed insert
  int         m_Rc;           // Return code from command
//int         AftRows;        // The number of affected rows
  int         N;              // The current table index
  int         Port;           // MySQL port number (0 = default) 
//int         Nparm;          // The number of statement parameters
//int         Quoted;         // The identifier quoting level
  }; // end of class TDBMYSQL

/***********************************************************************/
/*  Class MYSQLCOL: MySQL table column.                                */
/***********************************************************************/
class MYSQLCOL : public COLBLK {
  friend class TDBMYSQL;
 public:
  // Constructors
  MYSQLCOL(PCOLDEF cdp, PTDB tdbp, PCOL cprec, int i,  PCSZ am = "MYSQL");
  MYSQLCOL(MYSQL_FIELD *fld, PTDB tdbp, int i,  PCSZ am = "MYSQL");
  MYSQLCOL(MYSQLCOL *colp, PTDB tdbp); // Constructor used in copy process

  // Implementation
  virtual int  GetAmType(void) {return TYPE_AM_MYSQL;}
          void InitBind(PGLOBAL g);

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

 protected:
  // Members
  MYSQL_BIND   *Bind;            // This column bind structure pointer
  PVAL          To_Val;          // To value used for Update/Insert
  unsigned long Slen;            // Bind string lengh
  int           Rank;            // Rank (position) number in the query
  }; // end of class MYSQLCOL

/***********************************************************************/
/*  This is the class declaration for the exec command MYSQL table.    */
/***********************************************************************/
class TDBMYEXC : public TDBMYSQL {
  friend class MYXCOL;
 public:
  // Constructors
  TDBMYEXC(PMYDEF tdp); 
  TDBMYEXC(PTDBMYX tdbp);

  // Implementation
  virtual AMT  GetAmType(void) {return TYPE_AM_MYX;}
  virtual PTDB Duplicate(PGLOBAL g) {return (PTDB)new(g) TDBMYEXC(this);}

  // Methods
  virtual PTDB Clone(PTABS t);
  virtual bool IsView(void) {return Isview;}

  // Database routines
  virtual PCOL MakeCol(PGLOBAL g, PCOLDEF cdp, PCOL cprec, int n);
  virtual int  GetMaxSize(PGLOBAL g);
  virtual bool OpenDB(PGLOBAL g);
  virtual int  ReadDB(PGLOBAL g);
  virtual int  WriteDB(PGLOBAL g);

 protected:
  // Internal functions
  PCMD MakeCMD(PGLOBAL g);

  // Members
  PCMD     Cmdlist;           // The commands to execute
  char    *Cmdcol;            // The name of the Xsrc command column
  bool     Shw;               // Show warnings
  bool     Havew;             // True when processing warnings
  bool     Isw;               // True for warning lines
  int      Warnings;          // Warnings number
  int      Mxr;               // Maximum errors before closing
  int      Nerr;              // Number of errors so far
  }; // end of class TDBMYEXC

/***********************************************************************/
/*  Class MYXCOL: MySQL exec command table column.                     */
/***********************************************************************/
class MYXCOL : public MYSQLCOL {
  friend class TDBMYEXC;
 public:
  // Constructors
  MYXCOL(PCOLDEF cdp, PTDB tdbp, PCOL cprec, int i,  PCSZ am = "MYSQL");
  MYXCOL(MYSQL_FIELD *fld, PTDB tdbp, int i,  PCSZ am = "MYSQL");
  MYXCOL(MYXCOL *colp, PTDB tdbp);   // Constructor used in copy process

  // Methods
  virtual void ReadColumn(PGLOBAL g);
  virtual void WriteColumn(PGLOBAL g);

 protected:
  // Members
  char    *Buffer;              // To get returned message
  int      Flag;                // Column content desc
  }; // end of class MYXCOL

/***********************************************************************/
/*  This is the class declaration for the MYSQL column catalog table.  */
/***********************************************************************/
class TDBMCL : public TDBCAT {
 public:
  // Constructor
  TDBMCL(PMYDEF tdp);

 protected:
	// Specific routines
	virtual PQRYRES GetResult(PGLOBAL g);

  // Members
  PCSZ Host;                      // Host machine to use            
	PCSZ Db;                        // Database to be used by server  
	PCSZ Tab;                       // External table name            
	PCSZ User;                      // User logon name                
	PCSZ Pwd;                       // Password logon info            
	int  Port;                      // MySQL port number (0 = default)
  }; // end of class TDBMCL