aboutsummaryrefslogtreecommitdiff
path: root/src/server/database/Database/MySQLConnection.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/server/database/Database/MySQLConnection.cpp')
-rw-r--r--src/server/database/Database/MySQLConnection.cpp42
1 files changed, 25 insertions, 17 deletions
diff --git a/src/server/database/Database/MySQLConnection.cpp b/src/server/database/Database/MySQLConnection.cpp
index 08a508ba897..1cd3d1d3287 100644
--- a/src/server/database/Database/MySQLConnection.cpp
+++ b/src/server/database/Database/MySQLConnection.cpp
@@ -19,16 +19,14 @@
#include "Common.h"
#include "DatabaseWorker.h"
#include "Log.h"
+#include "MySQLHacks.h"
+#include "MySQLPreparedStatement.h"
#include "PreparedStatement.h"
#include "QueryResult.h"
#include "Timer.h"
#include "Transaction.h"
#include "Util.h"
-#include <errmsg.h>
-#ifdef _WIN32 // hack for broken mysql.h not including the correct winsock header for SOCKET definition, fixed in 5.7
-#include <winsock2.h>
-#endif
-#include <mysql.h>
+#include "MySQLWorkaround.h"
#include <mysqld_error.h>
MySQLConnectionInfo::MySQLConnectionInfo(std::string const& infoString)
@@ -130,8 +128,8 @@ uint32 MySQLConnection::Open()
}
#endif
- m_Mysql = mysql_real_connect(mysqlInit, m_connectionInfo.host.c_str(), m_connectionInfo.user.c_str(),
- m_connectionInfo.password.c_str(), m_connectionInfo.database.c_str(), port, unix_socket, 0);
+ m_Mysql = reinterpret_cast<MySQLHandle*>(mysql_real_connect(mysqlInit, m_connectionInfo.host.c_str(), m_connectionInfo.user.c_str(),
+ m_connectionInfo.password.c_str(), m_connectionInfo.database.c_str(), port, unix_socket, 0));
if (m_Mysql)
{
@@ -242,7 +240,7 @@ bool MySQLConnection::Execute(PreparedStatement* stmt)
return true;
}
-bool MySQLConnection::_Query(PreparedStatement* stmt, MYSQL_RES **pResult, uint64* pRowCount, uint32* pFieldCount)
+bool MySQLConnection::_Query(PreparedStatement* stmt, MySQLResult** pResult, uint64* pRowCount, uint32* pFieldCount)
{
if (!m_Mysql)
return false;
@@ -289,7 +287,7 @@ bool MySQLConnection::_Query(PreparedStatement* stmt, MYSQL_RES **pResult, uint6
m_mStmt->ClearParameters();
- *pResult = mysql_stmt_result_metadata(msql_STMT);
+ *pResult = reinterpret_cast<MySQLResult*>(mysql_stmt_result_metadata(msql_STMT));
*pRowCount = mysql_stmt_num_rows(msql_STMT);
*pFieldCount = mysql_stmt_field_count(msql_STMT);
@@ -301,8 +299,8 @@ ResultSet* MySQLConnection::Query(char const* sql)
if (!sql)
return nullptr;
- MYSQL_RES *result = nullptr;
- MYSQL_FIELD *fields = nullptr;
+ MySQLResult* result = NULL;
+ MySQLField* fields = NULL;
uint64 rowCount = 0;
uint32 fieldCount = 0;
@@ -312,7 +310,7 @@ ResultSet* MySQLConnection::Query(char const* sql)
return new ResultSet(result, fields, rowCount, fieldCount);
}
-bool MySQLConnection::_Query(const char *sql, MYSQL_RES **pResult, MYSQL_FIELD **pFields, uint64* pRowCount, uint32* pFieldCount)
+bool MySQLConnection::_Query(const char* sql, MySQLResult** pResult, MySQLField** pFields, uint64* pRowCount, uint32* pFieldCount)
{
if (!m_Mysql)
return false;
@@ -334,7 +332,7 @@ bool MySQLConnection::_Query(const char *sql, MYSQL_RES **pResult, MYSQL_FIELD *
else
TC_LOG_DEBUG("sql.sql", "[%u ms] SQL: %s", getMSTimeDiff(_s, getMSTime()), sql);
- *pResult = mysql_store_result(m_Mysql);
+ *pResult = reinterpret_cast<MySQLResult*>(mysql_store_result(m_Mysql));
*pRowCount = mysql_affected_rows(m_Mysql);
*pFieldCount = mysql_field_count(m_Mysql);
}
@@ -348,7 +346,7 @@ bool MySQLConnection::_Query(const char *sql, MYSQL_RES **pResult, MYSQL_FIELD *
return false;
}
- *pFields = mysql_fetch_fields(*pResult);
+ *pFields = reinterpret_cast<MySQLField*>(mysql_fetch_fields(*pResult));
return true;
}
@@ -419,6 +417,11 @@ int MySQLConnection::ExecuteTransaction(SQLTransaction& transaction)
return 0;
}
+size_t MySQLConnection::EscapeString(char* to, const char* from, size_t length)
+{
+ return mysql_real_escape_string(m_Mysql, to, from, length);
+}
+
void MySQLConnection::Ping()
{
mysql_ping(m_Mysql);
@@ -439,6 +442,11 @@ void MySQLConnection::Unlock()
m_Mutex.unlock();
}
+uint32 MySQLConnection::GetServerVersion() const
+{
+ return mysql_get_server_version(m_Mysql);
+}
+
MySQLPreparedStatement* MySQLConnection::GetPreparedStatement(uint32 index)
{
ASSERT(index < m_stmts.size(), "Tried to access invalid prepared statement index %u (max index " SZFMTD ") on database `%s`, connection type: %s",
@@ -479,13 +487,13 @@ void MySQLConnection::PrepareStatement(uint32 index, std::string const& sql, Con
m_prepareError = true;
}
else
- m_stmts[index] = Trinity::make_unique<MySQLPreparedStatement>(stmt, sql);
+ m_stmts[index] = Trinity::make_unique<MySQLPreparedStatement>(reinterpret_cast<MySQLStmt*>(stmt), sql);
}
}
PreparedResultSet* MySQLConnection::Query(PreparedStatement* stmt)
{
- MYSQL_RES *result = nullptr;
+ MySQLResult* result = NULL;
uint64 rowCount = 0;
uint32 fieldCount = 0;
@@ -511,7 +519,7 @@ bool MySQLConnection::_HandleMySQLErrno(uint32 errNo, uint8 attempts /*= 5*/)
{
TC_LOG_ERROR("sql.sql", "Lost the connection to the MySQL server!");
- mysql_close(GetHandle());
+ mysql_close(m_Mysql);
m_Mysql = nullptr;
}
}