SNode.C
Loading...
Searching...
No Matches
MariaDBCommand.h
Go to the documentation of this file.
1/*
2 * SNode.C - a slim toolkit for network communication
3 * Copyright (C) Volker Christian <me@vchrist.at>
4 * 2020, 2021, 2022, 2023, 2024, 2025
5 * 2021, 2022 Daniel Flockert
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as published
9 * by the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#ifndef DATABASE_MARIADB_MARIADBCOMMAND
22#define DATABASE_MARIADB_MARIADBCOMMAND
23
24namespace database::mariadb {
26} // namespace database::mariadb
27
28#ifndef DOXYGEN_SHOULD_SKIP_THIS
29
30#include "utils/Timeval.h"
31
32#include <functional> // IWYU pragma: export
33#include <mysql.h> // IWYU pragma: export
34#include <string> // IWYU pragma: export
35
36// IWYU pragma: no_include "mysql.h"
37
38using st_mysql = MYSQL;
39
40#endif /* DOXYGEN_SHOULD_SKIP_THIS */
41
42namespace database::mariadb {
43
45 public:
46 MariaDBCommand(const std::string& name, const std::function<void(const std::string&, unsigned int)>& onError);
47 virtual ~MariaDBCommand() = default;
48
49 const std::string& commandName();
50
51 int commandStart(MYSQL* mysql, const utils::Timeval& currentTime);
52
53 void setMariaDBConnection(MariaDBConnection* mariaDBConnection);
54
55 private:
56 virtual int commandStart() = 0;
57
58 public:
59 virtual int commandContinue(int status) = 0;
60 virtual bool commandCompleted() = 0;
61 virtual void commandError(const std::string& errorString, unsigned int errorNumber) = 0;
62 virtual std::string commandInfo();
63
64 private:
65 std::string name;
66
68
69 protected:
70 MYSQL* mysql = nullptr;
71
72 const std::function<void(const std::string&, unsigned int)> onError;
73
74 private:
75 utils::Timeval startTime = 0;
76 };
77
78} // namespace database::mariadb
79
80#endif // DATABASE_MARIADB_MARIADBCOMMAND
virtual int commandContinue(int status)=0
const std::function< void(const std::string &, unsigned int)> onError
int commandStart(MYSQL *mysql, const utils::Timeval &currentTime)
MariaDBCommand(const std::string &name, const std::function< void(const std::string &, unsigned int)> &onError)
void setMariaDBConnection(MariaDBConnection *mariaDBConnection)
virtual void commandError(const std::string &errorString, unsigned int errorNumber)=0
MariaDBConnection * mariaDBConnection
MariaDBAutoCommitCommand(my_bool autoCommit, const std::function< void(void)> &onAutoCommit, const std::function< void(const std::string &, unsigned int)> &onError)
void commandError(const std::string &errorString, unsigned int errorNumber) override