minor nxdbmgr refactoring
authorVictor Kirhenshtein <victor@netxms.org>
Tue, 24 Oct 2017 15:14:05 +0000 (18:14 +0300)
committerVictor Kirhenshtein <victor@netxms.org>
Tue, 24 Oct 2017 15:14:05 +0000 (18:14 +0300)
src/server/tools/nxdbmgr/check.cpp

index 603b352..be2ac91 100644 (file)
@@ -393,32 +393,32 @@ static void CheckComponents(const TCHAR *pszDisplayName, const TCHAR *pszTable)
  */
 static void CheckObjectProperties()
 {
-   DB_RESULT hResult;
-   TCHAR szQuery[1024];
-   DWORD i, dwNumRows, dwObjectId;
-
    StartStage(_T("Checking object properties"));
-   hResult = SQLSelect(_T("SELECT object_id,name,last_modified FROM object_properties"));
+   DB_RESULT hResult = SQLSelect(_T("SELECT object_id,name,last_modified FROM object_properties"));
    if (hResult != NULL)
    {
-      dwNumRows = DBGetNumRows(hResult);
-      for(i = 0; i < dwNumRows; i++)
+      int count = DBGetNumRows(hResult);
+      SetStageWorkTotal(count);
+      for(int i = 0; i < count; i++)
       {
-         dwObjectId = DBGetFieldULong(hResult, i, 0);
+         UINT32 objectId = DBGetFieldULong(hResult, i, 0);
 
          // Check last change time
          if (DBGetFieldULong(hResult, i, 2) == 0)
          {
             m_iNumErrors++;
+            TCHAR objectName[MAX_OBJECT_NAME];
             if (GetYesNoEx(_T("Object %d [%s] has invalid timestamp. Fix it?"),
-                                            dwObjectId, DBGetField(hResult, i, 1, szQuery, 1024)))
+                                               objectId, DBGetField(hResult, i, 1, objectName, MAX_OBJECT_NAME)))
             {
-               _sntprintf(szQuery, 1024, _T("UPDATE object_properties SET last_modified=") TIME_T_FMT _T(" WHERE object_id=%d"),
-                          TIME_T_FCAST(time(NULL)), (int)dwObjectId);
-               if (SQLQuery(szQuery))
+               TCHAR query[256];
+               _sntprintf(query, 256, _T("UPDATE object_properties SET last_modified=") TIME_T_FMT _T(" WHERE object_id=%d"),
+                          TIME_T_FCAST(time(NULL)), (int)objectId);
+               if (SQLQuery(query))
                   m_iNumFixes++;
             }
          }
+         UpdateStageProgress(1);
       }
       DBFreeResult(hResult);
    }