mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-22 18:15:31 +01:00
Core/DBLayer:
- Rewrite Field class to be able to store both binary prepared statement data and data from adhoc query resultsets
- Buffer the data of prepared statements using ResultSet and Field classes and let go of mysql c api structures after PreparedResultSet constructor. Fixes a race condition and thus a possible crash/data corruption (issue pointed out to Derex, basic suggestion by raczman)
- Conform PreparedResultSet and ResultSet to the same design standards, and using Field class as data buffer class for both
* NOTE: This means the fetching methods are uniform again, using ¨Field* fields = result->Fetch();¨ and access to elements trough fields[x].
* NOTE: for access to the correct row in prepared statements, ¨Field* fields = result->Fetch();¨ must ALWAYS be called inside the do { }while(result->NextRow()) loop.
* NOTE: This means that Field::GetString() returns std::string object and Field::GetCString() returns const char* pointer.
Still experimental and all that jazz, not recommended for production servers until feedback is given.
--HG--
branch : trunk
This commit is contained in:
@@ -89,13 +89,6 @@ QueryResult SQLQueryHolder::GetResult(size_t index)
|
||||
// Don't call to this function if the index is of an ad-hoc statement
|
||||
if (index < m_queries.size())
|
||||
{
|
||||
/// the query strings are freed on the first GetResult or in the destructor
|
||||
if (SQLElementData* data = &m_queries[index].first)
|
||||
{
|
||||
free((void*)(const_cast<char*>(data->element.query)));
|
||||
data->element.query = NULL;
|
||||
}
|
||||
|
||||
ResultSet* result = m_queries[index].second.qresult;
|
||||
if (!result || !result->GetRowCount())
|
||||
return QueryResult(NULL);
|
||||
@@ -112,18 +105,10 @@ PreparedQueryResult SQLQueryHolder::GetPreparedResult(size_t index)
|
||||
// Don't call to this function if the index is of a prepared statement
|
||||
if (index < m_queries.size())
|
||||
{
|
||||
/// the query strings are freed on the first GetResult or in the destructor
|
||||
if (SQLElementData* data = &m_queries[index].first)
|
||||
{
|
||||
delete data->element.stmt;
|
||||
data->element.stmt = NULL;
|
||||
}
|
||||
|
||||
PreparedResultSet* result = m_queries[index].second.presult;
|
||||
if (!result || !result->GetRowCount())
|
||||
return PreparedQueryResult(NULL);
|
||||
|
||||
result->NextRow();
|
||||
return PreparedQueryResult(result);
|
||||
}
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user