SNode.C
Loading...
Searching...
No Matches
MariaDBClientASyncAPI.cpp
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#include "database/mariadb/MariaDBClientASyncAPI.h"
22
23#include "database/mariadb/MariaDBCommandSequence.h"
24#include "database/mariadb/commands/async/MariaDBAutoCommitCommand.h"
25#include "database/mariadb/commands/async/MariaDBCommitCommand.h"
26#include "database/mariadb/commands/async/MariaDBExecCommand.h"
27#include "database/mariadb/commands/async/MariaDBFetchRowCommand.h"
28#include "database/mariadb/commands/async/MariaDBFreeResultCommand.h"
29#include "database/mariadb/commands/async/MariaDBQueryCommand.h"
30#include "database/mariadb/commands/async/MariaDBRollbackCommand.h"
31#include "database/mariadb/commands/sync/MariaDBUseResultCommand.h"
32
33#ifndef DOXYGEN_SHOULD_SKIP_THIS
34
35#include <mysql.h>
36
37#endif /* DOXYGEN_SHOULD_SKIP_THIS */
38
39namespace database::mariadb {
40
43
45 const std::function<void(const MYSQL_ROW)>& onQuery,
46 const std::function<void(const std::string&, unsigned int)>& onError) {
47 return execute_async(new database::mariadb::commands::async::MariaDBQueryCommand(
48 sql,
49 []() {
50 },
51 onError))
52 .execute_async(new database::mariadb::commands::sync::MariaDBUseResultCommand(
53 [&lastResult = this->lastResult](MYSQL_RES* result) {
54 lastResult = result;
55 },
56 onError))
57 .execute_async(new database::mariadb::commands::async::MariaDBFetchRowCommand(lastResult, onQuery, onError))
58 .execute_async(new database::mariadb::commands::async::MariaDBFreeResultCommand(
59 lastResult,
60 [this]() {
61 lastResult = nullptr;
62 },
63 onError));
64 }
65
67 const std::function<void(void)>& onExec,
68 const std::function<void(const std::string&, unsigned int)>& onError) {
69 return execute_async(new database::mariadb::commands::async::MariaDBExecCommand(sql, onExec, onError));
70 }
71
72 MariaDBCommandSequence& MariaDBClientASyncAPI::startTransactions(const std::function<void()>& onAutoCommit,
73 const std::function<void(const std::string&, unsigned int)>& onError) {
74 return execute_async(new database::mariadb::commands::async::MariaDBAutoCommitCommand(0, onAutoCommit, onError));
75 }
76
77 MariaDBCommandSequence& MariaDBClientASyncAPI::endTransactions(const std::function<void()>& onAutoCommit,
78 const std::function<void(const std::string&, unsigned int)>& onError) {
79 return execute_async(new database::mariadb::commands::async::MariaDBAutoCommitCommand(1, onAutoCommit, onError));
80 }
81
82 MariaDBCommandSequence& MariaDBClientASyncAPI::commit(const std::function<void()>& onCommit,
83 const std::function<void(const std::string&, unsigned int)>& onError) {
84 return execute_async(new database::mariadb::commands::async::MariaDBCommitCommand(onCommit, onError));
85 }
86
87 MariaDBCommandSequence& MariaDBClientASyncAPI::rollback(const std::function<void()>& onRollback,
88 const std::function<void(const std::string&, unsigned int)>& onError) {
89 return execute_async(new database::mariadb::commands::async::MariaDBRollbackCommand(onRollback, onError));
90 }
91
92} // namespace database::mariadb
MariaDBCommandSequence & commit(const std::function< void(void)> &onCommit, const std::function< void(const std::string &, unsigned int)> &onError)
MariaDBCommandSequence & startTransactions(const std::function< void(void)> &onAutoCommit, const std::function< void(const std::string &, unsigned int)> &onError)
MariaDBCommandSequence & rollback(const std::function< void(void)> &onRollback, const std::function< void(const std::string &, unsigned int)> &onError)
MariaDBCommandSequence & exec(const std::string &sql, const std::function< void(void)> &onExec, const std::function< void(const std::string &, unsigned int)> &onError)
MariaDBCommandSequence & endTransactions(const std::function< void(void)> &onAutoCommit, const std::function< void(const std::string &, unsigned int)> &onError)
MariaDBCommandSequence & query(const std::string &sql, const std::function< void(const MYSQL_ROW)> &onQuery, const std::function< void(const std::string &, unsigned int)> &onError)