You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

95 lines
3.5 KiB

  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. #if defined(WIN32) && defined(MYCONN_EXPORTS)
  19. #if defined(DLL_EXPORT)
  20. #define DllItem _declspec(dllexport)
  21. #else // !DLL_EXPORT
  22. #define DllItem _declspec(dllimport)
  23. #endif // !DLL_EXPORT
  24. #else // !WIN32 || !MYCONN_EXPORTS
  25. #define DllItem
  26. #endif // !WIN32
  27. //#define TYPE_AM_MYSQL (AMT)192
  28. #define MYSQL_ENABLED 0x00000001
  29. #define MYSQL_LOGON 0x00000002
  30. typedef class MYSQLC *PMYC;
  31. /***********************************************************************/
  32. /* Prototypes of info functions. */
  33. /***********************************************************************/
  34. PQRYRES MyColumns(PGLOBAL g, const char *host, const char *db,
  35. const char *user, const char *pwd,
  36. const char *table, const char *colpat,
  37. int port, bool key, bool info);
  38. /* -------------------------- MYCONN class --------------------------- */
  39. /***********************************************************************/
  40. /* MYSQLC exported/imported class. A MySQL connection. */
  41. /***********************************************************************/
  42. class DllItem MYSQLC {
  43. friend class TDBMYSQL;
  44. // Construction
  45. public:
  46. MYSQLC(void);
  47. // Implementation
  48. int GetRows(void) {return m_Rows;}
  49. bool Connected(void);
  50. // Methods
  51. // int GetCurPos(void) {return (m_Res) ? N : 0;}
  52. // int GetProgCur(void) {return N;}
  53. int GetResultSize(PGLOBAL g, PSZ sql);
  54. int Open(PGLOBAL g, const char *host, const char *db,
  55. const char *user= "root", const char *pwd= "*",
  56. int pt= 0);
  57. //ulong GetThreadID(void);
  58. //ulong ServerVersion(void);
  59. //const char *ServerInfo(void);
  60. int KillQuery(ulong id);
  61. int ExecSQL(PGLOBAL g, const char *query, int *w = NULL);
  62. int PrepareSQL(PGLOBAL g, const char *query);
  63. int ExecStmt(PGLOBAL g);
  64. int BindParams(PGLOBAL g, MYSQL_BIND *bind);
  65. PQRYRES GetResult(PGLOBAL g, bool pdb = FALSE);
  66. int Fetch(PGLOBAL g, int pos);
  67. char *GetCharField(int i);
  68. int GetFieldLength(int i);
  69. void Rewind(void);
  70. void FreeResult(void);
  71. void Close(void);
  72. //void DiscardResults(void);
  73. protected:
  74. MYSQL_FIELD *GetNextField(void);
  75. void DataSeek(my_ulonglong row);
  76. // Members
  77. MYSQL *m_DB; // The return from MySQL connection
  78. MYSQL_STMT *m_Stmt; // Prepared statement handle
  79. MYSQL_RES *m_Res; // Points to MySQL Result
  80. MYSQL_ROW m_Row; // Point to current row
  81. int m_Rows; // The number of rows of the result
  82. int N;
  83. int m_Fields; // The number of result fields
  84. }; // end of class MYSQLC