Index: /trunk/FACT++/src/rootifysql.cc
===================================================================
--- /trunk/FACT++/src/rootifysql.cc	(revision 19137)
+++ /trunk/FACT++/src/rootifysql.cc	(revision 19138)
@@ -354,4 +354,96 @@
 }
 
+int finish(Database &connection, const uint16_t &verbose, const bool &profiling, const bool &print_connection)
+{
+    if (verbose>0)
+    {
+        try
+        {
+            const auto resw =
+                connection.query("SHOW WARNINGS").store();
+
+            if (resw.num_rows()>0)
+                cout << "\n" << resw.num_rows() << " Warning(s) issued:\n\n";
+
+            for (size_t i=0; i<resw.num_rows(); i++)
+            {
+                const mysqlpp::Row &roww = resw[i];
+
+                cout << roww["Level"] << '[' << roww["Code"] << "]: ";
+                cout << roww["Message"] << '\n';
+            }
+            cout << endl;
+
+        }
+        catch (const exception &e)
+        {
+            cerr << "\nSHOW WARNINGS\n\n";
+            cerr << "SQL query failed:\n" << e.what() << endl;
+            return 6;
+        }
+    }
+
+    if (profiling)
+    {
+        try
+        {
+            const auto N =
+                connection.query("SHOW PROFILES").store().num_rows();
+
+            const auto resp =
+                connection.query("SHOW PROFILE ALL FOR QUERY "+to_string(verbose?N-1:N)).store();
+
+            cout << '\n';
+            cout << left;
+            cout << setw(26) << "Status"     << ' ';
+            cout << right;
+            cout << setw(11) << "Duration"   << ' ';
+            cout << setw(11) << "CPU User"   << ' ';
+            cout << setw(11) << "CPU System" << '\n';
+            cout << "--------------------------------------------------------------\n";
+            for (size_t i=0; i<resp.num_rows(); i++)
+            {
+                const mysqlpp::Row &rowp = resp[i];
+
+                cout << left;
+                cout << setw(26) << rowp["Status"] << ' ';
+                cout << right;
+                cout << setw(11) << rowp["Duration"] << ' ';
+                cout << setw(11) << rowp["CPU_user"] << ' ';
+                cout << setw(11) << rowp["CPU_system"] << '\n';
+            }
+            cout << "--------------------------------------------------------------\n";
+            cout << endl;
+        }
+        catch (const exception &e)
+        {
+            cerr << "\nSHOW PROFILE ALL\n\n";
+            cerr << "SQL query failed:\n" << e.what() << '\n' <<endl;
+            return 11;
+        }
+    }
+
+    if (print_connection)
+    {
+        try
+        {
+            // Exchange _send and _received as it is the view of the server
+            const auto &res1 = connection.query("SHOW STATUS LIKE 'Bytes_%'").store();
+            cout << left << setw(16) << res1[1]["Variable_name"] << ' ' << Tools::Scientific(res1[0]["Value"]) << endl;
+            cout << left << setw(16) << res1[0]["Variable_name"] << ' ' << Tools::Scientific(res1[1]["Value"]) << endl;
+            cout << endl;
+        }
+        catch (const exception &e)
+        {
+            cerr << "\nSHOW STATUS LIKE 'Bytes_%'\n\n";
+            cerr << "SQL query failed:\n" << e.what() << endl;
+            return 6;
+        }
+    }
+
+    return 0;
+
+}
+
 int main(int argc, const char* argv[])
 {
@@ -674,4 +766,5 @@
     {
         cerr << "Empty set returned... nothing to write." << endl;
+        finish(connection, verbose, profiling, print_connection);
         return 10;
     }
@@ -874,89 +967,6 @@
         cout << "(" << Tools::Fractional(sec/count) << "s/row)\n";
         cout << "--------------------------------------------------------------" << endl;
-
-        try
-        {
-            const auto resw =
-                connection.query("SHOW WARNINGS").store();
-
-            if (resw.num_rows()>0)
-                cout << "\n" << resw.num_rows() << " Warning(s) issued:\n\n";
-
-            for (size_t i=0; i<resw.num_rows(); i++)
-            {
-                const mysqlpp::Row &roww = resw[i];
-
-                cout << roww["Level"] << '[' << roww["Code"] << "]: ";
-                cout << roww["Message"] << '\n';
-            }
-            cout << endl;
-
-        }
-        catch (const exception &e)
-        {
-            cerr << "\nSHOW WARNINGS\n\n";
-            cerr << "SQL query failed:\n" << e.what() << endl;
-            return 6;
-        }
-    }
-
-    if (profiling)
-    {
-        try
-        {
-            const auto N =
-                connection.query("SHOW PROFILES").store().num_rows();
-
-            const auto resp =
-                connection.query("SHOW PROFILE ALL FOR QUERY "+to_string(verbose?N-1:N)).store();
-
-            cout << '\n';
-            cout << left;
-            cout << setw(26) << "Status"     << ' ';
-            cout << right;
-            cout << setw(11) << "Duration"   << ' ';
-            cout << setw(11) << "CPU User"   << ' ';
-            cout << setw(11) << "CPU System" << '\n';
-            cout << "--------------------------------------------------------------\n";
-            for (size_t i=0; i<resp.num_rows(); i++)
-            {
-                const mysqlpp::Row &rowp = resp[i];
-
-                cout << left;
-                cout << setw(26) << rowp["Status"] << ' ';
-                cout << right;
-                cout << setw(11) << rowp["Duration"] << ' ';
-                cout << setw(11) << rowp["CPU_user"] << ' ';
-                cout << setw(11) << rowp["CPU_system"] << '\n';
-            }
-            cout << "--------------------------------------------------------------\n";
-            cout << endl;
-        }
-        catch (const exception &e)
-        {
-            cerr << "\nSHOW PROFILE ALL\n\n";
-            cerr << "SQL query failed:\n" << e.what() << '\n' <<endl;
-            return 11;
-        }
-    }
-
-    if (print_connection)
-    {
-        try
-        {
-            // Exchange _send and _received as it is the view of the server
-            const auto &res1 = connection.query("SHOW STATUS LIKE 'Bytes_%'").store();
-            cout << left << setw(16) << res1[1]["Variable_name"] << ' ' << Tools::Scientific(res1[0]["Value"]) << endl;
-            cout << left << setw(16) << res1[0]["Variable_name"] << ' ' << Tools::Scientific(res1[1]["Value"]) << endl;
-            cout << endl;
-        }
-        catch (const exception &e)
-        {
-            cerr << "\nSHOW STATUS LIKE 'Bytes_%'\n\n";
-            cerr << "SQL query failed:\n" << e.what() << endl;
-            return 6;
-        }
-    }
-
-    return 0;
+    }
+
+    return finish(connection, verbose, profiling, print_connection);
 }
