TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
QueryHolder.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
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 <future>
22 
24 {
25  friend class SQLQueryHolderTask;
26  private:
27  typedef std::pair<SQLElementData, SQLResultSetUnion> SQLResultPair;
28  std::vector<SQLResultPair> m_queries;
29  public:
31  virtual ~SQLQueryHolder();
32  bool SetQuery(size_t index, const char* sql);
33  template<typename Format, typename... Args>
34  bool SetPQuery(size_t index, Format&& sql, Args&&... args)
35  {
36  return SetQuery(index, Trinity::StringFormat(std::forward<Format>(sql), std::forward<Args>(args)...).c_str());
37  }
38  bool SetPreparedQuery(size_t index, PreparedStatement* stmt);
39  void SetSize(size_t size);
40  QueryResult GetResult(size_t index);
41  PreparedQueryResult GetPreparedResult(size_t index);
42  void SetResult(size_t index, ResultSet* result);
43  void SetPreparedResult(size_t index, PreparedResultSet* result);
44 };
45 
46 typedef std::future<SQLQueryHolder*> QueryResultHolderFuture;
47 typedef std::promise<SQLQueryHolder*> QueryResultHolderPromise;
48 
50 {
51  private:
54  bool m_executed;
55 
56  public:
58  : m_holder(holder), m_executed(false) { }
59 
61 
62  bool Execute() override;
63  QueryResultHolderFuture GetFuture() { return m_result.get_future(); }
64 };
65 
66 #endif
bool m_executed
Definition: QueryHolder.h:54
#define TC_DATABASE_API
Definition: Define.h:122
std::shared_ptr< PreparedResultSet > PreparedQueryResult
Definition: QueryResult.h:107
QueryResultHolderPromise m_result
Definition: QueryHolder.h:53
std::vector< SQLResultPair > m_queries
Definition: QueryHolder.h:28
Definition: QueryHolder.h:23
std::pair< SQLElementData, SQLResultSetUnion > SQLResultPair
Definition: QueryHolder.h:27
#define false
Definition: CascPort.h:18
virtual bool Execute()=0
Definition: PreparedStatement.h:74
std::future< SQLQueryHolder * > QueryResultHolderFuture
Definition: QueryHolder.h:46
Definition: QueryResult.h:30
SQLQueryHolder()
Definition: QueryHolder.h:30
Definition: QueryHolder.h:49
SQLQueryHolderTask(SQLQueryHolder *holder)
Definition: QueryHolder.h:57
std::shared_ptr< ResultSet > QueryResult
Definition: QueryResult.h:61
std::promise< SQLQueryHolder * > QueryResultHolderPromise
Definition: QueryHolder.h:47
std::string StringFormat(Format &&fmt, Args &&...args)
Default TC string format function.
Definition: StringFormat.h:28
SQLQueryHolder * m_holder
Definition: QueryHolder.h:52
Definition: SQLOperation.h:56
QueryResultHolderFuture GetFuture()
Definition: QueryHolder.h:63
Definition: QueryResult.h:63
bool SetPQuery(size_t index, Format &&sql, Args &&...args)
Definition: QueryHolder.h:34