TrinityCore
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 "DatabaseEnvFwd.h"
22#include "Define.h"
23#include "Duration.h"
24#include <span>
25#include <string>
26#include <variant>
27#include <vector>
28
29class MySQLConnection;
30
32{
33 std::variant<
34 bool,
35 uint8,
36 uint16,
37 uint32,
38 uint64,
39 int8,
40 int16,
41 int32,
42 int64,
43 float,
44 double,
45 std::string,
46 std::vector<uint8>,
48 std::nullptr_t
50
51 template<typename T>
52 static std::string ToString(T value);
53
54 static std::string ToString(bool value);
55 static std::string ToString(uint8 value);
56 static std::string ToString(int8 value);
57 static std::string ToString(std::string const& value);
58 static std::string ToString(std::vector<uint8> const& value);
59 static std::string ToString(SystemTimePoint value);
60 static std::string ToString(std::nullptr_t);
61};
62
63//- Upper-level class that is used in code
65{
67
68 public:
69 explicit PreparedStatementBase(uint32 index, uint8 capacity);
70 virtual ~PreparedStatementBase();
71
72 void setNull(uint8 index);
73 void setBool(uint8 index, bool value);
74 void setUInt8(uint8 index, uint8 value);
75 void setUInt16(uint8 index, uint16 value);
76 void setUInt32(uint8 index, uint32 value);
77 void setUInt64(uint8 index, uint64 value);
78 void setInt8(uint8 index, int8 value);
79 void setInt16(uint8 index, int16 value);
80 void setInt32(uint8 index, int32 value);
81 void setInt64(uint8 index, int64 value);
82 void setFloat(uint8 index, float value);
83 void setDouble(uint8 index, double value);
84 void setDate(uint8 index, SystemTimePoint value);
85 void setString(uint8 index, std::string&& value);
86 void setString(uint8 index, std::string_view value);
87 void setBinary(uint8 index, std::vector<uint8>&& value);
88 void setBinary(uint8 index, std::span<uint8 const> value);
89
90 uint32 GetIndex() const { return m_index; }
91 std::vector<PreparedStatementData> const& GetParameters() const { return statement_data; }
92
93 protected:
95
96 //- Buffer of parameters, not tied to MySQL in any way yet
97 std::vector<PreparedStatementData> statement_data;
98
101};
102
103template<typename T>
105{
106public:
107 explicit PreparedStatement(uint32 index, uint8 capacity) : PreparedStatementBase(index, capacity)
108 {
109 }
110
111private:
112 PreparedStatement(PreparedStatement const& right) = delete;
114};
115
116//- Lower-level class, enqueuable operation
118{
119public:
121 static bool Execute(MySQLConnection* conn, PreparedStatementBase* stmt);
122};
123
124#endif
std::shared_ptr< PreparedResultSet > PreparedQueryResult
uint8_t uint8
Definition: Define.h:144
#define TC_DATABASE_API
Definition: Define.h:111
int64_t int64
Definition: Define.h:137
int16_t int16
Definition: Define.h:139
int8_t int8
Definition: Define.h:140
int32_t int32
Definition: Define.h:138
uint64_t uint64
Definition: Define.h:141
uint16_t uint16
Definition: Define.h:143
uint32_t uint32
Definition: Define.h:142
std::chrono::system_clock::time_point SystemTimePoint
Definition: Duration.h:37
PreparedStatementBase(PreparedStatementBase const &right)=delete
PreparedStatementBase & operator=(PreparedStatementBase const &right)=delete
std::vector< PreparedStatementData > statement_data
std::vector< PreparedStatementData > const & GetParameters() const
PreparedStatement(uint32 index, uint8 capacity)
PreparedStatement(PreparedStatement const &right)=delete
PreparedStatement & operator=(PreparedStatement const &right)=delete
void Execute(Creature *me, EventMap &events, uint32 eventId)
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)