TrinityCore
QueryHolder.h
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef _QUERYHOLDER_H
19#define _QUERYHOLDER_H
20
21#include "Define.h"
22#include "DatabaseEnvFwd.h"
23#include <vector>
24
25class MySQLConnection;
26
28{
29 friend class SQLQueryHolderTask;
30 private:
31 std::vector<std::pair<PreparedStatementBase*, PreparedQueryResult>> m_queries;
32 public:
33 SQLQueryHolderBase() = default;
34 virtual ~SQLQueryHolderBase();
35 void SetSize(size_t size);
36 PreparedQueryResult GetPreparedResult(size_t index) const;
37 void SetPreparedResult(size_t index, PreparedResultSet* result);
38
39 protected:
40 bool SetPreparedQueryImpl(size_t index, PreparedStatementBase* stmt);
41};
42
43template<typename T>
45{
46public:
47 bool SetPreparedQuery(size_t index, PreparedStatement<T>* stmt)
48 {
49 return SetPreparedQueryImpl(index, stmt);
50 }
51};
52
54{
55public:
56 static bool Execute(MySQLConnection* conn, SQLQueryHolderBase* holder);
57};
58
60{
61public:
62 SQLQueryHolderCallback(std::shared_ptr<SQLQueryHolderBase>&& holder, QueryResultHolderFuture&& future)
63 : m_holder(std::move(holder)), m_future(std::move(future)) { }
64
66
68
69 void AfterComplete(std::function<void(SQLQueryHolderBase const&)> callback) &
70 {
71 m_callback = std::move(callback);
72 }
73
74 bool InvokeIfReady();
75
76 std::shared_ptr<SQLQueryHolderBase> m_holder;
78 std::function<void(SQLQueryHolderBase const&)> m_callback;
79};
80
81#endif
std::shared_ptr< PreparedResultSet > PreparedQueryResult
std::future< void > QueryResultHolderFuture
#define TC_DATABASE_API
Definition: Define.h:111
SQLQueryHolderBase()=default
std::vector< std::pair< PreparedStatementBase *, PreparedQueryResult > > m_queries
Definition: QueryHolder.h:31
bool SetPreparedQueryImpl(size_t index, PreparedStatementBase *stmt)
Definition: QueryHolder.cpp:25
SQLQueryHolderCallback & operator=(SQLQueryHolderCallback &&)=default
std::shared_ptr< SQLQueryHolderBase > m_holder
Definition: QueryHolder.h:76
void AfterComplete(std::function< void(SQLQueryHolderBase const &)> callback) &
Definition: QueryHolder.h:69
QueryResultHolderFuture m_future
Definition: QueryHolder.h:77
SQLQueryHolderCallback(SQLQueryHolderCallback &&)=default
std::function< void(SQLQueryHolderBase const &)> m_callback
Definition: QueryHolder.h:78
SQLQueryHolderCallback(std::shared_ptr< SQLQueryHolderBase > &&holder, QueryResultHolderFuture &&future)
Definition: QueryHolder.h:62
bool SetPreparedQuery(size_t index, PreparedStatement< T > *stmt)
Definition: QueryHolder.h:47
constexpr std::size_t size()
Definition: UpdateField.h:796
STL namespace.