2013-02-11 00:31:03 +01:00
|
|
|
// TDBMYSQL.H Olivier Bertrand 2007-2013
|
2013-02-07 10:34:27 +01:00
|
|
|
#include "myconn.h" // MySQL connection declares
|
|
|
|
|
|
|
|
typedef class MYSQLDEF *PMYDEF;
|
|
|
|
typedef class TDBMYSQL *PTDBMY;
|
|
|
|
typedef class MYSQLCOL *PMYCOL;
|
2013-10-26 17:14:58 +02:00
|
|
|
typedef class TDBMYEXC *PTDBMYX;
|
|
|
|
typedef class MYXCOL *PMYXCOL;
|
|
|
|
typedef class MYSQLC *PMYC;
|
2013-02-07 10:34:27 +01:00
|
|
|
|
|
|
|
/* ------------------------- MYSQL classes --------------------------- */
|
|
|
|
|
|
|
|
/***********************************************************************/
|
|
|
|
/* MYSQL: table type that are MySQL tables. */
|
|
|
|
/* Using embedded MySQL library (or optionally calling a MySQL server)*/
|
|
|
|
/***********************************************************************/
|
|
|
|
|
|
|
|
/***********************************************************************/
|
|
|
|
/* MYSQL table. */
|
|
|
|
/***********************************************************************/
|
|
|
|
class MYSQLDEF : public TABDEF {/* Logical table description */
|
|
|
|
friend class TDBMYSQL;
|
2013-02-11 00:31:03 +01:00
|
|
|
friend class TDBMCL;
|
2013-02-22 17:26:08 +01:00
|
|
|
friend class ha_connect;
|
2013-02-07 10:34:27 +01:00
|
|
|
public:
|
|
|
|
// Constructor
|
|
|
|
MYSQLDEF(void);
|
|
|
|
|
|
|
|
|
|
|
|
// Implementation
|
|
|
|
virtual const char *GetType(void) {return "MYSQL";}
|
|
|
|
inline PSZ GetHostname(void) {return Hostname;};
|
|
|
|
inline PSZ GetDatabase(void) {return Database;};
|
|
|
|
inline PSZ GetTabname(void) {return Tabname;}
|
2013-05-19 19:25:06 +02:00
|
|
|
inline PSZ GetSrcdef(void) {return Srcdef;}
|
2013-02-07 10:34:27 +01:00
|
|
|
inline PSZ GetUsername(void) {return Username;};
|
|
|
|
inline PSZ GetPassword(void) {return Password;};
|
|
|
|
inline int GetPortnumber(void) {return Portnumber;}
|
|
|
|
|
|
|
|
// Methods
|
|
|
|
virtual bool DefineAM(PGLOBAL g, LPCSTR am, int poff);
|
|
|
|
virtual PTDB GetTable(PGLOBAL g, MODE m);
|
2013-10-27 10:37:12 +01:00
|
|
|
bool ParseURL(PGLOBAL g, char *url, bool b = true);
|
2013-06-16 19:07:27 +02:00
|
|
|
bool GetServerInfo(PGLOBAL g, const char *server_name);
|
2013-02-07 10:34:27 +01:00
|
|
|
|
|
|
|
protected:
|
|
|
|
// Members
|
|
|
|
PSZ Hostname; /* Host machine to use */
|
|
|
|
PSZ Database; /* Database to be used by server */
|
|
|
|
PSZ Tabname; /* External table name */
|
2013-05-19 19:25:06 +02:00
|
|
|
PSZ Srcdef; /* The source table SQL definition */
|
2013-02-07 10:34:27 +01:00
|
|
|
PSZ Username; /* User logon name */
|
|
|
|
PSZ Password; /* Password logon info */
|
2013-08-09 18:02:47 +02:00
|
|
|
PSZ Server; /* PServerID */
|
2013-02-22 17:26:08 +01:00
|
|
|
int Portnumber; /* MySQL port number (0 = default) */
|
2013-05-19 19:25:06 +02:00
|
|
|
bool Isview; /* TRUE if this table is a MySQL view */
|
2013-02-22 17:26:08 +01:00
|
|
|
bool Bind; /* Use prepared statement on insert */
|
|
|
|
bool Delayed; /* Delayed insert */
|
2013-10-26 17:14:58 +02:00
|
|
|
bool Xsrc; /* Execution type */
|
2013-02-07 10:34:27 +01:00
|
|
|
}; // end of MYSQLDEF
|
|
|
|
|
|
|
|
/***********************************************************************/
|
|
|
|
/* This is the class declaration for the MYSQL table. */
|
|
|
|
/***********************************************************************/
|
|
|
|
class TDBMYSQL : public TDBASE {
|
|
|
|
friend class MYSQLCOL;
|
|
|
|
public:
|
|
|
|
// Constructor
|
|
|
|
TDBMYSQL(PMYDEF tdp);
|
|
|
|
TDBMYSQL(PGLOBAL g, PTDBMY tdbp);
|
|
|
|
|
|
|
|
// Implementation
|
|
|
|
virtual AMT GetAmType(void) {return TYPE_AM_MYSQL;}
|
|
|
|
virtual PTDB Duplicate(PGLOBAL g) {return (PTDB)new(g) TDBMYSQL(g, this);}
|
|
|
|
|
|
|
|
// Methods
|
|
|
|
virtual PTDB CopyOne(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);
|
2013-05-19 19:25:06 +02:00
|
|
|
virtual bool IsView(void) {return Isview;}
|
2013-08-09 18:02:47 +02:00
|
|
|
virtual PSZ GetServer(void) {return Server;}
|
2013-04-12 18:30:15 +02:00
|
|
|
void SetDatabase(LPCSTR db) {Database = (char*)db;}
|
2013-02-07 10:34:27 +01:00
|
|
|
|
|
|
|
// 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);
|
|
|
|
virtual int DeleteDB(PGLOBAL g, int irc);
|
|
|
|
virtual void CloseDB(PGLOBAL g);
|
|
|
|
|
2013-05-19 19:25:06 +02:00
|
|
|
// Specific routines
|
|
|
|
bool SetColumnRanks(PGLOBAL g);
|
|
|
|
PCOL MakeFieldColumn(PGLOBAL g, char *name);
|
2013-05-22 13:35:21 +02:00
|
|
|
PSZ FindFieldColumn(char *name);
|
2013-05-19 19:25:06 +02:00
|
|
|
|
2013-02-07 10:34:27 +01:00
|
|
|
protected:
|
|
|
|
// Internal functions
|
|
|
|
bool MakeSelect(PGLOBAL g);
|
|
|
|
bool MakeInsert(PGLOBAL g);
|
|
|
|
//bool MakeUpdate(PGLOBAL g);
|
|
|
|
//bool MakeDelete(PGLOBAL g);
|
|
|
|
int BindColumns(PGLOBAL g);
|
|
|
|
|
|
|
|
// Members
|
|
|
|
MYSQLC Myc; // MySQL connection class
|
2013-02-20 16:57:38 +01:00
|
|
|
MYSQL_BIND *Bind; // To the MySQL bind structure array
|
2013-02-07 10:34:27 +01:00
|
|
|
char *Host; // Host machine to use
|
|
|
|
char *User; // User logon info
|
|
|
|
char *Pwd; // Password logon info
|
|
|
|
char *Database; // Database to be used by server
|
|
|
|
char *Tabname; // External table name
|
2013-05-19 19:25:06 +02:00
|
|
|
char *Srcdef; // The source table SQL definition
|
2013-08-09 18:02:47 +02:00
|
|
|
char *Server; // The server ID
|
2013-02-07 10:34:27 +01:00
|
|
|
char *Query; // Points to SQL query
|
2013-05-19 19:25:06 +02:00
|
|
|
char *Qbuf; // Used for not prepared insert
|
2013-02-07 10:34:27 +01:00
|
|
|
bool Fetched; // True when fetch was done
|
2013-05-19 19:25:06 +02:00
|
|
|
bool Isview; // True if this table is a MySQL view
|
2013-02-07 10:34:27 +01:00
|
|
|
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)
|
2013-02-11 00:31:03 +01:00
|
|
|
int Nparm; // The number of statement parameters
|
2013-02-07 10:34:27 +01:00
|
|
|
}; // 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, PSZ am = "MYSQL");
|
2013-05-19 19:25:06 +02:00
|
|
|
MYSQLCOL(MYSQL_FIELD *fld, PTDB tdbp, int i, PSZ am = "MYSQL");
|
2013-02-07 10:34:27 +01:00
|
|
|
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);
|
2013-05-19 19:25:06 +02:00
|
|
|
bool FindRank(PGLOBAL g);
|
2013-02-07 10:34:27 +01:00
|
|
|
|
|
|
|
protected:
|
|
|
|
// Default constructor not to be used
|
|
|
|
MYSQLCOL(void) {}
|
|
|
|
|
|
|
|
// Members
|
|
|
|
MYSQL_BIND *Bind; // This column bind structure pointer
|
2013-02-11 00:31:03 +01:00
|
|
|
PVAL To_Val; // To value used for Update/Insert
|
2013-02-07 10:34:27 +01:00
|
|
|
unsigned long Slen; // Bind string lengh
|
|
|
|
int Rank; // Rank (position) number in the query
|
|
|
|
}; // end of class MYSQLCOL
|
|
|
|
|
2013-10-26 17:14:58 +02:00
|
|
|
/***********************************************************************/
|
|
|
|
/* This is the class declaration for the exec command MYSQL table. */
|
|
|
|
/***********************************************************************/
|
|
|
|
class TDBMYEXC : public TDBMYSQL {
|
|
|
|
friend class MYXCOL;
|
|
|
|
public:
|
|
|
|
// Constructor
|
|
|
|
TDBMYEXC(PMYDEF tdp) : TDBMYSQL(tdp) {Cmdcol = NULL;}
|
|
|
|
TDBMYEXC(PGLOBAL g, PTDBMYX tdbp) : TDBMYSQL(g, tdbp)
|
|
|
|
{Cmdcol = tdbp->Cmdcol;}
|
|
|
|
|
|
|
|
// Implementation
|
|
|
|
//virtual AMT GetAmType(void) {return TYPE_AM_MYSQL;}
|
|
|
|
virtual PTDB Duplicate(PGLOBAL g) {return (PTDB)new(g) TDBMYEXC(g, this);}
|
|
|
|
|
|
|
|
// Methods
|
|
|
|
virtual PTDB CopyOne(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 PSZ GetServer(void) {return Server;}
|
|
|
|
// void SetDatabase(LPCSTR db) {Database = (char*)db;}
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
//virtual int DeleteDB(PGLOBAL g, int irc);
|
|
|
|
//virtual void CloseDB(PGLOBAL g);
|
|
|
|
|
|
|
|
// Specific routines
|
|
|
|
// bool SetColumnRanks(PGLOBAL g);
|
|
|
|
// PCOL MakeFieldColumn(PGLOBAL g, char *name);
|
|
|
|
// PSZ FindFieldColumn(char *name);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
// Internal functions
|
|
|
|
char *MakeCMD(PGLOBAL g);
|
|
|
|
//bool MakeSelect(PGLOBAL g);
|
|
|
|
//bool MakeInsert(PGLOBAL g);
|
|
|
|
//int BindColumns(PGLOBAL g);
|
|
|
|
|
|
|
|
// Members
|
|
|
|
char *Cmdcol; // The name of the Xsrc command column
|
|
|
|
}; // 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, PSZ am = "MYSQL");
|
|
|
|
MYXCOL(MYSQL_FIELD *fld, PTDB tdbp, int i, PSZ am = "MYSQL");
|
|
|
|
MYXCOL(MYXCOL *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:
|
|
|
|
// Default constructor not to be used
|
|
|
|
MYXCOL(void) {}
|
|
|
|
|
|
|
|
// Members
|
|
|
|
char *Buffer; // To get returned message
|
|
|
|
int Flag; // Column content desc
|
|
|
|
}; // end of class MYXCOL
|
|
|
|
|
2013-02-11 00:31:03 +01:00
|
|
|
/***********************************************************************/
|
|
|
|
/* This is the class declaration for the MYSQL column catalog table. */
|
|
|
|
/***********************************************************************/
|
|
|
|
class TDBMCL : public TDBCAT {
|
|
|
|
public:
|
|
|
|
// Constructor
|
|
|
|
TDBMCL(PMYDEF tdp);
|
2013-02-07 13:37:44 +01:00
|
|
|
|
2013-02-11 00:31:03 +01:00
|
|
|
protected:
|
|
|
|
// Specific routines
|
|
|
|
virtual PQRYRES GetResult(PGLOBAL g);
|
|
|
|
|
|
|
|
// Members
|
|
|
|
PSZ Host; // Host machine to use
|
|
|
|
PSZ Db; // Database to be used by server
|
|
|
|
PSZ Tab; // External table name
|
|
|
|
PSZ User; // User logon name
|
|
|
|
PSZ Pwd; // Password logon info
|
|
|
|
int Port; // MySQL port number (0 = default)
|
|
|
|
}; // end of class TDBMCL
|