Loading...
Searching...
No Matches
database_manager.h
1/*
2 * <one line to give the program's name and a brief idea of what it does.>
3 * Copyright (C) 2023 Jose F Rivas C <email>
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#ifndef NAF_QUERY_DATABASE_MANAGER
20#define NAF_QUERY_DATABASE_MANAGER
21
22
23#include <iostream>
24#include <memory>
25#include <string>
26#include <mutex>
27
28#include "Poco/Exception.h"
29#include "Poco/Data/Session.h"
30#include "Poco/Data/MySQL/Connector.h"
31#include <Poco/Data/MySQL/MySQLException.h>
32#include <Poco/Data/Statement.h>
33
34
35namespace NAF
36{
37 namespace Query
38 {
39 class DatabaseManager;
40 }
41}
42
43using namespace Poco;
44using namespace Poco::Data;
45using namespace Poco::Data::Keywords;
46
48{
49 public:
51 {
52 Credentials() :
53 db_host("")
54 ,db_port("")
55 ,db_name("")
56 ,db_user("")
57 ,db_password("")
58 {
59
60 }
61 Credentials(std::string db_host, std::string db_port, std::string db_name, std::string db_user, std::string db_password) :
62 db_host(db_host)
63 ,db_port(db_port)
64 ,db_name(db_name)
65 ,db_user(db_user)
66 ,db_password(db_password)
67 {
68
69 }
70 void Replace_(Credentials& credentials)
71 {
72 db_host = credentials.db_host;
73 db_port = credentials.db_port;
74 db_name = credentials.db_name;
75 db_user = credentials.db_user;
76 db_password = credentials.db_password;
77 }
78
79 std::string db_host, db_port, db_name, db_user, db_password;
80 };
81
84
85 static void StartMySQL_();
86 static void StopMySQL_();
87 static std::shared_ptr<Data::Session> StartSessionMySQL_(Credentials& credentials);
88
89 private:
90 static bool initialized_;
91
92};
93
94#endif // NAF_QUERY_DATABASE_MANAGER
Definition database_manager.h:48
Definition database_manager.h:51