mirror of
https://gitee.com/js-yhsec/energy_storage.git
synced 2026-05-28 03:09:24 +08:00
上传项目代码
This commit is contained in:
111
src/database/DaoEntity.h
Normal file
111
src/database/DaoEntity.h
Normal file
@@ -0,0 +1,111 @@
|
||||
#ifndef _DaoBase_H_
|
||||
#define _DaoBase_H_
|
||||
|
||||
#include "MysqlClient.h"
|
||||
|
||||
class DaoEntity
|
||||
{
|
||||
public:
|
||||
DaoEntity(string tableName);
|
||||
~DaoEntity();
|
||||
|
||||
static MysqlOptions& mysqlOptions();
|
||||
|
||||
static std::shared_ptr<DaoEntity> create(string tableName);
|
||||
|
||||
/**
|
||||
* 执行sql语句
|
||||
* @param: sql 要执行的完整 sql 语句
|
||||
*/
|
||||
static bool execOnce(string sql);
|
||||
|
||||
/**
|
||||
* 执行sql语句,返回结果数据集
|
||||
* @param: sql 要执行的完整 sql 语句
|
||||
* @param: result 返回的结果数据集
|
||||
*/
|
||||
static bool execOnce(string sql, vector<DataFields>& result);
|
||||
|
||||
/**
|
||||
* 设置数据库表名称
|
||||
* @param: tableName 数据表名
|
||||
*/
|
||||
void setTableName(string tableName);
|
||||
|
||||
/**
|
||||
* 设置数据库表名称
|
||||
* @return: bool true: 连接成功;false:未连接/连接失败
|
||||
*/
|
||||
bool isConnected();
|
||||
|
||||
/**
|
||||
* 执行sql语句
|
||||
*/
|
||||
bool exec(string sql);
|
||||
|
||||
/**
|
||||
* 执行sql语句并返回执行(查询)的结果集
|
||||
*/
|
||||
bool exec(string sql, vector<DataFields>& result);
|
||||
|
||||
|
||||
/**
|
||||
* 数据库插入一条数据, 需要先指定数据表名称
|
||||
* @param: fields 写入的数据字段和值
|
||||
*/
|
||||
bool insertFields(DataFields& vecFields);
|
||||
|
||||
/**
|
||||
* 数据库插入多条数据, 需要先指定数据表名称
|
||||
* @param: vecFields 写入的数据字段和值的集合
|
||||
*/
|
||||
bool insertFields(vector<DataFields>& vecFields);
|
||||
|
||||
/**
|
||||
* 数据库插入多条数据,UNIQUE索引或PRIMARY KEY重复时执行更新数据, 需要先指定数据表名称
|
||||
* @param: vecFields 写入的数据字段和值的集合
|
||||
* @param: keys 数据重复时需要更新的字段
|
||||
*/
|
||||
bool duplicateUpdate(DataFields& vecFields, vector<string>& keys);
|
||||
|
||||
/**
|
||||
* 数据库查询,需要先指定数据表名称
|
||||
* @param: sql_c 查询条件,例:"where id='1'"
|
||||
* @param: result 查询的数据结果集
|
||||
*/
|
||||
bool queryFields(string keys, const string& sql_c, vector<DataFields>& result);
|
||||
|
||||
/**
|
||||
* 数据库查询,需要先指定数据表名称
|
||||
* @param: sql_c 查询条件,例:"where id='1'"
|
||||
* @param: pageinfo 分页信息
|
||||
* @param: result 查询的数据结果集
|
||||
*/
|
||||
bool queryFields(string keys, const string& sql_c, PageInfo& pageinfo, vector<DataFields>& result);
|
||||
|
||||
/**
|
||||
* 数据库更新,需要先指定数据表名称
|
||||
* @param: fields 要更新的数据字段和值
|
||||
* @param: sql_c 更新条件
|
||||
*/
|
||||
bool updateFields(DataFields& fields, const string& sql_c);
|
||||
|
||||
/**
|
||||
* 数据库更新,需要先指定数据表名称
|
||||
* @param: fields 要更新的数据值
|
||||
* @param: vecKeys 要更新的字段名称
|
||||
* @param: cond 更新条件
|
||||
*/
|
||||
bool updateFields(DataFields& fields, vector<string> vecKeys, const string& cond);
|
||||
|
||||
protected:
|
||||
static MysqlOptions options_;
|
||||
|
||||
// mysql 数据库操作对象
|
||||
std::shared_ptr<MysqlClient> db_ = nullptr;
|
||||
|
||||
// 数据库表名称
|
||||
string tableName_;
|
||||
};
|
||||
|
||||
#endif // !!! _DaoBase_H_
|
||||
Reference in New Issue
Block a user