mirror of
https://github.com/EQEmu/Server.git
synced 2026-05-19 13:28:25 +00:00
[Code] Add mysql prepared statement support (#4530)
This adds support for using prepared statements for MySQL queries. It is intended for use in a database quest API but it can be used in source with some caveats: - It uses exceptions for error handling instead of returning a fake result that needs checked. Usage must be wrapped in try/catch. - DBcore has a connection mutex which indicates the connection might be shared with other threads. This mutex is locked for certain stmt operations in an attempt to make it safe to use with multi threaded connections. - Prepared statements should only be used on the main thread since the internal logging is not synchronized. - Unlike the current query API which retrieves all results as strings, results are stored in buffers that represent the db field type. Getter functions are available to retrieve values as desired types.
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
#include "timer.h"
|
||||
|
||||
#include "dbcore.h"
|
||||
#include "mysql_stmt.h"
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
@@ -436,3 +437,8 @@ MySQLRequestResult DBcore::QueryDatabaseMulti(const std::string &query)
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
mysql::PreparedStmt DBcore::Prepare(std::string query)
|
||||
{
|
||||
return mysql::PreparedStmt(*mysql, std::move(query), m_mutex);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user