Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Loading...
Searching...
No Matches
PreparedStatement.h
Go to the documentation of this file.
1/*
2* This file is part of Project SkyFire https://www.projectskyfire.org.
3* See LICENSE.md file for Copyright information
4*/
5
6#ifndef _PREPAREDSTATEMENT_H
7#define _PREPAREDSTATEMENT_H
8
9#include "SQLOperation.h"
10#include "Threading/Future.h"
11
12#ifdef __APPLE__
13#undef TYPE_BOOL
14#endif
15
16//- Union for data buffer (upper-level bind -> queue -> lower-level bind)
31
32//- This enum helps us differ data held in above union
50
57
58//- Forward declare
60
61//- Upper-level class that is used in code
63{
66 friend class MySQLConnection;
67
68public:
69 explicit PreparedStatement(uint32 index);
71
72 void setBool(const uint8 index, const bool value);
73 void setUInt8(const uint8 index, const uint8 value);
74 void setUInt16(const uint8 index, const uint16 value);
75 void setUInt32(const uint8 index, const uint32 value);
76 void setUInt64(const uint8 index, const uint64 value);
77 void setInt8(const uint8 index, const int8 value);
78 void setInt16(const uint8 index, const int16 value);
79 void setInt32(const uint8 index, const int32 value);
80 void setInt64(const uint8 index, const int64 value);
81 void setFloat(const uint8 index, const float value);
82 void setDouble(const uint8 index, const double value);
83 void setString(const uint8 index, const std::string& value);
84 void setBinary(const uint8 index, const std::vector<uint8>& 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 void setNull(const uint8 index);
92
93protected:
94 void BindParameters();
95
98 std::vector<PreparedStatementData> statement_data; //- Buffer of parameters, not tied to MySQL in any way yet
99private:
100 PreparedStatement(PreparedStatement const& right) = delete;
102};
103
104//- Class of which the instances are unique per MySQLConnection
105//- access to these class objects is only done when a prepared statement task
106//- is executed.
108{
109 friend class MySQLConnection;
110 friend class PreparedStatement;
111
112public:
113 MySQLPreparedStatement(MYSQL_STMT* stmt);
115
116 void setBool(const uint8 index, const bool value);
117 void setUInt8(const uint8 index, const uint8 value);
118 void setUInt16(const uint8 index, const uint16 value);
119 void setUInt32(const uint8 index, const uint32 value);
120 void setUInt64(const uint8 index, const uint64 value);
121 void setInt8(const uint8 index, const int8 value);
122 void setInt16(const uint8 index, const int16 value);
123 void setInt32(const uint8 index, const int32 value);
124 void setInt64(const uint8 index, const int64 value);
125 void setFloat(const uint8 index, const float value);
126 void setDouble(const uint8 index, const double value);
127 void setBinary(const uint8 index, const std::vector<uint8>& value, bool isString);
128 void setNull(const uint8 index);
129
130protected:
131 MYSQL_STMT* GetSTMT() { return m_Mstmt; }
132 MYSQL_BIND* GetBind() { return m_bind; }
134 void ClearParameters();
135 bool CheckValidIndex(uint8 index);
136 std::string getQueryString(std::string const& sqlPattern) const;
137
138private:
139 void setValue(MYSQL_BIND* param, enum_field_types type, const void* value, uint32 len, bool isUnsigned);
140
141private:
142 MYSQL_STMT* m_Mstmt;
144 std::vector<bool> m_paramsSet;
145 MYSQL_BIND* m_bind;
148};
149
151
152//- Lower-level class, enqueuable operation
167#endif
std::int32_t int32
Definition Define.h:73
std::uint8_t uint8
Definition Define.h:79
std::uint32_t uint32
Definition Define.h:77
std::int8_t int8
Definition Define.h:75
std::uint64_t uint64
Definition Define.h:76
std::int64_t int64
Definition Define.h:72
std::uint16_t uint16
Definition Define.h:78
std::int16_t int16
Definition Define.h:74
Skyfire::Future< PreparedQueryResult > PreparedQueryResultFuture
PreparedStatementValueType
@ TYPE_DOUBLE
@ TYPE_NULL
@ TYPE_FLOAT
@ TYPE_BOOL
@ TYPE_UI32
@ TYPE_I16
@ TYPE_I64
@ TYPE_BINARY
@ TYPE_I32
@ TYPE_I8
@ TYPE_UI8
@ TYPE_STRING
@ TYPE_UI16
@ TYPE_UI64
void setUInt32(const uint8 index, const uint32 value)
void setBool(const uint8 index, const bool value)
void setNull(const uint8 index)
MySQLPreparedStatement(MYSQL_STMT *stmt)
void setInt64(const uint8 index, const int64 value)
void setDouble(const uint8 index, const double value)
void setInt8(const uint8 index, const int8 value)
PreparedStatement * m_stmt
MySQLPreparedStatement & operator=(MySQLPreparedStatement const &right)=delete
std::string getQueryString(std::string const &sqlPattern) const
void setUInt64(const uint8 index, const uint64 value)
void setUInt16(const uint8 index, const uint16 value)
bool CheckValidIndex(uint8 index)
void setInt32(const uint8 index, const int32 value)
void setUInt8(const uint8 index, const uint8 value)
void setValue(MYSQL_BIND *param, enum_field_types type, const void *value, uint32 len, bool isUnsigned)
void setFloat(const uint8 index, const float value)
void setInt16(const uint8 index, const int16 value)
MySQLPreparedStatement(MySQLPreparedStatement const &right)=delete
void setBinary(const uint8 index, const std::vector< uint8 > &value, bool isString)
std::vector< bool > m_paramsSet
void setBool(const uint8 index, const bool value)
friend class MySQLConnection
void setFloat(const uint8 index, const float value)
void setString(const uint8 index, const std::string &value)
void setInt64(const uint8 index, const int64 value)
MySQLPreparedStatement * m_stmt
void setUInt16(const uint8 index, const uint16 value)
PreparedStatement(uint32 index)
PreparedStatement(PreparedStatement const &right)=delete
friend class PreparedStatementTask
PreparedStatement & operator=(PreparedStatement const &right)=delete
void setUInt64(const uint8 index, const uint64 value)
void setBinary(const uint8 index, const std::vector< uint8 > &value)
void setNull(const uint8 index)
void setBinary(const uint8 index, std::array< uint8, Size > const &value)
void setInt8(const uint8 index, const int8 value)
void setUInt32(const uint8 index, const uint32 value)
std::vector< PreparedStatementData > statement_data
void setInt16(const uint8 index, const int16 value)
friend class MySQLPreparedStatement
void setDouble(const uint8 index, const double value)
void setUInt8(const uint8 index, const uint8 value)
void setInt32(const uint8 index, const int32 value)
PreparedStatementTask(PreparedStatement *stmt)
PreparedQueryResultFuture m_result
PreparedStatement * m_stmt
std::vector< uint8 > binary
PreparedStatementDataUnion data
PreparedStatementValueType type
Definition adtfile.h:28