USB_Config_Vendor/CC_SDK/Include/Environment/mysql/CCMySql.h

85 lines
2.1 KiB
C
Raw Permalink Normal View History

2026-02-03 14:36:30 +08:00
#ifndef CC_MySql_H
#define CC_MySql_H
#ifndef _WINSOCKAPI_
#define _WINSOCKAPI_
#endif
#include "mysql.h"
#include "string"
#include "vector"
#include "nlohmann/json.hpp"
/*
* create DATABASE xxx;
* DROP DATABASE xxx;
*
*
* //创建表
* CREATE TABLE xxx (
column1 datatype,
column2 datatype,
...
);
//删除表
DROP TABLE xxx; or DROP TABLE [IF EXISTS] xxx;
//插入表
INSERT INTO xxx (column1, column2, column3, ...) VALUES (value1, value2, value3, ...);
//查询表
SELECT column1, column2, ... FROM xxx; or SELECT * FROM xxx; or SELECT * FROM xxx WHERE ID='xx';
* */
namespace CTL{
struct RetData{
std::vector<nlohmann::json> Data;
/// 结果集中行数
int Row = 0;
/// 结果集中列数
int Col = 0;
/// 操作是否成功标志
bool Flag = false;
std::string Error;
};
class MySql{
MYSQL* mysql = nullptr; //mysql连接
public:
MySql();
~MySql();
/**
* MySQL数据库
* @param host
* @param user
* @param passwd
* @param db
* @param port
* @return truefalse
*/
bool Connect(const std::string& host, const std::string& user, const std::string& passwd, const std::string& db, int port) const;
/**
* SQL查询
* @param sql SQL查询语句
* @return
*/
RetData Query(const std::string& sql) const;
/**
* SQL语句
* @param sql SQL语句
* @return truefalse
*/
RetData Execute(const std::string& sql) const;
/**
*
*/
void Close() const;
private:
public:
};
}
#endif