Cleanup Operator padding

This commit is contained in:
Schmoozerd 2012-07-20 17:38:23 +02:00
parent 9141299127
commit e32b9953a1
264 changed files with 6715 additions and 6715 deletions

View file

@ -35,35 +35,35 @@ bool DBCFileLoader::Load(const char* filename, const char* fmt)
if (data)
{
delete [] data;
data=NULL;
data = NULL;
}
FILE* f=fopen(filename,"rb");
FILE* f = fopen(filename, "rb");
if (!f)return false;
if (fread(&header,4,1,f)!=1) // Number of records
if (fread(&header, 4, 1, f) != 1) // Number of records
return false;
EndianConvert(header);
if (header!=0x43424457)
if (header != 0x43424457)
return false; //'WDBC'
if (fread(&recordCount,4,1,f)!=1) // Number of records
if (fread(&recordCount, 4, 1, f) != 1) // Number of records
return false;
EndianConvert(recordCount);
if (fread(&fieldCount,4,1,f)!=1) // Number of fields
if (fread(&fieldCount, 4, 1, f) != 1) // Number of fields
return false;
EndianConvert(fieldCount);
if (fread(&recordSize,4,1,f)!=1) // Size of a record
if (fread(&recordSize, 4, 1, f) != 1) // Size of a record
return false;
EndianConvert(recordSize);
if (fread(&stringSize,4,1,f)!=1) // String size
if (fread(&stringSize, 4, 1, f) != 1) // String size
return false;
EndianConvert(stringSize);
@ -79,10 +79,10 @@ bool DBCFileLoader::Load(const char* filename, const char* fmt)
fieldsOffset[i] += 4;
}
data = new unsigned char[recordSize*recordCount+stringSize];
stringTable = data + recordSize*recordCount;
data = new unsigned char[recordSize * recordCount + stringSize];
stringTable = data + recordSize * recordCount;
if (fread(data,recordSize*recordCount+stringSize,1,f)!=1)
if (fread(data, recordSize * recordCount + stringSize, 1, f) != 1)
return false;
fclose(f);
@ -100,10 +100,10 @@ DBCFileLoader::~DBCFileLoader()
DBCFileLoader::Record DBCFileLoader::getRecord(size_t id)
{
assert(data);
return Record(*this, data + id*recordSize);
return Record(*this, data + id * recordSize);
}
uint32 DBCFileLoader::GetFormatRecordSize(const char* format,int32* index_pos)
uint32 DBCFileLoader::GetFormatRecordSize(const char* format, int32* index_pos)
{
uint32 recordsize = 0;
int32 i = -1;
@ -121,10 +121,10 @@ uint32 DBCFileLoader::GetFormatRecordSize(const char* format,int32* index_pos)
recordsize += sizeof(char*);
break;
case FT_SORT:
i=x;
i = x;
break;
case FT_IND:
i=x;
i = x;
recordsize += sizeof(uint32);
break;
case FT_BYTE:
@ -162,27 +162,27 @@ char* DBCFileLoader::AutoProduceData(const char* format, uint32& records, char**
*/
typedef char* ptr;
if (strlen(format)!=fieldCount)
if (strlen(format) != fieldCount)
return NULL;
//get struct size and index pos
int32 i;
uint32 recordsize=GetFormatRecordSize(format,&i);
uint32 recordsize = GetFormatRecordSize(format, &i);
if (i>=0)
if (i >= 0)
{
uint32 maxi=0;
uint32 maxi = 0;
//find max index
for (uint32 y=0; y<recordCount; y++)
for (uint32 y = 0; y < recordCount; y++)
{
uint32 ind=getRecord(y).getUInt(i);
if (ind>maxi)maxi=ind;
uint32 ind = getRecord(y).getUInt(i);
if (ind > maxi)maxi = ind;
}
++maxi;
records=maxi;
indexTable=new ptr[maxi];
memset(indexTable,0,maxi*sizeof(ptr));
records = maxi;
indexTable = new ptr[maxi];
memset(indexTable, 0, maxi * sizeof(ptr));
}
else
{
@ -190,38 +190,38 @@ char* DBCFileLoader::AutoProduceData(const char* format, uint32& records, char**
indexTable = new ptr[recordCount];
}
char* dataTable= new char[recordCount*recordsize];
char* dataTable = new char[recordCount * recordsize];
uint32 offset=0;
uint32 offset = 0;
for (uint32 y =0; y < recordCount; ++y)
for (uint32 y = 0; y < recordCount; ++y)
{
if (i >= 0)
{
indexTable[getRecord(y).getUInt(i)]=&dataTable[offset];
indexTable[getRecord(y).getUInt(i)] = &dataTable[offset];
}
else
indexTable[y]=&dataTable[offset];
indexTable[y] = &dataTable[offset];
for (uint32 x = 0; x < fieldCount; ++x)
{
switch (format[x])
{
case FT_FLOAT:
*((float*)(&dataTable[offset]))=getRecord(y).getFloat(x);
*((float*)(&dataTable[offset])) = getRecord(y).getFloat(x);
offset += sizeof(float);
break;
case FT_IND:
case FT_INT:
*((uint32*)(&dataTable[offset]))=getRecord(y).getUInt(x);
*((uint32*)(&dataTable[offset])) = getRecord(y).getUInt(x);
offset += sizeof(uint32);
break;
case FT_BYTE:
*((uint8*)(&dataTable[offset]))=getRecord(y).getUInt8(x);
*((uint8*)(&dataTable[offset])) = getRecord(y).getUInt8(x);
offset += sizeof(uint8);
break;
case FT_STRING:
*((char**)(&dataTable[offset]))=NULL; // will be replaces non-empty or "" strings in AutoProduceStrings
*((char**)(&dataTable[offset])) = NULL; // will be replaces non-empty or "" strings in AutoProduceStrings
offset += sizeof(char*);
break;
case FT_LOGIC:
@ -243,15 +243,15 @@ char* DBCFileLoader::AutoProduceData(const char* format, uint32& records, char**
char* DBCFileLoader::AutoProduceStrings(const char* format, char* dataTable)
{
if (strlen(format)!=fieldCount)
if (strlen(format) != fieldCount)
return NULL;
char* stringPool= new char[stringSize];
memcpy(stringPool,stringTable,stringSize);
char* stringPool = new char[stringSize];
memcpy(stringPool, stringTable, stringSize);
uint32 offset=0;
uint32 offset = 0;
for (uint32 y =0; y < recordCount; ++y)
for (uint32 y = 0; y < recordCount; ++y)
{
for (uint32 x = 0; x < fieldCount; ++x)
{
@ -274,7 +274,7 @@ char* DBCFileLoader::AutoProduceStrings(const char* format, char* dataTable)
if (!*slot || !** slot)
{
const char* st = getRecord(y).getString(x);
*slot=stringPool+(st-(const char*)stringTable);
*slot = stringPool + (st - (const char*)stringTable);
}
offset += sizeof(char*);
break;

View file

@ -24,17 +24,17 @@
enum
{
FT_NA='x', // ignore/ default, 4 byte size, in Source String means field is ignored, in Dest String means field is filled with default value
FT_NA_BYTE='X', // ignore/ default, 1 byte size, see above
FT_NA_FLOAT='F', // ignore/ default, float size, see above
FT_NA_POINTER='p', // fill default value into dest, pointer size, Use this only with static data (otherwise mem-leak)
FT_STRING='s', //char*
FT_FLOAT='f', //float
FT_INT='i', //uint32
FT_BYTE='b', //uint8
FT_SORT='d', //sorted by this field, field is not included
FT_IND='n', //the same,but parsed to data
FT_LOGIC='l' //Logical (boolean)
FT_NA = 'x', // ignore/ default, 4 byte size, in Source String means field is ignored, in Dest String means field is filled with default value
FT_NA_BYTE = 'X', // ignore/ default, 1 byte size, see above
FT_NA_FLOAT = 'F', // ignore/ default, float size, see above
FT_NA_POINTER = 'p', // fill default value into dest, pointer size, Use this only with static data (otherwise mem-leak)
FT_STRING = 's', //char*
FT_FLOAT = 'f', //float
FT_INT = 'i', //uint32
FT_BYTE = 'b', //uint8
FT_SORT = 'd', //sorted by this field, field is not included
FT_IND = 'n', //the same,but parsed to data
FT_LOGIC = 'l' //Logical (boolean)
};
class DBCFileLoader
@ -51,21 +51,21 @@ class DBCFileLoader
float getFloat(size_t field) const
{
assert(field < file.fieldCount);
float val = *reinterpret_cast<float*>(offset+file.GetOffset(field));
float val = *reinterpret_cast<float*>(offset + file.GetOffset(field));
EndianConvert(val);
return val;
}
uint32 getUInt(size_t field) const
{
assert(field < file.fieldCount);
uint32 val = *reinterpret_cast<uint32*>(offset+file.GetOffset(field));
uint32 val = *reinterpret_cast<uint32*>(offset + file.GetOffset(field));
EndianConvert(val);
return val;
}
uint8 getUInt8(size_t field) const
{
assert(field < file.fieldCount);
return *reinterpret_cast<uint8*>(offset+file.GetOffset(field));
return *reinterpret_cast<uint8*>(offset + file.GetOffset(field));
}
const char* getString(size_t field) const
@ -92,7 +92,7 @@ class DBCFileLoader
uint32 GetNumRows() const { return recordCount;}
uint32 GetCols() const { return fieldCount; }
uint32 GetOffset(size_t id) const { return (fieldsOffset != NULL && id < fieldCount) ? fieldsOffset[id] : 0; }
bool IsLoaded() {return (data!=NULL);}
bool IsLoaded() {return (data != NULL);}
char* AutoProduceData(const char* fmt, uint32& count, char**& indexTable);
char* AutoProduceStrings(const char* fmt, char* dataTable);
static uint32 GetFormatRecordSize(const char* format, int32* index_pos = NULL);

View file

@ -44,13 +44,13 @@ class DBCStorage
fieldCount = dbc.GetCols();
// load raw non-string data
m_dataTable = (T*)dbc.AutoProduceData(fmt,nCount,(char**&)indexTable);
m_dataTable = (T*)dbc.AutoProduceData(fmt, nCount, (char**&)indexTable);
// load strings from dbc data
m_stringPoolList.push_back(dbc.AutoProduceStrings(fmt,(char*)m_dataTable));
m_stringPoolList.push_back(dbc.AutoProduceStrings(fmt, (char*)m_dataTable));
// error in dbc file at loading if NULL
return indexTable!=NULL;
return indexTable != NULL;
}
bool LoadStringsFrom(char const* fn)
@ -65,7 +65,7 @@ class DBCStorage
return false;
// load strings from another locale dbc data
m_stringPoolList.push_back(dbc.AutoProduceStrings(fmt,(char*)m_dataTable));
m_stringPoolList.push_back(dbc.AutoProduceStrings(fmt, (char*)m_dataTable));
return true;
}

View file

@ -104,10 +104,10 @@ bool Database::Initialize(const char* infoString, int nConns /*= 1*/)
// Enable logging of SQL commands (usually only GM commands)
// (See method: PExecuteLog)
m_logSQL = sConfig.GetBoolDefault("LogSQL", false);
m_logsDir = sConfig.GetStringDefault("LogsDir","");
m_logsDir = sConfig.GetStringDefault("LogsDir", "");
if (!m_logsDir.empty())
{
if ((m_logsDir.at(m_logsDir.length()-1)!='/') && (m_logsDir.at(m_logsDir.length()-1)!='\\'))
if ((m_logsDir.at(m_logsDir.length() - 1) != '/') && (m_logsDir.at(m_logsDir.length() - 1) != '\\'))
m_logsDir.append("/");
}
@ -215,9 +215,9 @@ void Database::escape_string(std::string& str)
if (str.empty())
return;
char* buf = new char[str.size()*2+1];
char* buf = new char[str.size() * 2 + 1];
//we don't care what connection to use - escape string will be the same
m_pQueryConnections[0]->escape_string(buf,str.c_str(),str.size());
m_pQueryConnections[0]->escape_string(buf, str.c_str(), str.size());
str = buf;
delete[] buf;
}
@ -250,7 +250,7 @@ void Database::Ping()
}
}
bool Database::PExecuteLog(const char* format,...)
bool Database::PExecuteLog(const char* format, ...)
{
if (!format)
return false;
@ -261,9 +261,9 @@ bool Database::PExecuteLog(const char* format,...)
int res = vsnprintf(szQuery, MAX_QUERY_LEN, format, ap);
va_end(ap);
if (res==-1)
if (res == -1)
{
sLog.outError("SQL Query truncated (and not execute) for format: %s",format);
sLog.outError("SQL Query truncated (and not execute) for format: %s", format);
return false;
}
@ -272,12 +272,12 @@ bool Database::PExecuteLog(const char* format,...)
time_t curr;
tm local;
time(&curr); // get current time_t value
local=*(localtime(&curr)); // dereference and assign
local = *(localtime(&curr)); // dereference and assign
char fName[128];
sprintf(fName, "%04d-%02d-%02d_logSQL.sql", local.tm_year+1900, local.tm_mon+1, local.tm_mday);
sprintf(fName, "%04d-%02d-%02d_logSQL.sql", local.tm_year + 1900, local.tm_mon + 1, local.tm_mday);
FILE* log_file;
std::string logsDir_fname = m_logsDir+fName;
std::string logsDir_fname = m_logsDir + fName;
log_file = fopen(logsDir_fname.c_str(), "a");
if (log_file)
{
@ -287,14 +287,14 @@ bool Database::PExecuteLog(const char* format,...)
else
{
// The file could not be opened
sLog.outError("SQL-Logging is disabled - Log file for the SQL commands could not be openend: %s",fName);
sLog.outError("SQL-Logging is disabled - Log file for the SQL commands could not be openend: %s", fName);
}
}
return Execute(szQuery);
}
QueryResult* Database::PQuery(const char* format,...)
QueryResult* Database::PQuery(const char* format, ...)
{
if (!format) return NULL;
@ -304,16 +304,16 @@ QueryResult* Database::PQuery(const char* format,...)
int res = vsnprintf(szQuery, MAX_QUERY_LEN, format, ap);
va_end(ap);
if (res==-1)
if (res == -1)
{
sLog.outError("SQL Query truncated (and not execute) for format: %s",format);
sLog.outError("SQL Query truncated (and not execute) for format: %s", format);
return NULL;
}
return Query(szQuery);
}
QueryNamedResult* Database::PQueryNamed(const char* format,...)
QueryNamedResult* Database::PQueryNamed(const char* format, ...)
{
if (!format) return NULL;
@ -323,9 +323,9 @@ QueryNamedResult* Database::PQueryNamed(const char* format,...)
int res = vsnprintf(szQuery, MAX_QUERY_LEN, format, ap);
va_end(ap);
if (res==-1)
if (res == -1)
{
sLog.outError("SQL Query truncated (and not execute) for format: %s",format);
sLog.outError("SQL Query truncated (and not execute) for format: %s", format);
return NULL;
}
@ -356,7 +356,7 @@ bool Database::Execute(const char* sql)
return true;
}
bool Database::PExecute(const char* format,...)
bool Database::PExecute(const char* format, ...)
{
if (!format)
return false;
@ -367,16 +367,16 @@ bool Database::PExecute(const char* format,...)
int res = vsnprintf(szQuery, MAX_QUERY_LEN, format, ap);
va_end(ap);
if (res==-1)
if (res == -1)
{
sLog.outError("SQL Query truncated (and not execute) for format: %s",format);
sLog.outError("SQL Query truncated (and not execute) for format: %s", format);
return false;
}
return Execute(szQuery);
}
bool Database::DirectPExecute(const char* format,...)
bool Database::DirectPExecute(const char* format, ...)
{
if (!format)
return false;
@ -387,9 +387,9 @@ bool Database::DirectPExecute(const char* format,...)
int res = vsnprintf(szQuery, MAX_QUERY_LEN, format, ap);
va_end(ap);
if (res==-1)
if (res == -1)
{
sLog.outError("SQL Query truncated (and not execute) for format: %s",format);
sLog.outError("SQL Query truncated (and not execute) for format: %s", format);
return false;
}
@ -459,7 +459,7 @@ bool Database::RollbackTransaction()
bool Database::CheckRequiredField(char const* table_name, char const* required_name)
{
// check required field
QueryResult* result = PQuery("SELECT %s FROM %s LIMIT 1",required_name,table_name);
QueryResult* result = PQuery("SELECT %s FROM %s LIMIT 1", required_name, table_name);
if (result)
{
delete result;
@ -479,16 +479,16 @@ bool Database::CheckRequiredField(char const* table_name, char const* required_n
else
db_name = "UNKNOWN";
char const* req_sql_update_name = required_name+strlen("required_");
char const* req_sql_update_name = required_name + strlen("required_");
QueryNamedResult* result2 = PQueryNamed("SELECT * FROM %s LIMIT 1",table_name);
QueryNamedResult* result2 = PQueryNamed("SELECT * FROM %s LIMIT 1", table_name);
if (result2)
{
QueryFieldNames const& namesMap = result2->GetFieldNames();
std::string reqName;
for (QueryFieldNames::const_iterator itr = namesMap.begin(); itr != namesMap.end(); ++itr)
{
if (itr->substr(0,9)=="required_")
if (itr->substr(0, 9) == "required_")
{
reqName = *itr;
break;
@ -497,15 +497,15 @@ bool Database::CheckRequiredField(char const* table_name, char const* required_n
delete result2;
std::string cur_sql_update_name = reqName.substr(strlen("required_"),reqName.npos);
std::string cur_sql_update_name = reqName.substr(strlen("required_"), reqName.npos);
if (!reqName.empty())
{
sLog.outErrorDb("The table `%s` in your [%s] database indicates that this database is out of date!",table_name,db_name);
sLog.outErrorDb("The table `%s` in your [%s] database indicates that this database is out of date!", table_name, db_name);
sLog.outErrorDb();
sLog.outErrorDb(" [A] You have: --> `%s.sql`",cur_sql_update_name.c_str());
sLog.outErrorDb(" [A] You have: --> `%s.sql`", cur_sql_update_name.c_str());
sLog.outErrorDb();
sLog.outErrorDb(" [B] You need: --> `%s.sql`",req_sql_update_name);
sLog.outErrorDb(" [B] You need: --> `%s.sql`", req_sql_update_name);
sLog.outErrorDb();
sLog.outErrorDb("You must apply all updates after [A] to [B] to use mangos with this database.");
sLog.outErrorDb("These updates are included in the sql/updates folder.");
@ -513,32 +513,32 @@ bool Database::CheckRequiredField(char const* table_name, char const* required_n
}
else
{
sLog.outErrorDb("The table `%s` in your [%s] database is missing its version info.",table_name,db_name);
sLog.outErrorDb("The table `%s` in your [%s] database is missing its version info.", table_name, db_name);
sLog.outErrorDb("MaNGOS cannot find the version info needed to check that the db is up to date.");
sLog.outErrorDb();
sLog.outErrorDb("This revision of MaNGOS requires a database updated to:");
sLog.outErrorDb("`%s.sql`",req_sql_update_name);
sLog.outErrorDb("`%s.sql`", req_sql_update_name);
sLog.outErrorDb();
if (!strcmp(db_name, "WORLD"))
sLog.outErrorDb("Post this error to your database provider forum or find a solution there.");
else
sLog.outErrorDb("Reinstall your [%s] database with the included sql file in the sql folder.",db_name);
sLog.outErrorDb("Reinstall your [%s] database with the included sql file in the sql folder.", db_name);
}
}
else
{
sLog.outErrorDb("The table `%s` in your [%s] database is missing or corrupt.",table_name,db_name);
sLog.outErrorDb("The table `%s` in your [%s] database is missing or corrupt.", table_name, db_name);
sLog.outErrorDb("MaNGOS cannot find the version info needed to check that the db is up to date.");
sLog.outErrorDb();
sLog.outErrorDb("This revision of mangos requires a database updated to:");
sLog.outErrorDb("`%s.sql`",req_sql_update_name);
sLog.outErrorDb("`%s.sql`", req_sql_update_name);
sLog.outErrorDb();
if (!strcmp(db_name, "WORLD"))
sLog.outErrorDb("Post this error to your database provider forum or find a solution there.");
else
sLog.outErrorDb("Reinstall your [%s] database with the included sql file in the sql folder.",db_name);
sLog.outErrorDb("Reinstall your [%s] database with the included sql file in the sql folder.", db_name);
}
return false;

View file

@ -53,7 +53,7 @@ class MANGOS_DLL_SPEC SqlConnection
virtual bool Execute(const char* sql) = 0;
//escape string generation
virtual unsigned long escape_string(char* to, const char* from, unsigned long length) { strncpy(to,from,length); return length; }
virtual unsigned long escape_string(char* to, const char* from, unsigned long length) { strncpy(to, from, length); return length; }
// nothing do if DB not support transactions
virtual bool BeginTransaction() { return true; }
@ -124,8 +124,8 @@ class MANGOS_DLL_SPEC Database
return guard->QueryNamed(sql);
}
QueryResult* PQuery(const char* format,...) ATTR_PRINTF(2,3);
QueryNamedResult* PQueryNamed(const char* format,...) ATTR_PRINTF(2,3);
QueryResult* PQuery(const char* format, ...) ATTR_PRINTF(2, 3);
QueryNamedResult* PQueryNamed(const char* format, ...) ATTR_PRINTF(2, 3);
inline bool DirectExecute(const char* sql)
{
@ -136,7 +136,7 @@ class MANGOS_DLL_SPEC Database
return guard->Execute(sql);
}
bool DirectPExecute(const char* format,...) ATTR_PRINTF(2,3);
bool DirectPExecute(const char* format, ...) ATTR_PRINTF(2, 3);
/// Async queries and query holders, implemented in DatabaseImpl.h
@ -158,20 +158,20 @@ class MANGOS_DLL_SPEC Database
bool AsyncQuery(void (*method)(QueryResult*, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char* sql);
// PQuery / member
template<class Class>
bool AsyncPQuery(Class* object, void (Class::*method)(QueryResult*), const char* format,...) ATTR_PRINTF(4,5);
bool AsyncPQuery(Class* object, void (Class::*method)(QueryResult*), const char* format, ...) ATTR_PRINTF(4, 5);
template<class Class, typename ParamType1>
bool AsyncPQuery(Class* object, void (Class::*method)(QueryResult*, ParamType1), ParamType1 param1, const char* format,...) ATTR_PRINTF(5,6);
bool AsyncPQuery(Class* object, void (Class::*method)(QueryResult*, ParamType1), ParamType1 param1, const char* format, ...) ATTR_PRINTF(5, 6);
template<class Class, typename ParamType1, typename ParamType2>
bool AsyncPQuery(Class* object, void (Class::*method)(QueryResult*, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char* format,...) ATTR_PRINTF(6,7);
bool AsyncPQuery(Class* object, void (Class::*method)(QueryResult*, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char* format, ...) ATTR_PRINTF(6, 7);
template<class Class, typename ParamType1, typename ParamType2, typename ParamType3>
bool AsyncPQuery(Class* object, void (Class::*method)(QueryResult*, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char* format,...) ATTR_PRINTF(7,8);
bool AsyncPQuery(Class* object, void (Class::*method)(QueryResult*, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char* format, ...) ATTR_PRINTF(7, 8);
// PQuery / static
template<typename ParamType1>
bool AsyncPQuery(void (*method)(QueryResult*, ParamType1), ParamType1 param1, const char* format,...) ATTR_PRINTF(4,5);
bool AsyncPQuery(void (*method)(QueryResult*, ParamType1), ParamType1 param1, const char* format, ...) ATTR_PRINTF(4, 5);
template<typename ParamType1, typename ParamType2>
bool AsyncPQuery(void (*method)(QueryResult*, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char* format,...) ATTR_PRINTF(5,6);
bool AsyncPQuery(void (*method)(QueryResult*, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char* format, ...) ATTR_PRINTF(5, 6);
template<typename ParamType1, typename ParamType2, typename ParamType3>
bool AsyncPQuery(void (*method)(QueryResult*, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char* format,...) ATTR_PRINTF(6,7);
bool AsyncPQuery(void (*method)(QueryResult*, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char* format, ...) ATTR_PRINTF(6, 7);
template<class Class>
// QueryHolder
bool DelayQueryHolder(Class* object, void (Class::*method)(QueryResult*, SqlQueryHolder*), SqlQueryHolder* holder);
@ -179,10 +179,10 @@ class MANGOS_DLL_SPEC Database
bool DelayQueryHolder(Class* object, void (Class::*method)(QueryResult*, SqlQueryHolder*, ParamType1), SqlQueryHolder* holder, ParamType1 param1);
bool Execute(const char* sql);
bool PExecute(const char* format,...) ATTR_PRINTF(2,3);
bool PExecute(const char* format, ...) ATTR_PRINTF(2, 3);
// Writes SQL commands to a LOG file (see mangosd.conf "LogSQL")
bool PExecuteLog(const char* format,...) ATTR_PRINTF(2,3);
bool PExecuteLog(const char* format, ...) ATTR_PRINTF(2, 3);
bool BeginTransaction();
bool CommitTransaction();

View file

@ -107,7 +107,7 @@ Database::AsyncQuery(void (*method)(QueryResult*, ParamType1, ParamType2, ParamT
template<class Class>
bool
Database::AsyncPQuery(Class* object, void (Class::*method)(QueryResult*), const char* format,...)
Database::AsyncPQuery(Class* object, void (Class::*method)(QueryResult*), const char* format, ...)
{
ASYNC_PQUERY_BODY(format, szQuery)
return AsyncQuery(object, method, szQuery);
@ -115,7 +115,7 @@ Database::AsyncPQuery(Class* object, void (Class::*method)(QueryResult*), const
template<class Class, typename ParamType1>
bool
Database::AsyncPQuery(Class* object, void (Class::*method)(QueryResult*, ParamType1), ParamType1 param1, const char* format,...)
Database::AsyncPQuery(Class* object, void (Class::*method)(QueryResult*, ParamType1), ParamType1 param1, const char* format, ...)
{
ASYNC_PQUERY_BODY(format, szQuery)
return AsyncQuery(object, method, param1, szQuery);
@ -123,7 +123,7 @@ Database::AsyncPQuery(Class* object, void (Class::*method)(QueryResult*, ParamTy
template<class Class, typename ParamType1, typename ParamType2>
bool
Database::AsyncPQuery(Class* object, void (Class::*method)(QueryResult*, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char* format,...)
Database::AsyncPQuery(Class* object, void (Class::*method)(QueryResult*, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char* format, ...)
{
ASYNC_PQUERY_BODY(format, szQuery)
return AsyncQuery(object, method, param1, param2, szQuery);
@ -131,7 +131,7 @@ Database::AsyncPQuery(Class* object, void (Class::*method)(QueryResult*, ParamTy
template<class Class, typename ParamType1, typename ParamType2, typename ParamType3>
bool
Database::AsyncPQuery(Class* object, void (Class::*method)(QueryResult*, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char* format,...)
Database::AsyncPQuery(Class* object, void (Class::*method)(QueryResult*, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char* format, ...)
{
ASYNC_PQUERY_BODY(format, szQuery)
return AsyncQuery(object, method, param1, param2, param3, szQuery);
@ -141,7 +141,7 @@ Database::AsyncPQuery(Class* object, void (Class::*method)(QueryResult*, ParamTy
template<typename ParamType1>
bool
Database::AsyncPQuery(void (*method)(QueryResult*, ParamType1), ParamType1 param1, const char* format,...)
Database::AsyncPQuery(void (*method)(QueryResult*, ParamType1), ParamType1 param1, const char* format, ...)
{
ASYNC_PQUERY_BODY(format, szQuery)
return AsyncQuery(method, param1, szQuery);
@ -149,7 +149,7 @@ Database::AsyncPQuery(void (*method)(QueryResult*, ParamType1), ParamType1 param
template<typename ParamType1, typename ParamType2>
bool
Database::AsyncPQuery(void (*method)(QueryResult*, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char* format,...)
Database::AsyncPQuery(void (*method)(QueryResult*, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char* format, ...)
{
ASYNC_PQUERY_BODY(format, szQuery)
return AsyncQuery(method, param1, param2, szQuery);
@ -157,7 +157,7 @@ Database::AsyncPQuery(void (*method)(QueryResult*, ParamType1, ParamType2), Para
template<typename ParamType1, typename ParamType2, typename ParamType3>
bool
Database::AsyncPQuery(void (*method)(QueryResult*, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char* format,...)
Database::AsyncPQuery(void (*method)(QueryResult*, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char* format, ...)
{
ASYNC_PQUERY_BODY(format, szQuery)
return AsyncQuery(method, param1, param2, param3, szQuery);

View file

@ -104,12 +104,12 @@ bool MySQLConnection::Initialize(const char* infoString)
if (iter != tokens.end())
database = *iter++;
mysql_options(mysqlInit,MYSQL_SET_CHARSET_NAME,"utf8");
mysql_options(mysqlInit, MYSQL_SET_CHARSET_NAME, "utf8");
#ifdef WIN32
if (host==".") // named pipe use option (Windows)
if (host == ".") // named pipe use option (Windows)
{
unsigned int opt = MYSQL_PROTOCOL_PIPE;
mysql_options(mysqlInit,MYSQL_OPT_PROTOCOL,(char const*)&opt);
mysql_options(mysqlInit, MYSQL_OPT_PROTOCOL, (char const*)&opt);
port = 0;
unix_socket = 0;
}
@ -119,10 +119,10 @@ bool MySQLConnection::Initialize(const char* infoString)
unix_socket = 0;
}
#else
if (host==".") // socket use option (Unix/Linux)
if (host == ".") // socket use option (Unix/Linux)
{
unsigned int opt = MYSQL_PROTOCOL_SOCKET;
mysql_options(mysqlInit,MYSQL_OPT_PROTOCOL,(char const*)&opt);
mysql_options(mysqlInit, MYSQL_OPT_PROTOCOL, (char const*)&opt);
host = "localhost";
port = 0;
unix_socket = port_or_socket.c_str();
@ -140,7 +140,7 @@ bool MySQLConnection::Initialize(const char* infoString)
if (!mMysql)
{
sLog.outError("Could not connect to MySQL database at %s: %s\n",
host.c_str(),mysql_error(mysqlInit));
host.c_str(), mysql_error(mysqlInit));
mysql_close(mysqlInit);
return false;
}
@ -189,7 +189,7 @@ bool MySQLConnection::_Query(const char* sql, MYSQL_RES** pResult, MYSQL_FIELD**
}
else
{
DEBUG_FILTER_LOG(LOG_FILTER_SQL_TEXT, "[%u ms] SQL: %s", WorldTimer::getMSTimeDiff(_s,WorldTimer::getMSTime()), sql);
DEBUG_FILTER_LOG(LOG_FILTER_SQL_TEXT, "[%u ms] SQL: %s", WorldTimer::getMSTimeDiff(_s, WorldTimer::getMSTime()), sql);
}
*pResult = mysql_store_result(mMysql);
@ -216,7 +216,7 @@ QueryResult* MySQLConnection::Query(const char* sql)
uint64 rowCount = 0;
uint32 fieldCount = 0;
if (!_Query(sql,&result,&fields,&rowCount,&fieldCount))
if (!_Query(sql, &result, &fields, &rowCount, &fieldCount))
return NULL;
QueryResultMysql* queryResult = new QueryResultMysql(result, fields, rowCount, fieldCount);
@ -232,7 +232,7 @@ QueryNamedResult* MySQLConnection::QueryNamed(const char* sql)
uint64 rowCount = 0;
uint32 fieldCount = 0;
if (!_Query(sql,&result,&fields,&rowCount,&fieldCount))
if (!_Query(sql, &result, &fields, &rowCount, &fieldCount))
return NULL;
QueryFieldNames names(fieldCount);
@ -242,7 +242,7 @@ QueryNamedResult* MySQLConnection::QueryNamed(const char* sql)
QueryResultMysql* queryResult = new QueryResultMysql(result, fields, rowCount, fieldCount);
queryResult->NextRow();
return new QueryNamedResult(queryResult,names);
return new QueryNamedResult(queryResult, names);
}
bool MySQLConnection::Execute(const char* sql)
@ -261,7 +261,7 @@ bool MySQLConnection::Execute(const char* sql)
}
else
{
DEBUG_FILTER_LOG(LOG_FILTER_SQL_TEXT, "[%u ms] SQL: %s", WorldTimer::getMSTimeDiff(_s,WorldTimer::getMSTime()), sql);
DEBUG_FILTER_LOG(LOG_FILTER_SQL_TEXT, "[%u ms] SQL: %s", WorldTimer::getMSTimeDiff(_s, WorldTimer::getMSTime()), sql);
}
// end guarded block
}

View file

@ -117,7 +117,7 @@ bool PostgreSQLConnection::_Query(const char* sql, PGresult** pResult, uint64* p
}
else
{
DEBUG_FILTER_LOG(LOG_FILTER_SQL_TEXT, "[%u ms] SQL: %s", WorldTimer::getMSTimeDiff(_s,WorldTimer::getMSTime()), sql);
DEBUG_FILTER_LOG(LOG_FILTER_SQL_TEXT, "[%u ms] SQL: %s", WorldTimer::getMSTimeDiff(_s, WorldTimer::getMSTime()), sql);
}
*pRowCount = PQntuples(*pResult);
@ -142,7 +142,7 @@ QueryResult* PostgreSQLConnection::Query(const char* sql)
uint64 rowCount = 0;
uint32 fieldCount = 0;
if (!_Query(sql,&result,&rowCount,&fieldCount))
if (!_Query(sql, &result, &rowCount, &fieldCount))
return NULL;
QueryResultPostgre* queryResult = new QueryResultPostgre(result, rowCount, fieldCount);
@ -160,7 +160,7 @@ QueryNamedResult* PostgreSQLConnection::QueryNamed(const char* sql)
uint64 rowCount = 0;
uint32 fieldCount = 0;
if (!_Query(sql,&result,&rowCount,&fieldCount))
if (!_Query(sql, &result, &rowCount, &fieldCount))
return NULL;
QueryFieldNames names(fieldCount);
@ -170,7 +170,7 @@ QueryNamedResult* PostgreSQLConnection::QueryNamed(const char* sql)
QueryResultPostgre* queryResult = new QueryResultPostgre(result, rowCount, fieldCount);
queryResult->NextRow();
return new QueryNamedResult(queryResult,names);
return new QueryNamedResult(queryResult, names);
}
bool PostgreSQLConnection::Execute(const char* sql)
@ -189,7 +189,7 @@ bool PostgreSQLConnection::Execute(const char* sql)
}
else
{
DEBUG_FILTER_LOG(LOG_FILTER_SQL_TEXT, "[%u ms] SQL: %s", WorldTimer::getMSTimeDiff(_s,WorldTimer::getMSTime()), sql);
DEBUG_FILTER_LOG(LOG_FILTER_SQL_TEXT, "[%u ms] SQL: %s", WorldTimer::getMSTimeDiff(_s, WorldTimer::getMSTime()), sql);
}
PQclear(res);

View file

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

View file

@ -36,7 +36,7 @@ void SQLStorage::EraseEntry(uint32 id)
case FT_STRING:
{
if (pIndex[id])
delete [] *(char**)((char*)(pIndex[id])+offset);
delete [] *(char**)((char*)(pIndex[id]) + offset);
offset += sizeof(char*);
break;
@ -81,7 +81,7 @@ void SQLStorage::Free()
{
for (uint32 y = 0; y < MaxEntry; ++y)
if (pIndex[y])
delete [] *(char**)((char*)(pIndex[y])+offset);
delete [] *(char**)((char*)(pIndex[y]) + offset);
offset += sizeof(char*);
break;

View file

@ -71,7 +71,7 @@ class SQLStorage
void init(const char* _entry_field, const char* sqlname)
{
entry_field = _entry_field;
table=sqlname;
table = sqlname;
data = NULL;
pIndex = NULL;
iNumFields = strlen(src_format);

View file

@ -84,35 +84,35 @@ void SQLStorageLoaderBase<T>::storeValue(V value, SQLStorage& store, char* p, ui
{
case FT_LOGIC:
subclass->convert(x, value, *((bool*)(&p[offset])));
offset+=sizeof(bool);
offset += sizeof(bool);
break;
case FT_BYTE:
subclass->convert(x, value, *((char*)(&p[offset])));
offset+=sizeof(char);
offset += sizeof(char);
break;
case FT_INT:
subclass->convert(x, value, *((uint32*)(&p[offset])));
offset+=sizeof(uint32);
offset += sizeof(uint32);
break;
case FT_FLOAT:
subclass->convert(x, value, *((float*)(&p[offset])));
offset+=sizeof(float);
offset += sizeof(float);
break;
case FT_STRING:
subclass->convert_to_str(x, value, *((char**)(&p[offset])));
offset+=sizeof(char*);
offset += sizeof(char*);
break;
case FT_NA:
subclass->default_fill(x, value, *((int32*)(&p[offset])));
offset+=sizeof(uint32);
offset += sizeof(uint32);
break;
case FT_NA_BYTE:
subclass->default_fill(x, value, *((char*)(&p[offset])));
offset+=sizeof(char);
offset += sizeof(char);
break;
case FT_NA_FLOAT:
subclass->default_fill(x, value, *((float*)(&p[offset])));
offset+=sizeof(float);
offset += sizeof(float);
break;
case FT_IND:
case FT_SORT:
@ -132,7 +132,7 @@ void SQLStorageLoaderBase<T>::storeValue(char const* value, SQLStorage& store, c
{
case FT_LOGIC:
subclass->convert_from_str(x, value, *((bool*)(&p[offset])));
offset+=sizeof(bool);
offset += sizeof(bool);
break;
case FT_BYTE:
subclass->convert_from_str(x, value, *((char*)(&p[offset])));
@ -177,7 +177,7 @@ void SQLStorageLoaderBase<T>::Load(SQLStorage& store, bool error_at_empty /*= tr
exit(1); // Stop server at loading non exited table or not accessable table
}
maxi = (*result)[0].GetUInt32()+1;
maxi = (*result)[0].GetUInt32() + 1;
delete result;
result = WorldDatabase.PQuery("SELECT COUNT(*) FROM %s", store.table);
@ -249,9 +249,9 @@ void SQLStorageLoaderBase<T>::Load(SQLStorage& store, bool error_at_empty /*= tr
}
char** newIndex = new char*[maxi];
memset(newIndex, 0, maxi*sizeof(char*));
memset(newIndex, 0, maxi * sizeof(char*));
char* _data= new char[store.RecordCount * recordsize];
char* _data = new char[store.RecordCount * recordsize];
uint32 count = 0;
BarGoLink bar(store.RecordCount);
do

View file

@ -130,7 +130,7 @@ bool SqlQueryHolder::SetQuery(size_t index, const char* sql)
if (m_queries[index].first != NULL)
{
sLog.outError("Attempt assign query to holder index (" SIZEFMTD ") where other query stored (Old: [%s] New: [%s])",
index,m_queries[index].first,sql);
index, m_queries[index].first, sql);
return false;
}
@ -143,7 +143,7 @@ bool SqlQueryHolder::SetPQuery(size_t index, const char* format, ...)
{
if (!format)
{
sLog.outError("Query (index: " SIZEFMTD ") is empty.",index);
sLog.outError("Query (index: " SIZEFMTD ") is empty.", index);
return false;
}
@ -153,13 +153,13 @@ bool SqlQueryHolder::SetPQuery(size_t index, const char* format, ...)
int res = vsnprintf(szQuery, MAX_QUERY_LEN, format, ap);
va_end(ap);
if (res==-1)
if (res == -1)
{
sLog.outError("SQL Query truncated (and not execute) for format: %s",format);
sLog.outError("SQL Query truncated (and not execute) for format: %s", format);
return false;
}
return SetQuery(index,szQuery);
return SetQuery(index, szQuery);
}
QueryResult* SqlQueryHolder::GetResult(size_t index)

View file

@ -118,7 +118,7 @@ class SqlQueryHolder
SqlQueryHolder() {}
~SqlQueryHolder();
bool SetQuery(size_t index, const char* sql);
bool SetPQuery(size_t index, const char* format, ...) ATTR_PRINTF(3,4);
bool SetPQuery(size_t index, const char* format, ...) ATTR_PRINTF(3, 4);
void SetSize(size_t size);
QueryResult* GetResult(size_t index);
void SetResult(size_t index, QueryResult* result);