fixed collected data export/import for non-node data collection targets (issue #NX...
authorVictor Kirhenshtein <victor@netxms.org>
Thu, 5 Oct 2017 14:35:29 +0000 (17:35 +0300)
committerVictor Kirhenshtein <victor@netxms.org>
Thu, 5 Oct 2017 14:35:29 +0000 (17:35 +0300)
ChangeLog
src/server/tools/nxdbmgr/.cproject
src/server/tools/nxdbmgr/check.cpp
src/server/tools/nxdbmgr/export.cpp
src/server/tools/nxdbmgr/import.cpp
src/server/tools/nxdbmgr/nxdbmgr.h

index d6c28d0..1dfd8e2 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -18,7 +18,7 @@
 - Improved database check procedure
 - Management console:
        - Option to set root object for "Geo Map" dashboard element
-- Fixed issues: NX-1147, NX-1265, NX-1270, NX-1276, NX-1282, NX-1290, NX-1296, NX-1300, NX-1309, NX-1313, NX-1314, NX-1315, NX-1324
+- Fixed issues: NX-1147, NX-1265, NX-1270, NX-1276, NX-1282, NX-1290, NX-1296, NX-1300, NX-1309, NX-1313, NX-1314, NX-1315, NX-1324, NX-1331
 
 
 *
index c2f2f6b..c9029dc 100644 (file)
@@ -5,12 +5,12 @@
                        <storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.toolchain.gnu.base.836348019" moduleId="org.eclipse.cdt.core.settings" name="Default">
                                <externalSettings/>
                                <extensions>
+                                       <extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
                                        <extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
                                        <extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
                                        <extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
                                        <extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
                                        <extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
-                                       <extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
                                </extensions>
                        </storageModule>
                        <storageModule moduleId="cdtBuildSystem" version="4.0.0">
@@ -84,4 +84,5 @@
                        <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
                </scannerConfigBuildInfo>
        </storageModule>
+       <storageModule moduleId="org.eclipse.cdt.make.core.buildtargets"/>
 </cproject>
index 6a31050..75de35b 100644 (file)
@@ -710,7 +710,7 @@ static void CollectObjectIdentifiers(const TCHAR *className, IntegerArray<UINT32
 /**
  * Get all data collection targets
  */
-static IntegerArray<UINT32> *GetDataCollectionTargets()
+IntegerArray<UINT32> *GetDataCollectionTargets()
 {
    IntegerArray<UINT32> *list = new IntegerArray<UINT32>(128, 128);
    CollectObjectIdentifiers(_T("nodes"), list);
index 6c584c3..c941261 100644 (file)
@@ -187,7 +187,7 @@ static int GetIDataQueryCB(void *arg, int cols, char **data, char **names)
 void ExportDatabase(char *file, bool skipAudit, bool skipAlarms, bool skipEvent, bool skipSysLog, bool skipTrapLog)
 {
        sqlite3 *db;
-       char *errmsg, buffer[MAX_PATH], queryTemplate[11][MAX_DB_STRING], *data;
+       char *errmsg, queryTemplate[11][MAX_DB_STRING], *data;
        TCHAR idataTable[128];
    int rowCount, version = 0;
        DB_RESULT hResult;
@@ -212,29 +212,15 @@ void ExportDatabase(char *file, bool skipAudit, bool skipAlarms, bool skipEvent,
    }
 
        // Setup database schema
-#ifdef UNICODE
-   TCHAR tmp[MAX_PATH];
-   GetNetXMSDirectory(nxDirShare, tmp);
-#ifdef _WIN32
-   _tcslcat(tmp, _T("\\sql\\dbschema_sqlite.sql"), MAX_PATH);
-#else
-   _tcslcat(tmp, _T("/sql/dbschema_sqlite.sql"), MAX_PATH);
-#endif
-       WideCharToMultiByte(CP_ACP, WC_COMPOSITECHECK | WC_DEFAULTCHAR, tmp, MAX_PATH, buffer, MAX_PATH, NULL, NULL);
-#else
-   GetNetXMSDirectory(nxDirShare, buffer);
-#ifdef _WIN32
-   strlcat(buffer, "\\sql\\dbschema_sqlite.sql", MAX_PATH);
-#else
-   strlcat(buffer, "/sql/dbschema_sqlite.sql", MAX_PATH);
-#endif
-#endif
+   TCHAR schemaFile[MAX_PATH];
+   GetNetXMSDirectory(nxDirShare, schemaFile);
+   _tcslcat(schemaFile, FS_PATH_SEPARATOR _T("sql") FS_PATH_SEPARATOR _T("dbschema_sqlite.sql"), MAX_PATH);
 
    UINT32 size;
-       data = (char *)LoadFileA(buffer, &size);
+       data = (char *)LoadFile(schemaFile, &size);
        if (data == NULL)
        {
-               _tprintf(_T("ERROR: cannot load schema file \"%hs\"\n"), buffer);
+               _tprintf(_T("ERROR: cannot load schema file \"%s\"\n"), schemaFile);
                goto cleanup;
        }
 
@@ -296,8 +282,9 @@ void ExportDatabase(char *file, bool skipAudit, bool skipAlarms, bool skipEvent,
 
       for(i = 0; i < 10; i++)
       {
-         sprintf(buffer, "SELECT var_value FROM metadata WHERE var_name='TDataTableCreationCommand_%d'", i);
-         if (sqlite3_exec(db, buffer, GetIDataQueryCB, queryTemplate[i + 1], &errmsg) != SQLITE_OK)
+         char query[256];
+         sprintf(query, "SELECT var_value FROM metadata WHERE var_name='TDataTableCreationCommand_%d'", i);
+         if (sqlite3_exec(db, query, GetIDataQueryCB, queryTemplate[i + 1], &errmsg) != SQLITE_OK)
          {
             _tprintf(_T("ERROR: SQLite query failed (%hs)\n"), errmsg);
             sqlite3_free(errmsg);
@@ -307,14 +294,12 @@ void ExportDatabase(char *file, bool skipAudit, bool skipAlarms, bool skipEvent,
             break;
       }
 
-      hResult = SQLSelect(_T("SELECT id FROM nodes"));
-      if (hResult == NULL)
+      IntegerArray<UINT32> *targets = GetDataCollectionTargets();
+      if (targets == NULL)
          goto cleanup;
-
-      rowCount = DBGetNumRows(hResult);
-      for(i = 0; i < rowCount; i++)
+      for(i = 0; i < targets->size(); i++)
       {
-         UINT32 id = DBGetFieldLong(hResult, i, 0);
+         UINT32 id = targets->get(i);
 
          if (!g_skipDataSchemaMigration)
          {
@@ -323,10 +308,11 @@ void ExportDatabase(char *file, bool skipAudit, bool skipAlarms, bool skipEvent,
                if (queryTemplate[j][0] == 0)
                   break;
 
-               snprintf(buffer, MAX_PATH, queryTemplate[j], id, id);
-               if (sqlite3_exec(db, buffer, NULL, NULL, &errmsg) != SQLITE_OK)
+               char query[1024];
+               snprintf(query, 1024, queryTemplate[j], id, id);
+               if (sqlite3_exec(db, query, NULL, NULL, &errmsg) != SQLITE_OK)
                {
-                  _tprintf(_T("ERROR: SQLite query failed: %hs (%hs)\n"), buffer, errmsg);
+                  _tprintf(_T("ERROR: SQLite query failed: %hs (%hs)\n"), query, errmsg);
                   sqlite3_free(errmsg);
                   DBFreeResult(hResult);
                   goto cleanup;
@@ -352,7 +338,7 @@ void ExportDatabase(char *file, bool skipAudit, bool skipAlarms, bool skipEvent,
          }
       }
 
-      DBFreeResult(hResult);
+      delete targets;
        }
 
        success = TRUE;
index 2d62629..1582fa6 100644 (file)
@@ -111,37 +111,47 @@ static BOOL ImportTable(sqlite3 *db, const TCHAR *table)
 /**
  * Import data tables
  */
-static BOOL ImportDataTables(sqlite3 *db)
+static bool ImportDataTables(sqlite3 *db)
 {
-       int i, count;
-       TCHAR buffer[1024];
+   IntegerArray<UINT32> *targets = GetDataCollectionTargets();
+   if (targets == NULL)
+      return false;
 
-       DB_RESULT hResult = SQLSelect(_T("SELECT id FROM nodes"));
-       if (hResult == NULL)
-               return FALSE;
-
-       // Create and import idata_xx tables for each node in "nodes" table
-       count = DBGetNumRows(hResult);
-       for(i = 0; i < count; i++)
+       // Create and import idata_xx tables for each data collection target
+   bool success = true;
+       for(int i = 0; i < targets->size(); i++)
        {
-               DWORD id = DBGetFieldULong(hResult, i, 0);
+               UINT32 id = targets->get(i);
                if (!CreateIDataTable(id))
+               {
+                  success = false;
                        break;  // Failed to create idata_xx table
+               }
 
-               _sntprintf(buffer, 1024, _T("idata_%d"), id);
-               if (!ImportTable(db, buffer))
+               TCHAR table[64];
+               _sntprintf(table, 64, _T("idata_%d"), id);
+               if (!ImportTable(db, table))
+               {
+         success = false;
                        break;
+               }
 
       if (!CreateTDataTable(id))
+      {
+         success = false;
                        break;  // Failed to create tdata tables
+      }
 
-               _sntprintf(buffer, 1024, _T("tdata_%d"), id);
-               if (!ImportTable(db, buffer))
+               _sntprintf(table, 64, _T("tdata_%d"), id);
+               if (!ImportTable(db, table))
+               {
+         success = false;
                        break;
+               }
        }
 
-       DBFreeResult(hResult);
-       return i == count;
+       delete targets;
+       return success;
 }
 
 /**
index a322215..0760281 100644 (file)
@@ -80,6 +80,7 @@ DWORD ConfigReadULong(const TCHAR *pszVar, DWORD dwDefault);
 bool CreateConfigParam(const TCHAR *name, const TCHAR *value, bool isVisible, bool needRestart, bool forceUpdate = false);
 bool CreateConfigParam(const TCHAR *name, const TCHAR *value, const TCHAR *description, char dataType, bool isVisible, bool needRestart, bool isPublic, bool forceUpdate = false);
 
+IntegerArray<UINT32> *GetDataCollectionTargets();
 bool IsDataTableExist(const TCHAR *format, UINT32 id);
 
 BOOL CreateIDataTable(DWORD nodeId);