fixed bug in agent local database structure check
authorVictor Kirhenshtein <victor@netxms.org>
Tue, 27 Sep 2016 14:17:25 +0000 (17:17 +0300)
committerVictor Kirhenshtein <victor@netxms.org>
Tue, 27 Sep 2016 14:17:25 +0000 (17:17 +0300)
src/agent/core/localdb.cpp

index 3282e43..4534ef5 100644 (file)
@@ -195,6 +195,17 @@ static bool CheckDatabaseStructure()
       return false;
    }
 
+   if (version < DB_SCHEMA_VERSION)
+   {
+      if (!UpgradeDatabase())
+      {
+         version = ReadMetadataAsInt(_T("SchemaVersion"));
+         nxlog_debug(1, _T("Local database schema version is %d and cannot be upgraded to %d"), version, DB_SCHEMA_VERSION);
+         nxlog_write(MSG_LOCAL_DB_CORRUPTED, NXLOG_ERROR, NULL);
+         return false;
+      }
+   }
+
    bool success = true;
    for(int i = 0; s_dbTables[i] != NULL; i++)
    {
@@ -244,7 +255,7 @@ bool OpenLocalDatabase()
       return false;
    }
 
-   if (!CheckDatabaseStructure() || !UpgradeDatabase())
+   if (!CheckDatabaseStructure())
    {
           g_failFlags |= FAIL_UPGRADE_DATABASE;
       DBDisconnect(s_db);