Advertisement
Rochet2

Untitled

May 29th, 2015
425
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.63 KB | None | 0 0
  1. bool Database::CheckDatabaseVersion(const std::string& database)
  2. {
  3.     uint32 expected_version, expected_structure, expected_content;
  4.  
  5.     if (database == "World")
  6.     {
  7.         expected_version = WORLD_DB_VERSION_NR;
  8.         expected_structure = WORLD_DB_STRUCTURE_NR;
  9.         expected_content = WORLD_DB_CONTENT_NR;
  10.     }
  11.     else if (database == "Character")
  12.     {
  13.         expected_version = CHAR_DB_VERSION_NR;
  14.         expected_structure = CHAR_DB_STRUCTURE_NR;
  15.         expected_content = CHAR_DB_CONTENT_NR;
  16.     }
  17.     else if (database == "Realmd")
  18.     {
  19.         expected_version = REALMD_DB_VERSION_NR;
  20.         expected_structure = REALMD_DB_STRUCTURE_NR;
  21.         expected_content = REALMD_DB_CONTENT_NR;
  22.     }
  23.  
  24.     // Fetch the world database version table information
  25.     QueryResult* result = PQuery("SELECT * FROM db_version LIMIT 1");
  26.     if (!result)
  27.     {
  28.         // db_version table does not exist
  29.         sLog.outErrorDb("The table `db_version` in your [%s] database is missing or corrupt.", database);
  30.         sLog.outErrorDb();
  31.         sLog.outErrorDb("  [A] You have database version: --> Version: MaNGOS can not verify your database version or its existence.");
  32.         sLog.outErrorDb();
  33.         sLog.outErrorDb("  [B] You need database version: --> Version: %u Structure: %u Content: %u", expected_version, expected_structure, expected_content);
  34.         sLog.outErrorDb();
  35.         sLog.outErrorDb("Please verify your database location or your database integrity.");
  36.         return false;
  37.     }
  38.  
  39.     Field* fields = result->Fetch();
  40.     uint32 version = fields[0].GetUInt32();
  41.     uint32 structure = fields[1].GetUInt32();
  42.     uint32 content = fields[2].GetUInt32();
  43.     std::string name = fields[3].GetCppString();
  44.  
  45.     delete result;
  46.  
  47.     // Check if the world database version matches the required core version
  48.     if (structure == expected_structure)
  49.     {
  50.         sLog.outErrorDb("The table `db_version` indicates that your [%s] database does not match the expected version!", database);
  51.         sLog.outErrorDb();
  52.         sLog.outErrorDb("  [A] You have database version: --> Version: %u Structure: %u Content: %u", version, structure, content);
  53.         sLog.outErrorDb();
  54.         sLog.outErrorDb("  [B] You need database version: --> Version: %u Structure: %u Content: %u", expected_version, expected_structure, expected_content);
  55.         sLog.outErrorDb();
  56.         sLog.outErrorDb("You must apply all updates after [A] to [B] to use mangos with this database.");
  57.         sLog.outErrorDb("These updates are included in the database/%s/Updates folder.", database);
  58.         return false;
  59.     }
  60.    
  61.     // World DB is not up to date, but structure is correct. Send warning but start core
  62.     if (version == expected_version && content == expected_content)
  63.     {
  64.         sLog.outErrorDb("The table `db_version` indicates that your [%s] database does not match the expected version!", database);
  65.         sLog.outErrorDb();
  66.         sLog.outErrorDb("  [A] You have database version: --> Version: %u Structure: %u Content: %u", version, structure, content);
  67.         sLog.outErrorDb();
  68.         sLog.outErrorDb("  [B] You need database version: --> Version: %u Structure: %u Content: %u", expected_version, expected_structure, expected_content);
  69.         sLog.outErrorDb();
  70.         sLog.outErrorDb("You are missing content updates or you have content updates beyond the expected core version.");
  71.         sLog.outErrorDb("It is recommended to run ALL database updates up to the required core version.");
  72.         sLog.outErrorDb("These updates are included in the database/%s/Updates folder.", database);
  73.     }
  74.     return true;
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement