2013-02-07 10:34:27 +01:00
|
|
|
/***********************************************************************/
|
2013-02-20 16:57:38 +01:00
|
|
|
/* MYCONN.H Olivier Bertrand 2007-2013 */
|
2013-02-07 10:34:27 +01:00
|
|
|
/* */
|
|
|
|
/* This is the declaration file for the MySQL connection class and */
|
|
|
|
/* a few utility functions used to communicate with MySQL. */
|
|
|
|
/* */
|
|
|
|
/* DO NOT define DLL_EXPORT in your application so these items are */
|
|
|
|
/* declared are imported from the Myconn DLL. */
|
|
|
|
/***********************************************************************/
|
2015-05-27 16:23:38 +02:00
|
|
|
#if defined(__WIN__)
|
2013-02-07 10:34:27 +01:00
|
|
|
#include <winsock.h>
|
2015-05-27 16:23:38 +02:00
|
|
|
#else // !__WIN__
|
2013-02-07 10:34:27 +01:00
|
|
|
#include <sys/socket.h>
|
2015-05-27 16:23:38 +02:00
|
|
|
#endif // !__WIN__
|
2013-02-07 10:34:27 +01:00
|
|
|
#include <mysql.h>
|
|
|
|
#include <errmsg.h>
|
2013-02-09 01:08:15 +01:00
|
|
|
#include "myutil.h"
|
2013-02-07 10:34:27 +01:00
|
|
|
|
2015-05-27 16:23:38 +02:00
|
|
|
#if defined(__WIN__) && defined(MYCONN_EXPORTS)
|
2013-02-07 10:34:27 +01:00
|
|
|
#if defined(DLL_EXPORT)
|
|
|
|
#define DllItem _declspec(dllexport)
|
|
|
|
#else // !DLL_EXPORT
|
|
|
|
#define DllItem _declspec(dllimport)
|
|
|
|
#endif // !DLL_EXPORT
|
2015-05-27 16:23:38 +02:00
|
|
|
#else // !__WIN__ || !MYCONN_EXPORTS
|
2013-02-07 10:34:27 +01:00
|
|
|
#define DllItem
|
2015-05-27 16:23:38 +02:00
|
|
|
#endif // !__WIN__
|
2013-02-07 10:34:27 +01:00
|
|
|
|
|
|
|
#define MYSQL_ENABLED 0x00000001
|
|
|
|
#define MYSQL_LOGON 0x00000002
|
|
|
|
|
|
|
|
typedef class MYSQLC *PMYC;
|
|
|
|
|
|
|
|
/***********************************************************************/
|
2013-02-09 01:08:15 +01:00
|
|
|
/* Prototypes of info functions. */
|
2013-02-07 10:34:27 +01:00
|
|
|
/***********************************************************************/
|
2014-03-30 22:52:54 +02:00
|
|
|
PQRYRES MyColumns(PGLOBAL g, THD *thd, const char *host, const char *db,
|
2013-02-09 01:08:15 +01:00
|
|
|
const char *user, const char *pwd,
|
|
|
|
const char *table, const char *colpat,
|
2013-05-19 19:25:06 +02:00
|
|
|
int port, bool info);
|
|
|
|
|
|
|
|
PQRYRES SrcColumns(PGLOBAL g, const char *host, const char *db,
|
|
|
|
const char *user, const char *pwd,
|
|
|
|
const char *srcdef, int port);
|
2013-02-07 10:34:27 +01:00
|
|
|
|
2013-05-28 17:22:38 +02:00
|
|
|
uint GetDefaultPort(void);
|
|
|
|
|
2013-02-07 10:34:27 +01:00
|
|
|
/* -------------------------- MYCONN class --------------------------- */
|
|
|
|
|
|
|
|
/***********************************************************************/
|
|
|
|
/* MYSQLC exported/imported class. A MySQL connection. */
|
|
|
|
/***********************************************************************/
|
|
|
|
class DllItem MYSQLC {
|
|
|
|
friend class TDBMYSQL;
|
2013-05-19 19:25:06 +02:00
|
|
|
friend class MYSQLCOL;
|
2013-10-26 17:14:58 +02:00
|
|
|
friend class TDBMYEXC;
|
2013-02-07 10:34:27 +01:00
|
|
|
// Construction
|
|
|
|
public:
|
|
|
|
MYSQLC(void);
|
|
|
|
|
|
|
|
// Implementation
|
|
|
|
int GetRows(void) {return m_Rows;}
|
|
|
|
bool Connected(void);
|
|
|
|
|
|
|
|
// Methods
|
|
|
|
int GetResultSize(PGLOBAL g, PSZ sql);
|
2014-07-17 18:13:51 +02:00
|
|
|
int GetTableSize(PGLOBAL g, PSZ query);
|
2013-02-07 13:37:44 +01:00
|
|
|
int Open(PGLOBAL g, const char *host, const char *db,
|
|
|
|
const char *user= "root", const char *pwd= "*",
|
2015-01-06 10:18:04 +01:00
|
|
|
int pt= 0, const char *csname = NULL);
|
2013-02-07 10:34:27 +01:00
|
|
|
int KillQuery(ulong id);
|
|
|
|
int ExecSQL(PGLOBAL g, const char *query, int *w = NULL);
|
2013-11-06 18:22:09 +01:00
|
|
|
int ExecSQLcmd(PGLOBAL g, const char *query, int *w);
|
|
|
|
#if defined(MYSQL_PREPARED_STATEMENTS)
|
2013-02-07 10:34:27 +01:00
|
|
|
int PrepareSQL(PGLOBAL g, const char *query);
|
|
|
|
int ExecStmt(PGLOBAL g);
|
|
|
|
int BindParams(PGLOBAL g, MYSQL_BIND *bind);
|
2013-11-06 18:22:09 +01:00
|
|
|
#endif // MYSQL_PREPARED_STATEMENTS
|
2013-02-07 10:34:27 +01:00
|
|
|
PQRYRES GetResult(PGLOBAL g, bool pdb = FALSE);
|
|
|
|
int Fetch(PGLOBAL g, int pos);
|
|
|
|
char *GetCharField(int i);
|
|
|
|
int GetFieldLength(int i);
|
2016-04-25 00:13:06 +02:00
|
|
|
int Rewind(PGLOBAL g, PSZ sql);
|
2013-02-07 10:34:27 +01:00
|
|
|
void FreeResult(void);
|
|
|
|
void Close(void);
|
|
|
|
|
|
|
|
protected:
|
2013-02-20 16:57:38 +01:00
|
|
|
MYSQL_FIELD *GetNextField(void);
|
|
|
|
void DataSeek(my_ulonglong row);
|
|
|
|
|
2013-02-07 10:34:27 +01:00
|
|
|
// Members
|
|
|
|
MYSQL *m_DB; // The return from MySQL connection
|
|
|
|
MYSQL_STMT *m_Stmt; // Prepared statement handle
|
|
|
|
MYSQL_RES *m_Res; // Points to MySQL Result
|
|
|
|
MYSQL_ROW m_Row; // Point to current row
|
|
|
|
int m_Rows; // The number of rows of the result
|
|
|
|
int N;
|
|
|
|
int m_Fields; // The number of result fields
|
2013-11-06 18:22:09 +01:00
|
|
|
int m_Afrw; // The number of affected rows
|
2014-04-27 19:18:20 +02:00
|
|
|
bool m_Use; // Use or store result set
|
2015-01-06 10:18:04 +01:00
|
|
|
const char *csname; // Table charset name
|
2013-02-07 10:34:27 +01:00
|
|
|
}; // end of class MYSQLC
|
|
|
|
|