72 lines
1.6 KiB
C++
72 lines
1.6 KiB
C++
|
|
|
|
|
|
/**
|
|
* @brief 数据数据库接口类
|
|
*
|
|
*/
|
|
#ifndef _DB_API_H_
|
|
#define _DB_API_H_
|
|
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#define MAX_DATALEN 256
|
|
#define MAX_ROW_NUM 100
|
|
|
|
typedef struct data_s{
|
|
uint32_t index; //存储序号
|
|
uint16_t pn; //测量量点号
|
|
uint32_t id; //数据id
|
|
time_t stime; //数据更新时间
|
|
time_t dtime; //数据时标
|
|
uint32_t crc; //数据校验
|
|
std::string source; //数据源
|
|
std::string data; //数据内容
|
|
}data_t;
|
|
|
|
typedef struct result_s{
|
|
int status; //返回结果 0 -- 正常 其他--错误码
|
|
int rowNum; //返回数据条数
|
|
}result_t;
|
|
|
|
typedef struct db_result_s {
|
|
result_t result; //返回结果
|
|
data_t row[MAX_ROW_NUM]; //返回的数据
|
|
}db_result_t;
|
|
|
|
|
|
|
|
class db_api{
|
|
|
|
public:
|
|
db_api(){};
|
|
db_api(const char *path){};
|
|
~db_api(){};
|
|
|
|
virtual void close(void)=0;
|
|
virtual void vaccum(void)=0;
|
|
virtual bool begin_transation() = 0;
|
|
virtual bool exec(std::string sql, db_result_t* results)=0;
|
|
virtual void end_transation() = 0;
|
|
virtual bool batch_exec(std::vector<std::string> &sql_list,std::vector<db_result_t> &result)=0;
|
|
};
|
|
|
|
typedef struct db_info_s{
|
|
db_api *db;
|
|
std::string tablename;
|
|
}db_info_t;
|
|
|
|
/**
|
|
* @brief 通过操作句柄,afn, id, 找到对应的数据库句柄和表明
|
|
* @param phandle -- 操作句柄
|
|
* @param afn -- 南网afn
|
|
* @param id -- 南网数据id
|
|
* @param db_info -- 数据库信息指针
|
|
* @return false -- 未找到数据库信息, true -- 找到数据库信息指针
|
|
*/
|
|
bool find_db_from_afn_id(void* phandle, uint8_t afn, uint32_t id, db_info_t *db_info);
|
|
|
|
|
|
#endif
|