#include "MySQLPreparedStatement.h"
◆ MySQLPreparedStatement() [1/2]
MySQLPreparedStatement::MySQLPreparedStatement |
( |
MySQLStmt * |
stmt, |
|
|
std::string_view |
queryString |
|
) |
| |
Initialize variable parameters
"If set to 1, causes mysql_stmt_store_result() to update the metadata MYSQL_FIELD->max_length value."
38 :
43{
49
52 mysql_stmt_attr_set(stmt, STMT_ATTR_UPDATE_MAX_LENGTH, &bool_tmp);
53}
std::remove_pointer_t< decltype(std::declval< MYSQL_BIND >().is_null)> MySQLBool
Definition MySQLHacks.h:32
MySQLBind * m_bind
Definition MySQLPreparedStatement.h:66
PreparedStatementBase * m_stmt
Definition MySQLPreparedStatement.h:57
MySQLStmt * m_Mstmt
Definition MySQLPreparedStatement.h:63
uint32 m_paramCount
Definition MySQLPreparedStatement.h:64
std::string m_queryString
Definition MySQLPreparedStatement.h:67
std::vector< bool > m_paramsSet
Definition MySQLPreparedStatement.h:65
Definition MySQLHacks.h:27
References m_bind, m_paramCount, and m_paramsSet.
◆ ~MySQLPreparedStatement()
MySQLPreparedStatement::~MySQLPreparedStatement |
( |
| ) |
|
◆ MySQLPreparedStatement() [2/2]
◆ AssertValidIndex()
void MySQLPreparedStatement::AssertValidIndex |
( |
const uint8 |
index | ) |
|
|
protected |
111{
113
115 LOG_ERROR(
"sql.sql",
"[ERROR] Prepared Statement (id: {}) trying to bind value on already bound index ({}).",
m_stmt->
GetIndex(), index);
116}
#define ASSERT
Definition Errors.h:68
#define LOG_ERROR(filterType__,...)
Definition Log.h:157
static bool ParamenterIndexAssertFail(uint32 stmtIndex, uint8 index, uint32 paramCount)
Definition MySQLPreparedStatement.cpp:101
uint32 GetIndex() const
Definition PreparedStatement.h:123
References ASSERT, PreparedStatementBase::GetIndex(), LOG_ERROR, m_paramCount, m_paramsSet, m_stmt, and ParamenterIndexAssertFail().
Referenced by SetParameter(), SetParameter(), SetParameter(), and SetParameter().
◆ BindParameters()
69{
71
74 {
75 std::visit([&](auto&& param)
76 {
78 }, data.data);
79
80 ++pos;
81 }
82
83#ifdef _DEBUG
85 LOG_WARN(
"sql.sql",
"[WARNING]: BindParameters() for statement {} did not bind all allocated parameters", stmt->
GetIndex());
86#endif
87}
std::uint8_t uint8
Definition Define.h:109
#define LOG_WARN(filterType__,...)
Definition Log.h:161
void SetParameter(const uint8 index, bool value)
Definition MySQLPreparedStatement.cpp:136
Definition PreparedStatement.h:42
References PreparedStatementBase::GetIndex(), PreparedStatementBase::GetParameters(), LOG_WARN, m_paramCount, m_stmt, and SetParameter().
Referenced by MySQLConnection::_Query(), and MySQLConnection::Execute().
◆ ClearParameters()
void MySQLPreparedStatement::ClearParameters |
( |
| ) |
|
|
protected |
◆ GetBind()
MySQLBind * MySQLPreparedStatement::GetBind |
( |
| ) |
|
|
inlineprotected |
◆ GetParameterCount()
uint32 MySQLPreparedStatement::GetParameterCount |
( |
| ) |
const |
|
inline |
◆ getQueryString()
std::string MySQLPreparedStatement::getQueryString |
( |
| ) |
const |
|
protected |
◆ GetSTMT()
MySQLStmt * MySQLPreparedStatement::GetSTMT |
( |
| ) |
|
|
inlineprotected |
◆ operator=()
◆ SetParameter() [1/5]
void MySQLPreparedStatement::SetParameter |
( |
const uint8 |
index, |
|
|
bool |
value |
|
) |
| |
|
protected |
◆ SetParameter() [2/5]
void MySQLPreparedStatement::SetParameter |
( |
const uint8 |
index, |
|
|
std::nullptr_t |
|
|
) |
| |
|
protected |
142{
145 MYSQL_BIND* param = &
m_bind[index];
146 param->buffer_type = MYSQL_TYPE_NULL;
147 delete[] static_cast<char*>(param->buffer);
148 param->buffer = nullptr;
149 param->buffer_length = 0;
150 param->is_null_value = 1;
151 delete param->length;
152 param->length = nullptr;
153}
void AssertValidIndex(const uint8 index)
Definition MySQLPreparedStatement.cpp:110
References AssertValidIndex(), m_bind, and m_paramsSet.
◆ SetParameter() [3/5]
void MySQLPreparedStatement::SetParameter |
( |
const uint8 |
index, |
|
|
std::string const & |
value |
|
) |
| |
|
protected |
156{
159 MYSQL_BIND* param = &
m_bind[index];
161 param->buffer_type = MYSQL_TYPE_VAR_STRING;
162 delete[] static_cast<char*>(param->buffer);
163 param->buffer = new char[len];
164 param->buffer_length = len;
165 param->is_null_value = 0;
166 delete param->length;
167 param->length = new unsigned long(len);
168
169 memcpy(param->buffer, value.c_str(), len);
170}
References AssertValidIndex(), m_bind, and m_paramsSet.
◆ SetParameter() [4/5]
void MySQLPreparedStatement::SetParameter |
( |
const uint8 |
index, |
|
|
std::vector< uint8 > const & |
value |
|
) |
| |
|
protected |
173{
176 MYSQL_BIND* param = &
m_bind[index];
178 param->buffer_type = MYSQL_TYPE_BLOB;
179 delete[] static_cast<char*>(param->buffer);
180 param->buffer = new char[len];
181 param->buffer_length = len;
182 param->is_null_value = 0;
183 delete param->length;
184 param->length = new unsigned long(len);
185
186 memcpy(param->buffer, value.data(), len);
187}
References AssertValidIndex(), m_bind, and m_paramsSet.
◆ SetParameter() [5/5]
template<typename T >
void MySQLPreparedStatement::SetParameter |
( |
const uint8 |
index, |
|
|
T |
value |
|
) |
| |
|
protected |
120{
123 MYSQL_BIND* param = &
m_bind[index];
126 delete[] static_cast<char*>(param->buffer);
127 param->buffer = new char[len];
128 param->buffer_length = 0;
129 param->is_null_value = 0;
130 param->length = nullptr;
131 param->is_unsigned = std::is_unsigned_v<T>;
132
133 memcpy(param->buffer, &value, len);
134}
Definition MySQLPreparedStatement.cpp:25
References AssertValidIndex(), m_bind, and m_paramsSet.
◆ MySQLConnection
◆ PreparedStatementBase
◆ m_bind
◆ m_Mstmt
◆ m_paramCount
uint32 MySQLPreparedStatement::m_paramCount |
|
private |
◆ m_paramsSet
std::vector<bool> MySQLPreparedStatement::m_paramsSet |
|
private |
◆ m_queryString
std::string MySQLPreparedStatement::m_queryString {} |
|
private |
◆ m_stmt
The documentation for this class was generated from the following files: