Core/DBLayer: Prevent using prepared statements on wrong database

This commit is contained in:
Shauren
2019-07-27 01:00:37 +02:00
parent 1dcbceba81
commit e8e89f58fb
102 changed files with 604 additions and 577 deletions

View File

@@ -26,13 +26,13 @@
#include <mysql.h>
#include <sstream>
PreparedStatement::PreparedStatement(uint32 index) :
PreparedStatementBase::PreparedStatementBase(uint32 index) :
m_stmt(NULL),
m_index(index) { }
PreparedStatement::~PreparedStatement() { }
PreparedStatementBase::~PreparedStatementBase() { }
void PreparedStatement::BindParameters()
void PreparedStatementBase::BindParameters()
{
ASSERT(m_stmt);
@@ -92,7 +92,7 @@ void PreparedStatement::BindParameters()
}
//- Bind to buffer
void PreparedStatement::setBool(const uint8 index, const bool value)
void PreparedStatementBase::setBool(const uint8 index, const bool value)
{
if (index >= statement_data.size())
statement_data.resize(index+1);
@@ -101,7 +101,7 @@ void PreparedStatement::setBool(const uint8 index, const bool value)
statement_data[index].type = TYPE_BOOL;
}
void PreparedStatement::setUInt8(const uint8 index, const uint8 value)
void PreparedStatementBase::setUInt8(const uint8 index, const uint8 value)
{
if (index >= statement_data.size())
statement_data.resize(index+1);
@@ -110,7 +110,7 @@ void PreparedStatement::setUInt8(const uint8 index, const uint8 value)
statement_data[index].type = TYPE_UI8;
}
void PreparedStatement::setUInt16(const uint8 index, const uint16 value)
void PreparedStatementBase::setUInt16(const uint8 index, const uint16 value)
{
if (index >= statement_data.size())
statement_data.resize(index+1);
@@ -119,7 +119,7 @@ void PreparedStatement::setUInt16(const uint8 index, const uint16 value)
statement_data[index].type = TYPE_UI16;
}
void PreparedStatement::setUInt32(const uint8 index, const uint32 value)
void PreparedStatementBase::setUInt32(const uint8 index, const uint32 value)
{
if (index >= statement_data.size())
statement_data.resize(index+1);
@@ -128,7 +128,7 @@ void PreparedStatement::setUInt32(const uint8 index, const uint32 value)
statement_data[index].type = TYPE_UI32;
}
void PreparedStatement::setUInt64(const uint8 index, const uint64 value)
void PreparedStatementBase::setUInt64(const uint8 index, const uint64 value)
{
if (index >= statement_data.size())
statement_data.resize(index+1);
@@ -137,7 +137,7 @@ void PreparedStatement::setUInt64(const uint8 index, const uint64 value)
statement_data[index].type = TYPE_UI64;
}
void PreparedStatement::setInt8(const uint8 index, const int8 value)
void PreparedStatementBase::setInt8(const uint8 index, const int8 value)
{
if (index >= statement_data.size())
statement_data.resize(index+1);
@@ -146,7 +146,7 @@ void PreparedStatement::setInt8(const uint8 index, const int8 value)
statement_data[index].type = TYPE_I8;
}
void PreparedStatement::setInt16(const uint8 index, const int16 value)
void PreparedStatementBase::setInt16(const uint8 index, const int16 value)
{
if (index >= statement_data.size())
statement_data.resize(index+1);
@@ -155,7 +155,7 @@ void PreparedStatement::setInt16(const uint8 index, const int16 value)
statement_data[index].type = TYPE_I16;
}
void PreparedStatement::setInt32(const uint8 index, const int32 value)
void PreparedStatementBase::setInt32(const uint8 index, const int32 value)
{
if (index >= statement_data.size())
statement_data.resize(index+1);
@@ -164,7 +164,7 @@ void PreparedStatement::setInt32(const uint8 index, const int32 value)
statement_data[index].type = TYPE_I32;
}
void PreparedStatement::setInt64(const uint8 index, const int64 value)
void PreparedStatementBase::setInt64(const uint8 index, const int64 value)
{
if (index >= statement_data.size())
statement_data.resize(index+1);
@@ -173,7 +173,7 @@ void PreparedStatement::setInt64(const uint8 index, const int64 value)
statement_data[index].type = TYPE_I64;
}
void PreparedStatement::setFloat(const uint8 index, const float value)
void PreparedStatementBase::setFloat(const uint8 index, const float value)
{
if (index >= statement_data.size())
statement_data.resize(index+1);
@@ -182,7 +182,7 @@ void PreparedStatement::setFloat(const uint8 index, const float value)
statement_data[index].type = TYPE_FLOAT;
}
void PreparedStatement::setDouble(const uint8 index, const double value)
void PreparedStatementBase::setDouble(const uint8 index, const double value)
{
if (index >= statement_data.size())
statement_data.resize(index+1);
@@ -191,7 +191,7 @@ void PreparedStatement::setDouble(const uint8 index, const double value)
statement_data[index].type = TYPE_DOUBLE;
}
void PreparedStatement::setString(const uint8 index, const std::string& value)
void PreparedStatementBase::setString(const uint8 index, const std::string& value)
{
if (index >= statement_data.size())
statement_data.resize(index+1);
@@ -201,7 +201,7 @@ void PreparedStatement::setString(const uint8 index, const std::string& value)
statement_data[index].type = TYPE_STRING;
}
void PreparedStatement::setBinary(const uint8 index, const std::vector<uint8>& value)
void PreparedStatementBase::setBinary(const uint8 index, const std::vector<uint8>& value)
{
if (index >= statement_data.size())
statement_data.resize(index + 1);
@@ -210,7 +210,7 @@ void PreparedStatement::setBinary(const uint8 index, const std::vector<uint8>& v
statement_data[index].type = TYPE_BINARY;
}
void PreparedStatement::setNull(const uint8 index)
void PreparedStatementBase::setNull(const uint8 index)
{
if (index >= statement_data.size())
statement_data.resize(index+1);
@@ -472,7 +472,7 @@ std::string MySQLPreparedStatement::getQueryString(std::string const& sqlPattern
}
//- Execution
PreparedStatementTask::PreparedStatementTask(PreparedStatement* stmt, bool async) :
PreparedStatementTask::PreparedStatementTask(PreparedStatementBase* stmt, bool async) :
m_stmt(stmt), m_result(nullptr)
{
m_has_result = async; // If it's async, then there's a result