]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/qt-console/restore/restoretree.cpp
Clean up a bit. Randomize the name of the table.
[bacula/bacula] / bacula / src / qt-console / restore / restoretree.cpp
index 6f953e95f0acd648f14225136e3e3598f25867d6..4cbaa016947fe33b4abe2f3637a7b32c146e780b 100644 (file)
@@ -148,11 +148,12 @@ void restoreTree::populateDirectoryTree()
    }
 
    QString cmd =
-      "SELECT DISTINCT Path.Path"
+      "SELECT DISTINCT Path.Path AS Path"
       " FROM Path"
       " LEFT OUTER JOIN File ON (File.PathId=Path.PathId)"
       " LEFT OUTER JOIN Job ON (File.JobId=Job.JobId)"
-      " WHERE Job.Jobid IN (" + m_jobQuery + ")";
+      " WHERE Job.Jobid IN (" + m_jobQuery + ")"
+      " ORDER BY Path";
    if (mainWin->m_sqlDebug) {
       Pmsg1(000, "Query cmd : %s\n", cmd.toUtf8().data());
    }
@@ -1389,26 +1390,18 @@ void restoreTree::testButtonPushed()
       /* did not succeed in getting an iterator to work as expected on versionFilesMulti so use doneKeys */
       if (doneKeys.value(fversion, 0) == 0) {
          if (tempTable == "") {
-            tempTable = "restoretest" + QString("%1").arg(fversion);
-            //if (mainWin->m_sqlDebug)
+            QSettings settings("www.bacula.org", "bat");
+            settings.beginGroup("Restore");
+            int counter = settings.value("Counter", 1).toInt();
+            settings.setValue("Counter", counter+1);
+            settings.endGroup();
+            tempTable = "restore_" + QString("%1").arg(qrand()) + "_" + QString("%1").arg(counter);
             QString sqlcmd = "CREATE TEMPORARY TABLE " + tempTable + " (JobId INTEGER, FileIndex INTEGER)";
+            if (mainWin->m_sqlDebug)
+               Pmsg1(000, "Query cmd : %s ;\n", sqlcmd.toUtf8().data());
             QStringList results;
-            Pmsg1(000, "Query cmd : %s ;\n", sqlcmd.toUtf8().data());
-            /*if (m_console->sql_cmd(sqlcmd, results)) {
-               QStringList fieldlist;
-               int row = 0;
-               foreach (QString resultline, results) {
-                  int column = 0;
-                  fieldlist = resultline.split("\t");
-                  foreach (QString field, fieldlist) {
-                     if (column == 0) {
-                        Pmsg1(000, "Returned from CREATE TABLE command %s\n", field.toUtf8().data());
-                     }
-                     column++;
-                  }
-                  row++;
-               }
-            }*/
+            if (!m_console->sql_cmd(sqlcmd, results))
+               Pmsg1(000, "CREATE TABLE FAILED!!!! %s\n", sqlcmd.toUtf8().data());
          }
 
          if (mainWin->m_rtRestore2Debug) Pmsg1(000, "Version->%i\n", fversion);
@@ -1417,27 +1410,12 @@ void restoreTree::testButtonPushed()
          foreach(QString ffullPath, fullPathList) {
             int fileIndex = fileIndexHash.value(ffullPath);
             if (mainWin->m_rtRestore2Debug) Pmsg2(000, "  file->%s id %i\n", ffullPath.toUtf8().data(), fileIndex);
-            //cmd += " file=\"" + ffullPath + "\"";
             QString sqlcmd = "INSERT INTO " + tempTable + " (JobId, FileIndex) VALUES (" + QString("%1").arg(fversion) + ", " + QString("%1").arg(fileIndex) + ")";
+            if (mainWin->m_sqlDebug)
+               Pmsg1(000, "Query cmd : %s ;\n", sqlcmd.toUtf8().data());
             QStringList results;
-//            Pmsg1(000, "Query cmd : %s ;\n", sqlcmd.toUtf8().data());
-            /* use printf for the moment to make pasting into psql easier. */
-            printf("%s ;\n", sqlcmd.toUtf8().data());
-            /*if (m_console->sql_cmd(sqlcmd, results)) {
-               QStringList fieldlist;
-               int row = 0;
-               foreach (QString resultline, results) {
-                  int column = 0;
-                  fieldlist = resultline.split("\t");
-                  foreach (QString field, fieldlist) {
-                     if (column == 0) {
-                        Pmsg1(000, "Returned from INSERT INTO command %s\n", field.toUtf8().data());
-                     }
-                     column++;
-                  }
-                  row++;
-               }
-            }*/
+            if (!m_console->sql_cmd(sqlcmd, results))
+               Pmsg1(000, "INSERT INTO FAILED!!!! %s\n", sqlcmd.toUtf8().data());
          } /* foreach fullPathList */
          doneKeys.insert(fversion,1);
          jobList.append(fversion);
@@ -1458,7 +1436,7 @@ void restoreTree::testButtonPushed()
              " file=\"?" + tempTable + "\" yes";
       if (mainWin->m_commandDebug)
          Pmsg1(000, "preRestore command \'%s\'\n", cmd.toUtf8().data());
-      //consoleCommand(cmd);
+      consoleCommand(cmd);
       mainWin->resetFocus();
    }
 }