-
Notifications
You must be signed in to change notification settings - Fork 1
/
dbhandler.h
101 lines (88 loc) · 2.97 KB
/
dbhandler.h
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
91
92
93
94
95
96
97
98
99
100
101
#ifndef DBHANDLER_H
#define DBHANDLER_H
#include <QSqlDatabase>
/**
* \class DbHandler
*
* \brief SQL Database Handler class
*
* DbHandler sets up the connection with SQL database
* and performs some basics queries. The class requires
* existing SQL database.
* There are advantages and disadvantages to using a serverless db.
* The main advantage is that there is no separate server process to install,
* setup, configure, initialize, manage, and troubleshoot.
* This is one reason why SQLite is a "zero-configuration" database engine.
* etaNet application will be easier to handle.
* The clients are not allowed to talk directly to the database,
* because they should initially authenticated by the management.
* And for security reasons, only the management should have access to db.
*/
class DbHandler
{
public:
/**
* @brief Constructor
*
* Constructor sets up connection with db and opens it
* @param {const QString&} path - absolute path to db file
*/
DbHandler();
/**
* @brief Destructor
*
* Close the db connection
*/
~DbHandler();
/**
* @brief Check if db exists and available
* @return {bool} true - db reachable, false - db not reachable
*/
bool isOpen() const;
/**
* @brief Creates a new monitoring table if it doesn't already exist
* @param {QString} message - message to create the insert query
* @return {bool} true - table created successfully, false - table not created
*/
bool createMonitoringTable(QString message);
/**
* @brief Creates a new controll table if it doesn't already exist
* @param {QString} message - message to create the insert query
* @return {bool} true - table created successfully, false - table not created
*/
bool createControllTable(QString message);
/**
* @brief Add tubel into one of a tabels
* @param {QString} message - message to create the insert query
* @return true - person added successfully, false - person not added
*/
bool insertMonitoringTuble(QString& message);
/**
* @brief Replace tubel into one of a tabels
* @param {QString} message - message to create the replace query
* @return true - person added successfully, false - person not added
*/
bool updateLastMonitoringTuble(QString& message);
/**
* @brief Creation of the Controll Matrix header
* @return true - created successfully
*/
bool initControllMatrix(void);
/**
* @brief Gets Controll Matrix String of one field element.
* @param {QString} field element name
* @return {QString} String of all controll parameters
*/
QString selectControllValues(QString& name);
private:
/**
* @brief database object - represents a connection to a monitoring database.
*/
QSqlDatabase m_db;
/**
* @brief Create a Log-Table
* @return {bool} true - Log-Table creation was sucessful
*/
bool log(void);
};
#endif // DBHANDLER_H