TrinityCore
Loading...
Searching...
No Matches
PreparedStatement.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 _PREPAREDSTATEMENT_H
19#define _PREPAREDSTATEMENT_H
20
21#include "Define.h"
22#include "Duration.h"
23#include "SQLOperation.h"
24#include <future>
25#include <vector>
26#include <variant>
27
29{
30 std::variant<
31 bool,
32 uint8,
33 uint16,
34 uint32,
35 uint64,
36 int8,
37 int16,
38 int32,
39 int64,
40 float,
41 double,
42 std::string,
43 std::vector<uint8>,
45 std::nullptr_t
47
48 template<typename T>
49 static std::string ToString(T value);
50
51 static std::string ToString(bool value);
52 static std::string ToString(uint8 value);
53 static std::string ToString(int8 value);
54 static std::string ToString(std::string const& value);
55 static std::string ToString(std::vector<uint8> const& value);
56 static std::string ToString(SystemTimePoint value);
57 static std::string ToString(std::nullptr_t);
58};
59
60//- Upper-level class that is used in code
62{
64
65 public:
66 explicit PreparedStatementBase(uint32 index, uint8 capacity);
67 virtual ~PreparedStatementBase();
68
69 void setNull(uint8 index);
70 void setBool(uint8 index, bool value);
71 void setUInt8(uint8 index, uint8 value);
72 void setUInt16(uint8 index, uint16 value);
73 void setUInt32(uint8 index, uint32 value);
74 void setUInt64(uint8 index, uint64 value);
75 void setInt8(uint8 index, int8 value);
76 void setInt16(uint8 index, int16 value);
77 void setInt32(uint8 index, int32 value);
78 void setInt64(uint8 index, int64 value);
79 void setFloat(uint8 index, float value);
80 void setDouble(uint8 index, double value);
81 void setDate(uint8 index, SystemTimePoint value);
82 void setString(uint8 index, std::string const& value);
83 void setStringView(uint8 index, std::string_view value);
84 void setBinary(uint8 index, std::vector<uint8> const& value);
85 template <size_t Size>
86 void setBinary(const uint8 index, std::array<uint8, Size> const& value)
87 {
88 std::vector<uint8> vec(value.begin(), value.end());
89 setBinary(index, vec);
90 }
91
92 uint32 GetIndex() const { return m_index; }
93 std::vector<PreparedStatementData> const& GetParameters() const { return statement_data; }
94
95 protected:
97
98 //- Buffer of parameters, not tied to MySQL in any way yet
99 std::vector<PreparedStatementData> statement_data;
100
103};
104
105template<typename T>
107{
108public:
109 explicit PreparedStatement(uint32 index, uint8 capacity) : PreparedStatementBase(index, capacity)
110 {
111 }
112
113private:
114 PreparedStatement(PreparedStatement const& right) = delete;
116};
117
118//- Lower-level class, enqueuable operation
120{
121 public:
122 PreparedStatementTask(PreparedStatementBase* stmt, bool async = false);
124
125 bool Execute() override;
126 PreparedQueryResultFuture GetFuture() { return m_result->get_future(); }
127
128 protected:
132};
133#endif
std::promise< PreparedQueryResult > PreparedQueryResultPromise
std::future< PreparedQueryResult > PreparedQueryResultFuture
uint8_t uint8
Definition Define.h:135
#define TC_DATABASE_API
Definition Define.h:102
int64_t int64
Definition Define.h:128
int16_t int16
Definition Define.h:130
int8_t int8
Definition Define.h:131
int32_t int32
Definition Define.h:129
uint64_t uint64
Definition Define.h:132
uint16_t uint16
Definition Define.h:134
uint32_t uint32
Definition Define.h:133
std::chrono::system_clock::time_point SystemTimePoint
Definition Duration.h:37
PreparedStatementBase(PreparedStatementBase const &right)=delete
PreparedStatementBase & operator=(PreparedStatementBase const &right)=delete
void setBinary(const uint8 index, std::array< uint8, Size > const &value)
std::vector< PreparedStatementData > statement_data
std::vector< PreparedStatementData > const & GetParameters() const
PreparedQueryResultFuture GetFuture()
PreparedQueryResultPromise * m_result
PreparedStatementBase * m_stmt
PreparedStatement(uint32 index, uint8 capacity)
PreparedStatement(PreparedStatement const &right)=delete
PreparedStatement & operator=(PreparedStatement const &right)=delete
std::variant< bool, uint8, uint16, uint32, uint64, int8, int16, int32, int64, float, double, std::string, std::vector< uint8 >, SystemTimePoint, std::nullptr_t > data
static std::string ToString(T value)