mirror of
https://github.com/mangosfour/server.git
synced 2025-12-18 01:37:01 +00:00
[8441] Implement check DBs versions (required_* fields) at mangosd/realmd loading.
* git_id updated to generate revision_sql.h file with required_* fields strings. * mangosd/realmd changed to include header and check this strings at startup. * mangosd/realmd will terminated if related strings not match in DB content. In most cases this meaning that not all expected sql updates applied. Current required_* field stored in DB output in error to help find what last sql updates applied. IMPORTNAT NOTE for mangos devs: please update used git_id before adding next commits with sql updates!
This commit is contained in:
parent
c9f475dfa0
commit
8a7b77c088
7 changed files with 111 additions and 7 deletions
|
|
@ -189,3 +189,43 @@ bool Database::DirectPExecute(const char * format,...)
|
|||
|
||||
return DirectExecute(szQuery);
|
||||
}
|
||||
|
||||
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);
|
||||
if(result)
|
||||
{
|
||||
delete result;
|
||||
return true;
|
||||
}
|
||||
|
||||
// check fail, prepare readabale error message
|
||||
|
||||
// search current required_* field in DB
|
||||
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_")
|
||||
{
|
||||
reqName = *itr;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
delete result;
|
||||
|
||||
if(!reqName.empty())
|
||||
{
|
||||
sLog.outErrorDb("Table `%s` have field `%s` but expected `%s`! Not all sql updates applied?",table_name,reqName.c_str(),required_name);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
sLog.outErrorDb("Table `%s` not have required_* field but expected `%s`! Not all sql updates applied?",table_name,required_name);
|
||||
return false;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue