#pragma once
|
#include<iostream>
|
#include <memory>
|
#include <string>
|
#include <mysql.h>
|
#include <chrono> // ʱÖÓ
|
#include <fstream>
|
|
#pragma comment(lib, "./lib/libmysql.lib") // ¼ÓÔØÊý¾Ý¿â¿âÎļþ
|
using namespace std;
|
using namespace chrono;
|
typedef long long ll;
|
|
class MysqlConn
|
{
|
private:
|
// ¾ø¶ÔʱÖÓ
|
steady_clock::time_point m_alivetime;
|
// Á¬½Ó
|
MYSQL* m_conn;
|
// ²éѯµÄ½á¹û¼¯
|
MYSQL_RES* m_result;
|
// µ¥¼Ç¼½á¹û¼¯
|
MYSQL_ROW m_mysqlRow;
|
|
// ½á¹û¼¯ÊÍ·Å
|
void freeRes();
|
// µ¼³öijһÕűíÖеÄÊý¾Ý
|
void backupCurrentTable(const string path, const string tableName);
|
public:
|
// ³õʼ»¯Êý¾Ý¿â
|
MysqlConn();
|
// Êý¾Ý¿âÁ¬½ÓÊÍ·Å
|
~MysqlConn();
|
// Á¬½ÓÊý¾Ý¿â, ÐèÌṩÓû§ ÃÜÂë Êý¾Ý¿âÃû³Æ ip ¶Ë¿Ú
|
bool connect(const string user, const string passwd, \
|
const string dbName, string ip, \
|
const unsigned short port = 3306U);
|
// ¸üÐÂÊý¾Ý¿â:Ôöɾ¸Ä²Ù×÷
|
bool update(const string sql) const;
|
// ²éѯÊý¾Ý¿â
|
bool query(const string sql);
|
// ±éÀú²éѯ½á¹û¼¯
|
bool getRes();
|
// »ñÈ¡½á¹û¼¯ÖеÄ×Ö¶ÎÖµ
|
string getValue(const int fieldIndex) const;
|
// Çл»Êý¾Ý¿â
|
bool selectDB(const string dbName) const;
|
// ½¨¿â
|
//bool createDB(const string dbName) const;
|
// ±¸·Ýij¸ö¿â
|
void backupCurrentDB(const string path);
|
// ÊÂÎñ²Ù×÷
|
bool transaction() const;
|
// Ìá½»ÊÂÎñ
|
bool commit() const;
|
// ÊÂÎñ»Ø¹ö
|
bool rollback() const;
|
// Ë¢ÐÂÆðʼµÄ¿ÕÏÐʱ¼äµã
|
void refreashAliveTime();
|
// ¼ÆËã´æ»î×Üʱ³¤
|
ll getAliveTime();
|
};
|