From 1db6623d40fc32a47615d947aec24c89b9528ad5 Mon Sep 17 00:00:00 2001
From: wangky <m1561510467@163.com>
Date: 星期四, 07 十一月 2024 16:41:56 +0800
Subject: [PATCH] 1
---
Server/王琨元/code/MysqlConn.h | 62 +++++++++++++++----------------
1 files changed, 30 insertions(+), 32 deletions(-)
diff --git "a/Server/\347\216\213\347\220\250\345\205\203/code/MysqlConn.h" "b/Server/\347\216\213\347\220\250\345\205\203/code/MysqlConn.h"
index 7e83a2b..fe6d6fc 100644
--- "a/Server/\347\216\213\347\220\250\345\205\203/code/MysqlConn.h"
+++ "b/Server/\347\216\213\347\220\250\345\205\203/code/MysqlConn.h"
@@ -2,56 +2,54 @@
#include <string>
#include <WinSock2.h>
-//#include <mysql.h>
#include "MySQL/include/mysql.h"
#include <string.h>
#include <chrono>
-
+#include <iostream>
+#include <memory>
+#include <queue>
+#include <mutex>
+#include <condition_variable>
+#include <regex>
#pragma comment(lib,"./MySQL/lib/libmysql.lib")
+using namespace std;
class MysqlConn
{
public:
- // 锟斤拷始锟斤拷锟斤拷锟斤拷
+ // 初始化连接
MysqlConn();
- // 锟斤拷锟斤拷锟斤拷锟捷匡拷
- bool connect(std::string ip, std::string userName, std::string passwd, std::string db , int port = 3306);
- // 锟酵凤拷锟斤拷源
- ~MysqlConn( );
- // 锟斤拷锟斤拷锟斤拷锟捷匡拷 ( insert update delete )
- bool update(std::string sql);
- // 锟斤拷询锟斤拷锟捷匡拷
- bool query(std::string sql);
- // 锟矫碉拷锟斤拷锟斤拷锟斤拷
+ // 连接数据库
+ //bool connect();
+ // 释放资源
+ ~MysqlConn();
+ // 更新数据库 ( insert update delete )
+ bool update(string sql);
+ // 查询数据库
+ bool query(string sql, vector<vector<string>>& result);
+ bool query(string sql);
+ // 得到结果集
bool getResult();
- // 锟斤拷取锟斤拷锟斤拷锟斤拷锟斤拷锟街讹拷
- std::string getField(int index);
- // 锟斤拷锟斤拷锟斤拷锟斤拷
+ // 获取结果集的字段
+ string getField(int index);
+ // 事务操作
bool transaction();
- // 锟结交锟斤拷锟斤拷
- bool commit( );
- // 锟斤拷锟斤拷锟截癸拷
+ // 提交事务
+ bool commit();
+ // 事务回滚
bool rollback();
- void refreshActiveTime( ); // 刷锟铰伙拷跃时锟斤拷
- long long getActiveTime(); // 锟斤拷取锟斤拷前锟斤拷跃锟斤拷时锟斤拷锟斤拷锟斤拷
- // 锟斤拷全校锟斤拷锟接匡拷
- bool isSqlSafe(const std::string& sql);
-private:
-
+ void refreshActiveTime(); // 刷新活跃时间
+ long long getActiveTime(); // 获取当前活跃的时间间隔
+ // 安全校验接口
+ bool isSqlSafe(const string& sql);
+ bool isConnected();
+protected:
void freeRes();
-<<<<<<< HEAD
MYSQL* m_mysql;
MYSQL_RES* m_res;
MYSQL_ROW m_row;
chrono::steady_clock::time_point m_activeTime;
-=======
- MYSQL* mysql_ = NULL ;
- MYSQL_RES* res_ = NULL;
- MYSQL_ROW row_ = nullptr;
- std::chrono::steady_clock::time_point activeTime_;
->>>>>>> eadb2439512aec3f324b6e75f09b525e8da33edb
};
-
--
Gitblit v1.8.0