mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-23 18:36:31 +01:00
*Massive cleanup (\n\n -> \n, *\n -> \n, cleanup for(...) to for (...), and some other cleanups by hand)
*Fix a possible crash in Spell::DoAllEffectOnTarget --HG-- branch : trunk
This commit is contained in:
@@ -17,20 +17,16 @@
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "SqlOperations.h"
|
||||
#include "SqlDelayThread.h"
|
||||
#include "DatabaseEnv.h"
|
||||
#include "DatabaseImpl.h"
|
||||
|
||||
/// ---- ASYNC STATEMENTS / TRANSACTIONS ----
|
||||
|
||||
void SqlStatement::Execute(Database *db)
|
||||
{
|
||||
/// just do it
|
||||
db->DirectExecute(m_sql);
|
||||
}
|
||||
|
||||
void SqlTransaction::Execute(Database *db)
|
||||
{
|
||||
if(m_queue.empty())
|
||||
@@ -40,7 +36,6 @@ void SqlTransaction::Execute(Database *db)
|
||||
{
|
||||
char const *sql = m_queue.front();
|
||||
m_queue.pop();
|
||||
|
||||
if(!db->DirectExecute(sql))
|
||||
{
|
||||
free((void*)const_cast<char*>(sql));
|
||||
@@ -52,14 +47,11 @@ void SqlTransaction::Execute(Database *db)
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
free((void*)const_cast<char*>(sql));
|
||||
}
|
||||
db->DirectExecute("COMMIT");
|
||||
}
|
||||
|
||||
/// ---- ASYNC QUERIES ----
|
||||
|
||||
void SqlQuery::Execute(Database *db)
|
||||
{
|
||||
if(!m_callback || !m_queue)
|
||||
@@ -69,7 +61,6 @@ void SqlQuery::Execute(Database *db)
|
||||
/// add the callback to the sql result queue of the thread it originated from
|
||||
m_queue->add(m_callback);
|
||||
}
|
||||
|
||||
void SqlResultQueue::Update()
|
||||
{
|
||||
/// execute the callbacks waiting in the synchronization queue
|
||||
@@ -80,19 +71,16 @@ void SqlResultQueue::Update()
|
||||
delete callback;
|
||||
}
|
||||
}
|
||||
|
||||
bool SqlQueryHolder::Execute(Trinity::IQueryCallback * callback, SqlDelayThread *thread, SqlResultQueue *queue)
|
||||
{
|
||||
if(!callback || !thread || !queue)
|
||||
return false;
|
||||
|
||||
/// delay the execution of the queries, sync them with the delay thread
|
||||
/// which will in turn resync on execution (via the queue) and call back
|
||||
SqlQueryHolderEx *holderEx = new SqlQueryHolderEx(this, callback, queue);
|
||||
thread->Delay(holderEx);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SqlQueryHolder::SetQuery(size_t index, const char *sql)
|
||||
{
|
||||
if(m_queries.size() <= index)
|
||||
@@ -100,19 +88,16 @@ bool SqlQueryHolder::SetQuery(size_t index, const char *sql)
|
||||
sLog.outError("Query index (%u) out of range (size: %u) for query: %s",index,(uint32)m_queries.size(),sql);
|
||||
return false;
|
||||
}
|
||||
|
||||
if(m_queries[index].first != NULL)
|
||||
{
|
||||
sLog.outError("Attempt assign query to holder index (%u) where other query stored (Old: [%s] New: [%s])",
|
||||
index,m_queries[index].first,sql);
|
||||
return false;
|
||||
}
|
||||
|
||||
/// not executed yet, just stored (it's not called a holder for nothing)
|
||||
m_queries[index] = SqlResultPair(strdup(sql), NULL);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SqlQueryHolder::SetPQuery(size_t index, const char *format, ...)
|
||||
{
|
||||
if(!format)
|
||||
@@ -120,22 +105,18 @@ bool SqlQueryHolder::SetPQuery(size_t index, const char *format, ...)
|
||||
sLog.outError("Query (index: %u) is empty.",index);
|
||||
return false;
|
||||
}
|
||||
|
||||
va_list ap;
|
||||
char szQuery [MAX_QUERY_LEN];
|
||||
va_start(ap, format);
|
||||
int res = vsnprintf( szQuery, MAX_QUERY_LEN, format, ap );
|
||||
va_end(ap);
|
||||
|
||||
if(res==-1)
|
||||
{
|
||||
sLog.outError("SQL Query truncated (and not execute) for format: %s",format);
|
||||
return false;
|
||||
}
|
||||
|
||||
return SetQuery(index,szQuery);
|
||||
}
|
||||
|
||||
QueryResult* SqlQueryHolder::GetResult(size_t index)
|
||||
{
|
||||
if(index < m_queries.size())
|
||||
@@ -152,14 +133,12 @@ QueryResult* SqlQueryHolder::GetResult(size_t index)
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void SqlQueryHolder::SetResult(size_t index, QueryResult *result)
|
||||
{
|
||||
/// store the result in the holder
|
||||
if(index < m_queries.size())
|
||||
m_queries[index].second = result;
|
||||
}
|
||||
|
||||
SqlQueryHolder::~SqlQueryHolder()
|
||||
{
|
||||
for(size_t i = 0; i < m_queries.size(); i++)
|
||||
@@ -174,28 +153,23 @@ SqlQueryHolder::~SqlQueryHolder()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SqlQueryHolder::SetSize(size_t size)
|
||||
{
|
||||
/// to optimize push_back, reserve the number of queries about to be executed
|
||||
m_queries.resize(size);
|
||||
}
|
||||
|
||||
void SqlQueryHolderEx::Execute(Database *db)
|
||||
{
|
||||
if(!m_holder || !m_callback || !m_queue)
|
||||
return;
|
||||
|
||||
/// we can do this, we are friends
|
||||
std::vector<SqlQueryHolder::SqlResultPair> &queries = m_holder->m_queries;
|
||||
|
||||
for(size_t i = 0; i < queries.size(); i++)
|
||||
{
|
||||
/// execute all queries in the holder and pass the results
|
||||
char const *sql = queries[i].first;
|
||||
if(sql) m_holder->SetResult(i, db->Query(sql));
|
||||
}
|
||||
|
||||
/// sync with the caller thread
|
||||
m_queue->add(m_callback);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user