mirror of
https://github.com/EQEmu/Server.git
synced 2025-12-12 17:51:28 +00:00
_GetFeeGuildID converted to QueryDatabase
This commit is contained in:
parent
a2d4376763
commit
7b440bbd9f
@ -313,27 +313,39 @@ uint32 BaseGuildManager::_GetFreeGuildID() {
|
|||||||
return(GUILD_NONE);
|
return(GUILD_NONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
char errbuf[MYSQL_ERRMSG_SIZE];
|
std::string query;
|
||||||
char query[100];
|
|
||||||
MYSQL_RES *result;
|
|
||||||
|
|
||||||
//this has got to be one of the more retarded things I have seen.
|
//this has got to be one of the more retarded things I have seen.
|
||||||
//none the less, im too lazy to rewrite it right now.
|
//none the less, im too lazy to rewrite it right now.
|
||||||
|
//possibly:
|
||||||
|
//
|
||||||
|
// SELECT t1.id + 1
|
||||||
|
// FROM guilds t1
|
||||||
|
// WHERE NOT EXISTS (
|
||||||
|
// SELECT *
|
||||||
|
// FROM guilds t2
|
||||||
|
// WHERE t2.id = t1.id + 1
|
||||||
|
// )
|
||||||
|
// LIMIT 1
|
||||||
|
//
|
||||||
|
// Seems likely what we should be doing is auto incrementing the guild table
|
||||||
|
// inserting, then getting the id. NOT getting a free id then inserting.
|
||||||
|
// could be a race condition.
|
||||||
|
|
||||||
uint16 x;
|
for (auto index = 1; index < MAX_NUMBER_GUILDS; ++index)
|
||||||
for (x = 1; x < MAX_NUMBER_GUILDS; x++) {
|
{
|
||||||
snprintf(query, 100, "SELECT id FROM guilds where id=%i;", x);
|
query = StringFormat("SELECT id FROM guilds where id=%i;", index);
|
||||||
|
auto results = m_db->QueryDatabase(query);
|
||||||
|
|
||||||
if (m_db->RunQuery(query, strlen(query), errbuf, &result)) {
|
if (!results.Success())
|
||||||
if (mysql_num_rows(result) == 0) {
|
{
|
||||||
mysql_free_result(result);
|
LogFile->write(EQEMuLog::Error, "Error in _GetFreeGuildID query '%s': %s", query.c_str(), results.ErrorMessage().c_str());
|
||||||
_log(GUILDS__DB, "Located free guild ID %d in the database", x);
|
continue;
|
||||||
return x;
|
|
||||||
}
|
|
||||||
mysql_free_result(result);
|
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
LogFile->write(EQEMuLog::Error, "Error in _GetFreeGuildID query '%s': %s", query, errbuf);
|
if (results.RowCount() == 0)
|
||||||
|
{
|
||||||
|
_log(GUILDS__DB, "Located free guild ID %d in the database", index);
|
||||||
|
return index;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user