1 /***********************************************************************/ 2 /* MYCONN.H Olivier Bertrand 2007-2013 */ 3 /* */ 4 /* This is the declaration file for the MySQL connection class and */ 5 /* a few utility functions used to communicate with MySQL. */ 6 /* */ 7 /* DO NOT define DLL_EXPORT in your application so these items are */ 8 /* declared are imported from the Myconn DLL. */ 9 /***********************************************************************/ 10 #if defined(_WIN32) 11 #include <winsock.h> 12 #else // !_WIN32 13 #include <sys/socket.h> 14 #endif // !_WIN32 15 #include <mysql.h> 16 #include <errmsg.h> 17 #include "myutil.h" 18 19 #if defined(_WIN32) && defined(MYCONN_EXPORTS) 20 #if defined(DLL_EXPORT) 21 #define DllItem _declspec(dllexport) 22 #else // !DLL_EXPORT 23 #define DllItem _declspec(dllimport) 24 #endif // !DLL_EXPORT 25 #else // !_WIN32 || !MYCONN_EXPORTS 26 #define DllItem 27 #endif // !_WIN32 28 29 #define MYSQL_ENABLED 0x00000001 30 #define MYSQL_LOGON 0x00000002 31 32 typedef class MYSQLC *PMYC; 33 34 /***********************************************************************/ 35 /* Prototypes of info functions. */ 36 /***********************************************************************/ 37 PQRYRES MyColumns(PGLOBAL g, THD *thd, const char *host, const char *db, 38 const char *user, const char *pwd, 39 const char *table, const char *colpat, 40 int port, bool info); 41 42 PQRYRES SrcColumns(PGLOBAL g, const char *host, const char *db, 43 const char *user, const char *pwd, 44 const char *srcdef, int port); 45 46 uint GetDefaultPort(void); 47 48 /* -------------------------- MYCONN class --------------------------- */ 49 50 /***********************************************************************/ 51 /* MYSQLC exported/imported class. A MySQL connection. */ 52 /***********************************************************************/ 53 class DllItem MYSQLC { 54 friend class TDBMYSQL; 55 friend class MYSQLCOL; 56 friend class TDBMYEXC; 57 // Construction 58 public: 59 MYSQLC(void); 60 61 // Implementation GetRows(void)62 int GetRows(void) {return m_Rows;} 63 bool Connected(void); 64 65 // Methods 66 int GetResultSize(PGLOBAL g, PSZ sql); 67 int GetTableSize(PGLOBAL g, PSZ query); 68 int Open(PGLOBAL g, const char *host, const char *db, 69 const char *user= "root", const char *pwd= "*", 70 int pt= 0, const char *csname = NULL); 71 int KillQuery(ulong id); 72 int ExecSQL(PGLOBAL g, const char *query, int *w = NULL); 73 int ExecSQLcmd(PGLOBAL g, const char *query, int *w); 74 #if defined(MYSQL_PREPARED_STATEMENTS) 75 int PrepareSQL(PGLOBAL g, const char *query); 76 int ExecStmt(PGLOBAL g); 77 int BindParams(PGLOBAL g, MYSQL_BIND *bind); 78 #endif // MYSQL_PREPARED_STATEMENTS 79 PQRYRES GetResult(PGLOBAL g, bool pdb = FALSE); 80 int Fetch(PGLOBAL g, int pos); 81 char *GetCharField(int i); 82 int GetFieldLength(int i); 83 int Rewind(PGLOBAL g, PSZ sql); 84 void FreeResult(void); 85 void Close(void); 86 87 protected: 88 MYSQL_FIELD *GetNextField(void); 89 void DataSeek(my_ulonglong row); 90 91 // Members 92 MYSQL *m_DB; // The return from MySQL connection 93 #if defined (MYSQL_PREPARED_STATEMENTS) 94 MYSQL_STMT *m_Stmt; // Prepared statement handle 95 #endif // MYSQL_PREPARED_STATEMENTS 96 MYSQL_RES *m_Res; // Points to MySQL Result 97 MYSQL_ROW m_Row; // Point to current row 98 int m_Rows; // The number of rows of the result 99 int N; 100 int m_Fields; // The number of result fields 101 int m_Afrw; // The number of affected rows 102 bool m_Use; // Use or store result set 103 const char *csname; // Table charset name 104 }; // end of class MYSQLC 105 106