TrinityCore
Loading...
Searching...
No Matches
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 <future>
24#include <vector>
25
26class MySQLConnection;
27
29{
30 friend class SQLQueryHolderTask;
31 private:
32 std::vector<std::pair<PreparedStatementBase*, PreparedQueryResult>> m_queries;
33 public:
34 SQLQueryHolderBase() = default;
35 virtual ~SQLQueryHolderBase();
36 void SetSize(size_t size);
37 PreparedQueryResult GetPreparedResult(size_t index) const;
38 void SetPreparedResult(size_t index, PreparedResultSet* result);
39
40 protected:
41 bool SetPreparedQueryImpl(size_t index, PreparedStatementBase* stmt);
42};
43
44template<typename T>
46{
47public:
48 bool SetPreparedQuery(size_t index, PreparedStatement<T>* stmt)
49 {
50 return SetPreparedQueryImpl(index, stmt);
51 }
52};
53
55{
56public:
57 static bool Execute(MySQLConnection* conn, SQLQueryHolderBase* holder);
58};
59
61{
62public:
63 SQLQueryHolderCallback(std::shared_ptr<SQLQueryHolderBase>&& holder, std::future<void>&& future)
64 : m_holder(std::move(holder)), m_future(std::move(future)) { }
65
67
69
70 void AfterComplete(std::function<void(SQLQueryHolderBase const&)> callback) &
71 {
72 m_callback = std::move(callback);
73 }
74
75 bool InvokeIfReady();
76
77 std::shared_ptr<SQLQueryHolderBase> m_holder;
78 std::future<void> m_future;
79 std::function<void(SQLQueryHolderBase const&)> m_callback;
80};
81
82inline bool InvokeAsyncCallbackIfReady(SQLQueryHolderCallback& callback) { return callback.InvokeIfReady(); }
83
84#endif
std::shared_ptr< PreparedResultSet > PreparedQueryResult
#define TC_DATABASE_API
Definition Define.h:111
bool InvokeAsyncCallbackIfReady(SQLQueryHolderCallback &callback)
Definition QueryHolder.h:82
SQLQueryHolderBase()=default
std::vector< std::pair< PreparedStatementBase *, PreparedQueryResult > > m_queries
Definition QueryHolder.h:32
bool SetPreparedQueryImpl(size_t index, PreparedStatementBase *stmt)
SQLQueryHolderCallback & operator=(SQLQueryHolderCallback &&)=default
SQLQueryHolderCallback(std::shared_ptr< SQLQueryHolderBase > &&holder, std::future< void > &&future)
Definition QueryHolder.h:63
std::shared_ptr< SQLQueryHolderBase > m_holder
Definition QueryHolder.h:77
void AfterComplete(std::function< void(SQLQueryHolderBase const &)> callback) &
Definition QueryHolder.h:70
SQLQueryHolderCallback(SQLQueryHolderCallback &&)=default
std::function< void(SQLQueryHolderBase const &)> m_callback
Definition QueryHolder.h:79
std::future< void > m_future
Definition QueryHolder.h:78
bool SetPreparedQuery(size_t index, PreparedStatement< T > *stmt)
Definition QueryHolder.h:48
STL namespace.