Apply style fix

This commit is contained in:
Antz 2020-01-10 23:13:44 +00:00
parent 5531a0087d
commit 35405dd549
155 changed files with 10968 additions and 3660 deletions

View file

@ -71,7 +71,9 @@ SqlPreparedStatement* SqlConnection::GetStmt(uint32 nIndex)
{
// resize stmt container
if (m_holder.size() <= nIndex)
{ m_holder.resize(nIndex + 1, NULL); }
{
m_holder.resize(nIndex + 1, NULL);
}
SqlPreparedStatement* pStmt = NULL;
@ -102,7 +104,9 @@ SqlPreparedStatement* SqlConnection::GetStmt(uint32 nIndex)
bool SqlConnection::ExecuteStmt(int nIndex, const SqlStmtParameters& id)
{
if (nIndex == -1)
{ return false; }
{
return false;
}
// get prepared statement object
SqlPreparedStatement* pStmt = GetStmt(nIndex);
@ -127,7 +131,9 @@ bool Database::Initialize(const char* infoString, int nConns /*= 1*/)
if (!m_logsDir.empty())
{
if ((m_logsDir.at(m_logsDir.length() - 1) != '/') && (m_logsDir.at(m_logsDir.length() - 1) != '\\'))
{ m_logsDir.append("/"); }
{
m_logsDir.append("/");
}
}
m_pingIntervallms = sConfig.GetIntDefault("MaxPingTime", 30) * (MINUTE * 1000);
@ -136,7 +142,9 @@ bool Database::Initialize(const char* infoString, int nConns /*= 1*/)
// setup connection pool size
if (nConns < MIN_CONNECTION_POOL_SIZE)
{ m_nQueryConnPoolSize = MIN_CONNECTION_POOL_SIZE; }
{
m_nQueryConnPoolSize = MIN_CONNECTION_POOL_SIZE;
}
else if (nConns > MAX_CONNECTION_POOL_SIZE)
{ m_nQueryConnPoolSize = MAX_CONNECTION_POOL_SIZE; }
else
@ -158,7 +166,9 @@ bool Database::Initialize(const char* infoString, int nConns /*= 1*/)
// create and initialize connection for async requests
m_pAsyncConn = CreateConnection();
if (!m_pAsyncConn->Initialize(infoString))
{ return false; }
{
return false;
}
m_pResultQueue = new SqlResultQueue;
@ -222,13 +232,17 @@ void Database::ThreadEnd()
void Database::ProcessResultQueue()
{
if (m_pResultQueue)
{ m_pResultQueue->Update(); }
{
m_pResultQueue->Update();
}
}
void Database::escape_string(std::string& str)
{
if (str.empty())
{ return; }
{
return;
}
char* buf = new char[str.size() * 2 + 1];
// we don't care what connection to use - escape string will be the same
@ -242,7 +256,9 @@ SqlConnection* Database::getQueryConnection()
int nCount = 0;
if (m_nQueryCounter == long(1 << 31))
{ m_nQueryCounter = 0; }
{
m_nQueryCounter = 0;
}
else
{ nCount = ++m_nQueryCounter; }
@ -268,7 +284,9 @@ void Database::Ping()
bool Database::PExecuteLog(const char* format, ...)
{
if (!format)
{ return false; }
{
return false;
}
va_list ap;
char szQuery [MAX_QUERY_LEN];
@ -350,7 +368,9 @@ QueryNamedResult* Database::PQueryNamed(const char* format, ...)
bool Database::Execute(const char* sql)
{
if (!m_pAsyncConn)
{ return false; }
{
return false;
}
SqlTransaction* pTrans = (*m_TransStorage)->get();
if (pTrans)
@ -362,7 +382,9 @@ bool Database::Execute(const char* sql)
{
// if async execution is not available
if (!m_bAllowAsyncTransactions)
{ return DirectExecute(sql); }
{
return DirectExecute(sql);
}
// Simple sql statement
m_threadBody->Delay(new SqlPlainRequest(sql));
@ -374,7 +396,9 @@ bool Database::Execute(const char* sql)
bool Database::PExecute(const char* format, ...)
{
if (!format)
{ return false; }
{
return false;
}
va_list ap;
char szQuery [MAX_QUERY_LEN];
@ -394,7 +418,9 @@ bool Database::PExecute(const char* format, ...)
bool Database::DirectPExecute(const char* format, ...)
{
if (!format)
{ return false; }
{
return false;
}
va_list ap;
char szQuery [MAX_QUERY_LEN];
@ -414,7 +440,9 @@ bool Database::DirectPExecute(const char* format, ...)
bool Database::BeginTransaction()
{
if (!m_pAsyncConn)
{ return false; }
{
return false;
}
// initiate transaction on current thread
// currently we do not support queued transactions
@ -425,15 +453,21 @@ bool Database::BeginTransaction()
bool Database::CommitTransaction()
{
if (!m_pAsyncConn)
{ return false; }
{
return false;
}
// check if we have pending transaction
if (!(*m_TransStorage)->get())
{ return false; }
{
return false;
}
// if async execution is not available
if (!m_bAllowAsyncTransactions)
{ return CommitTransactionDirect(); }
{
return CommitTransactionDirect();
}
// add SqlTransaction to the async queue
m_threadBody->Delay((*m_TransStorage)->detach());
@ -443,11 +477,15 @@ bool Database::CommitTransaction()
bool Database::CommitTransactionDirect()
{
if (!m_pAsyncConn)
{ return false; }
{
return false;
}
// check if we have pending transaction
if (!(*m_TransStorage)->get())
{ return false; }
{
return false;
}
// directly execute SqlTransaction
SqlTransaction* pTrans = (*m_TransStorage)->detach();
@ -460,10 +498,14 @@ bool Database::CommitTransactionDirect()
bool Database::RollbackTransaction()
{
if (!m_pAsyncConn)
{ return false; }
{
return false;
}
if (!(*m_TransStorage)->get())
{ return false; }
{
return false;
}
// remove scheduled transaction
(*m_TransStorage)->reset();
@ -554,7 +596,9 @@ bool Database::CheckDatabaseVersion(DatabaseTypes database)
bool Database::ExecuteStmt(const SqlStatementID& id, SqlStmtParameters* params)
{
if (!m_pAsyncConn)
{ return false; }
{
return false;
}
SqlTransaction* pTrans = (*m_TransStorage)->get();
if (pTrans)
@ -566,7 +610,9 @@ bool Database::ExecuteStmt(const SqlStatementID& id, SqlStmtParameters* params)
{
// if async execution is not available
if (!m_bAllowAsyncTransactions)
{ return DirectExecuteStmt(id, params); }
{
return DirectExecuteStmt(id, params);
}
// Simple sql statement
m_threadBody->Delay(new SqlPreparedRequest(id.ID(), params));
@ -617,13 +663,17 @@ std::string Database::GetStmtString(const int stmtId) const
LOCK_GUARD _guard(m_stmtGuard);
if (stmtId == -1 || stmtId > m_iStmtIndex)
{ return std::string(); }
{
return std::string();
}
PreparedStmtRegistry::const_iterator iter_last = m_stmtRegistry.end();
for (PreparedStmtRegistry::const_iterator iter = m_stmtRegistry.begin(); iter != iter_last; ++iter)
{
if (iter->second == stmtId)
{ return iter->first; }
{
return iter->first;
}
}
return std::string();

View file

@ -296,7 +296,9 @@ class Database
inline bool DirectExecute(const char* sql)
{
if (!m_pAsyncConn)
{ return false; }
{
return false;
}
SqlConnection::Lock guard(m_pAsyncConn);
return guard->Execute(sql);

View file

@ -102,15 +102,25 @@ bool MySQLConnection::Initialize(const char* infoString)
iter = tokens.begin();
if (iter != tokens.end())
{ host = *iter++; }
{
host = *iter++;
}
if (iter != tokens.end())
{ port_or_socket = *iter++; }
{
port_or_socket = *iter++;
}
if (iter != tokens.end())
{ user = *iter++; }
{
user = *iter++;
}
if (iter != tokens.end())
{ password = *iter++; }
{
password = *iter++;
}
if (iter != tokens.end())
{ database = *iter++; }
{
database = *iter++;
}
mysql_options(mysqlInit, MYSQL_SET_CHARSET_NAME, "utf8");
mysql_options(mysqlInit, MYSQL_OPT_RECONNECT, "1");
@ -170,7 +180,9 @@ bool MySQLConnection::Initialize(const char* infoString)
// LEAVE 'AUTOCOMMIT' MODE ALWAYS ENABLED!!!
// W/O IT EVEN 'SELECT' QUERIES WOULD REQUIRE TO BE WRAPPED INTO 'START TRANSACTION'<>'COMMIT' CLAUSES!!!
if (!mysql_autocommit(mMysql, 1))
{ DETAIL_LOG("AUTOCOMMIT SUCCESSFULLY SET TO 1"); }
{
DETAIL_LOG("AUTOCOMMIT SUCCESSFULLY SET TO 1");
}
else
{ DETAIL_LOG("AUTOCOMMIT NOT SET TO 1"); }
/*-------------------------------------*/
@ -186,7 +198,9 @@ bool MySQLConnection::Initialize(const char* infoString)
bool MySQLConnection::_Query(const char* sql, MYSQL_RES** pResult, MYSQL_FIELD** pFields, uint64* pRowCount, uint32* pFieldCount)
{
if (!mMysql)
{ return 0; }
{
return 0;
}
uint32 _s = WorldTimer::getMSTime();
@ -206,7 +220,9 @@ bool MySQLConnection::_Query(const char* sql, MYSQL_RES** pResult, MYSQL_FIELD**
*pFieldCount = mysql_field_count(mMysql);
if (!*pResult)
{ return false; }
{
return false;
}
if (!*pRowCount)
{
@ -226,7 +242,9 @@ QueryResult* MySQLConnection::Query(const char* sql)
uint32 fieldCount = 0;
if (!_Query(sql, &result, &fields, &rowCount, &fieldCount))
{ return NULL; }
{
return NULL;
}
QueryResultMysql* queryResult = new QueryResultMysql(result, fields, rowCount, fieldCount);
@ -242,7 +260,9 @@ QueryNamedResult* MySQLConnection::QueryNamed(const char* sql)
uint32 fieldCount = 0;
if (!_Query(sql, &result, &fields, &rowCount, &fieldCount))
{ return NULL; }
{
return NULL;
}
QueryFieldNames names(fieldCount);
for (uint32 i = 0; i < fieldCount; ++i)
@ -257,7 +277,9 @@ QueryNamedResult* MySQLConnection::QueryNamed(const char* sql)
bool MySQLConnection::Execute(const char* sql)
{
if (!mMysql)
{ return false; }
{
return false;
}
{
uint32 _s = WorldTimer::getMSTime();
@ -311,7 +333,9 @@ bool MySQLConnection::RollbackTransaction()
unsigned long MySQLConnection::escape_string(char* to, const char* from, unsigned long length)
{
if (!mMysql || !to || !from || !length)
{ return 0; }
{
return 0;
}
return(mysql_real_escape_string(mMysql, to, from, length));
}
@ -336,7 +360,9 @@ MySqlPreparedStatement::~MySqlPreparedStatement()
bool MySqlPreparedStatement::prepare()
{
if (isPrepared())
{ return true; }
{
return true;
}
// remove old binds
RemoveBinds();
@ -402,7 +428,9 @@ void MySqlPreparedStatement::bind(const SqlStmtParameters& holder)
// finalize adding params
if (!m_pInputArgs)
{ return; }
{
return;
}
// verify if we bound all needed input parameters
if (m_nParams != holder.boundParams())
@ -450,7 +478,9 @@ void MySqlPreparedStatement::addParam(unsigned int nIndex, const SqlStmtFieldDat
void MySqlPreparedStatement::RemoveBinds()
{
if (!m_stmt)
{ return; }
{
return;
}
delete[] m_pInputArgs;
delete[] m_pResult;
@ -469,7 +499,9 @@ void MySqlPreparedStatement::RemoveBinds()
bool MySqlPreparedStatement::execute()
{
if (!isPrepared())
{ return false; }
{
return false;
}
if (mysql_stmt_execute(m_stmt))
{

View file

@ -72,18 +72,30 @@ bool PostgreSQLConnection::Initialize(const char* infoString)
iter = tokens.begin();
if (iter != tokens.end())
{ host = *iter++; }
{
host = *iter++;
}
if (iter != tokens.end())
{ port_or_socket_dir = *iter++; }
{
port_or_socket_dir = *iter++;
}
if (iter != tokens.end())
{ user = *iter++; }
{
user = *iter++;
}
if (iter != tokens.end())
{ password = *iter++; }
{
password = *iter++;
}
if (iter != tokens.end())
{ database = *iter++; }
{
database = *iter++;
}
if (host == ".")
{ mPGconn = PQsetdbLogin(NULL, port_or_socket_dir == "." ? NULL : port_or_socket_dir.c_str(), NULL, NULL, database.c_str(), user.c_str(), password.c_str()); }
{
mPGconn = PQsetdbLogin(NULL, port_or_socket_dir == "." ? NULL : port_or_socket_dir.c_str(), NULL, NULL, database.c_str(), user.c_str(), password.c_str());
}
else
{ mPGconn = PQsetdbLogin(host.c_str(), port_or_socket_dir.c_str(), NULL, NULL, database.c_str(), user.c_str(), password.c_str()); }
@ -105,13 +117,17 @@ bool PostgreSQLConnection::Initialize(const char* infoString)
bool PostgreSQLConnection::_Query(const char* sql, PGresult** pResult, uint64* pRowCount, uint32* pFieldCount)
{
if (!mPGconn)
{ return false; }
{
return false;
}
uint32 _s = WorldTimer::getMSTime();
// Send the query
*pResult = PQexec(mPGconn, sql);
if (!*pResult)
{ return false; }
{
return false;
}
if (PQresultStatus(*pResult) != PGRES_TUPLES_OK)
{
@ -141,14 +157,18 @@ bool PostgreSQLConnection::_Query(const char* sql, PGresult** pResult, uint64* p
QueryResult* PostgreSQLConnection::Query(const char* sql)
{
if (!mPGconn)
{ return NULL; }
{
return NULL;
}
PGresult* result = NULL;
uint64 rowCount = 0;
uint32 fieldCount = 0;
if (!_Query(sql, &result, &rowCount, &fieldCount))
{ return NULL; }
{
return NULL;
}
QueryResultPostgre* queryResult = new QueryResultPostgre(result, rowCount, fieldCount);
@ -159,14 +179,18 @@ QueryResult* PostgreSQLConnection::Query(const char* sql)
QueryNamedResult* PostgreSQLConnection::QueryNamed(const char* sql)
{
if (!mPGconn)
{ return NULL; }
{
return NULL;
}
PGresult* result = NULL;
uint64 rowCount = 0;
uint32 fieldCount = 0;
if (!_Query(sql, &result, &rowCount, &fieldCount))
{ return NULL; }
{
return NULL;
}
QueryFieldNames names(fieldCount);
for (uint32 i = 0; i < fieldCount; ++i)
@ -181,7 +205,9 @@ QueryNamedResult* PostgreSQLConnection::QueryNamed(const char* sql)
bool PostgreSQLConnection::Execute(const char* sql)
{
if (!mPGconn)
{ return false; }
{
return false;
}
uint32 _s = WorldTimer::getMSTime();
@ -204,7 +230,9 @@ bool PostgreSQLConnection::Execute(const char* sql)
bool PostgreSQLConnection::_TransactionCmd(const char* sql)
{
if (!mPGconn)
{ return false; }
{
return false;
}
PGresult* res = PQexec(mPGconn, sql);
if (PQresultStatus(res) != PGRES_COMMAND_OK)
@ -238,7 +266,9 @@ bool PostgreSQLConnection::RollbackTransaction()
unsigned long PostgreSQLConnection::escape_string(char* to, const char* from, unsigned long length)
{
if (!mPGconn || !to || !from || !length)
{ return 0; }
{
return 0;
}
return PQescapeString(to, from, length);
}

View file

@ -154,7 +154,9 @@ class Field
{
uint64 value = 0;
if (!mValue || sscanf(mValue, UI64FMTD, &value) == -1)
{ return 0; }
{
return 0;
}
return value;
}

View file

@ -176,7 +176,9 @@ class QueryNamedResult
for (size_t idx = 0; idx < mFieldNames.size(); ++idx)
{
if (mFieldNames[idx] == name)
{ return idx; }
{
return idx;
}
}
MANGOS_ASSERT(false && "unknown field name");
return uint32(-1);

View file

@ -47,7 +47,9 @@ bool QueryResultMysql::NextRow()
MYSQL_ROW row;
if (!mResult)
{ return false; }
{
return false;
}
row = mysql_fetch_row(mResult);
if (!row)

View file

@ -45,7 +45,9 @@ QueryResultPostgre::~QueryResultPostgre()
bool QueryResultPostgre::NextRow()
{
if (!mResult)
{ return false; }
{
return false;
}
if (mTableIndex >= mRowCount)
{
@ -58,7 +60,9 @@ bool QueryResultPostgre::NextRow()
{
pPQgetvalue = PQgetvalue(mResult, mTableIndex, j);
if (pPQgetvalue && !(*pPQgetvalue))
{ pPQgetvalue = NULL; }
{
pPQgetvalue = NULL;
}
mCurrentRow[j].SetValue(pPQgetvalue);
}

View file

@ -75,7 +75,9 @@ void SQLStorageBase::prepareToLoad(uint32 maxEntry, uint32 recordCount, uint32 r
void SQLStorageBase::Free()
{
if (!m_data)
{ return; }
{
return;
}
uint32 offset = 0;
for (uint32 x = 0; x < m_dstFieldCount; ++x)
@ -193,7 +195,9 @@ void SQLHashStorage::EraseEntry(uint32 id)
// do not erase from m_records
RecordMap::iterator find = m_indexMap.find(id);
if (find != m_indexMap.end())
{ find->second = NULL; }
{
find->second = NULL;
}
}
SQLHashStorage::SQLHashStorage(const char* fmt, const char* _entry_field, const char* sqlname)

View file

@ -298,7 +298,9 @@ class SQLStorage : public SQLStorageBase
T const* LookupEntry(uint32 id) const
{
if (id >= GetMaxEntry())
{ return NULL; }
{
return NULL;
}
return reinterpret_cast<T const*>(m_Index[id]);
}
@ -390,7 +392,9 @@ class SQLHashStorage : public SQLStorageBase
{
RecordMap::const_iterator find = m_indexMap.find(id);
if (find != m_indexMap.end())
{ return reinterpret_cast<T const*>(find->second); }
{
return reinterpret_cast<T const*>(find->second);
}
return NULL;
}

View file

@ -266,7 +266,9 @@ void SQLStorageLoaderBase<DerivedLoader, StorageClass>::Load(StorageClass& store
if (!result)
{
if (error_at_empty)
{ sLog.outError("%s table is empty!\n", store.GetTableName()); }
{
sLog.outError("%s table is empty!\n", store.GetTableName());
}
else
{ sLog.outString("%s table is empty!\n", store.GetTableName()); }
@ -348,7 +350,9 @@ void SQLStorageLoaderBase<DerivedLoader, StorageClass>::Load(StorageClass& store
// It is required that the input has at least as many columns set as the output requires
if (y >= store.GetSrcFieldCount())
{ assert(false && "SQL storage has too few columns!"); }
{
assert(false && "SQL storage has too few columns!");
}
switch (store.GetSrcFormat(y))
{

View file

@ -50,7 +50,9 @@ SqlTransaction::~SqlTransaction()
bool SqlTransaction::Execute(SqlConnection* conn)
{
if (m_queue.empty())
{ return true; }
{
return true;
}
LOCK_DB_CONN(conn);
@ -91,7 +93,9 @@ bool SqlPreparedRequest::Execute(SqlConnection* conn)
bool SqlQuery::Execute(SqlConnection* conn)
{
if (!m_callback || !m_queue)
{ return false; }
{
return false;
}
LOCK_DB_CONN(conn);
/// execute the query and store the result in the callback
@ -116,7 +120,9 @@ void SqlResultQueue::Update()
bool SqlQueryHolder::Execute(MaNGOS::IQueryCallback* callback, SqlDelayThread* thread, SqlResultQueue* queue)
{
if (!callback || !thread || !queue)
{ return false; }
{
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
@ -189,7 +195,9 @@ void SqlQueryHolder::SetResult(size_t index, QueryResult* result)
{
/// store the result in the holder
if (index < m_queries.size())
{ m_queries[index].second = result; }
{
m_queries[index].second = result;
}
}
SqlQueryHolder::~SqlQueryHolder()
@ -215,7 +223,9 @@ void SqlQueryHolder::SetSize(size_t size)
bool SqlQueryHolderEx::Execute(SqlConnection* conn)
{
if (!m_holder || !m_callback || !m_queue)
{ return false; }
{
return false;
}
LOCK_DB_CONN(conn);
/// we can do this, we are friends

View file

@ -28,7 +28,9 @@ SqlStmtParameters::SqlStmtParameters(uint32 nParams)
{
// reserve memory if needed
if (nParams > 0)
{ m_params.reserve(nParams); }
{
m_params.reserve(nParams);
}
}
void SqlStmtParameters::reset(const SqlStatement& stmt)
@ -36,7 +38,9 @@ void SqlStmtParameters::reset(const SqlStatement& stmt)
m_params.clear();
// reserve memory if needed
if (stmt.arguments() > 0)
{ m_params.reserve(stmt.arguments()); }
{
m_params.reserve(stmt.arguments());
}
}
//////////////////////////////////////////////////////////////////////////
@ -51,7 +55,9 @@ SqlStatement& SqlStatement::operator=(const SqlStatement& index)
m_pParams = NULL;
if (index.m_pParams)
{ m_pParams = new SqlStmtParameters(*(index.m_pParams)); }
{
m_pParams = new SqlStmtParameters(*(index.m_pParams));
}
}
return *this;
@ -132,7 +138,9 @@ void SqlPlainPreparedStatement::bind(const SqlStmtParameters& holder)
bool SqlPlainPreparedStatement::execute()
{
if (m_szPlainRequest.empty())
{ return false; }
{
return false;
}
return m_pConn.Execute(m_szPlainRequest.c_str());
}

View file

@ -446,7 +446,9 @@ class SqlStatement
SqlStatement(const SqlStatement& index) : m_index(index.m_index), m_pDB(index.m_pDB), m_pParams(NULL)
{
if (index.m_pParams)
{ m_pParams = new SqlStmtParameters(*(index.m_pParams)); }
{
m_pParams = new SqlStmtParameters(*(index.m_pParams));
}
}
/**
@ -655,7 +657,9 @@ class SqlStatement
SqlStmtParameters* get()
{
if (!m_pParams)
{ m_pParams = new SqlStmtParameters(arguments()); }
{
m_pParams = new SqlStmtParameters(arguments());
}
return m_pParams;
}