-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdataboard.cpp
More file actions
90 lines (75 loc) · 2.73 KB
/
databoard.cpp
File metadata and controls
90 lines (75 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
//
// Created by ws01 on 2021/7/23.
//
#include "databoard.h"
#include "mysql/operatormysql.h"
#include "sqlite/operatorsqlite.h"
#include <exception>
DataBoard::DataBoard(SQLType type, const std::shared_ptr<SQLBase> &sqlPtr) {
sqlType_ = type;
sqlPtr_ = sqlPtr;
}
DataBoard::DataBoard(const std::string &ip, int port, const std::string &user, const std::string &password,
const std::string &dbName) {
sqlType_ = SQLType::MySQL;
try {
sqlPtr_ = std::make_shared<OperatorMySQL>(ip, port, user, password, dbName);
} catch (const std::exception &ep){
throw ep;
}
}
DataBoard::DataBoard(const std::string &db_path) {
sqlType_ = SQLType::SQLite;
try {
sqlPtr_ = std::make_shared<OperatorSQLite>(db_path);
}catch (const std::exception &ep){
throw ep;
}
}
DataBoard::~DataBoard() {
if(sqlPtr_.use_count() != 0){
sqlPtr_->close();
}
}
bool DataBoard::initData(const std::list<std::shared_ptr<TableBase>> &tableList) {
return sqlPtr_->initSQL(tableList);
}
bool
DataBoard::getAllData(std::list<std::shared_ptr<TableBase>> &dataList,
const std::shared_ptr<TableBase> &tableName, std::string *error) {
return sqlPtr_->getCustomizeData(dataList, tableName, "", error);
}
bool DataBoard::getData(std::list<std::shared_ptr<TableBase>> &dataList, const std::shared_ptr<TableBase> &table,
const std::list<std::string> &condition, std::string *error) {
return sqlPtr_->getData(dataList, table, condition, error);
}
bool DataBoard::getPrimaryKeyData(std::shared_ptr<TableBase> &data, std::string *error) {
if(data->primaryKey.empty()){
if(error != nullptr){
*error = "primaryKey nullptr";
}
return false;
}
std::list<std::shared_ptr<TableBase>> dataList;
std::list<std::string> condition;
condition.emplace_back(data->primaryKey);
auto result = sqlPtr_->getData(dataList, data, condition, error);
if(result){
if(!dataList.empty()){
data.swap(dataList.front());
}
}
return result;
}
bool
DataBoard::getCustomizeData(std::list<std::shared_ptr<TableBase>> &dataList, const std::shared_ptr<TableBase> &table,
const std::string &condition, std::string *error) {
return sqlPtr_->getCustomizeData(dataList, table, condition, error);
}
bool DataBoard::insertData(const std::shared_ptr<TableBase> &data, std::string *err, bool equal) {
return sqlPtr_->insertData(data, err, equal);
}
bool DataBoard::modifyData(const std::shared_ptr<TableBase> &table, const std::list<std::string> &condition,
std::string *error) {
return sqlPtr_->modifyData(table, condition, error);
}