Index: /trunk/FACT++/src/root2sql.cc
===================================================================
--- /trunk/FACT++/src/root2sql.cc	(revision 19071)
+++ /trunk/FACT++/src/root2sql.cc	(revision 19072)
@@ -60,6 +60,11 @@
         ("first",          var<int64_t>(int64_t(0)),  "First event to start with (default: 0), mainly for test purpose")
         ("max",            var<int64_t>(int64_t(0)),  "Maximum number of events to process (0: all), mainly for test purpose")
+        ("engine",         var<string>("MyISAM"),     "Database engine to be used when a new table is created")
+        ;
+
+    po::options_description debug("Debug options");
+    debug.add_options()
         ("no-insert",      po_switch(),               "Does not insert any data into the table")
-        ("engine",         var<string>("MyISAM"),     "Database engine to be used when a new table is created")
+        ("dry-run",        po_switch(),               "Skip any query which changes the databse (might result in consecutive failures)")
         ("print-branches", po_switch(),               "Print the branches found in the tree")
         ("print-leaves",   po_switch(),               "Print the leaves found in the tree (this is what is processed)")
@@ -73,4 +78,5 @@
 
     conf.AddOptions(control);
+    conf.AddOptions(debug);
     conf.SetArgumentPositions(p);
 }
@@ -223,5 +229,5 @@
         switch (type)
         {
-        case kFloat:   str << setprecision(8) << *reinterpret_cast<Float_t*>(ptr); break;
+        case kFloat:   str << setprecision(8) << *reinterpret_cast<Float_t*>(ptr);  break;
         case kDouble:  str << setprecision(16) << *reinterpret_cast<Double_t*>(ptr); break;
         case kInt16:   str << *reinterpret_cast<Short_t*>(ptr); break;
@@ -235,4 +241,7 @@
         }
 
+        if (str.str()=="nan" || str.str()=="-nan" || str.str()=="inf" || str.str()=="-inf")
+            return "NULL";
+
         return str.str();
     }
@@ -275,4 +284,5 @@
     const bool create            = conf.Get<bool>("create") || drop;
     const bool noinsert          = conf.Get<bool>("no-insert");
+    const bool dry_run           = conf.Get<bool>("dry-run");
 
     const string engine          = conf.Get<string>("engine");
@@ -343,5 +353,4 @@
         "CREATE TABLE IF NOT EXISTS `"+table+"`\n"
         "(\n"
-        "   `Night` SMALLINT UNSIGNED NOT NULL";
 
     vector<Container> vec;
@@ -399,5 +408,7 @@
                 sqltype = m->second;
 
-        query += ",\n   `"+name+"` "+sqltype+" NOT NULL COMMENT '"+o->GetName()+"'";
+        if (!vec.empty())
+            query += ",\n";
+        query += "   `"+name+"` "+sqltype+" NOT NULL COMMENT '"+o->GetName()+"'";
 
         vec.emplace_back(o->GetName(), name, it->second.first);
@@ -426,4 +437,5 @@
 
     // -------------------------------------------------------------------------
+    // Checking for database connection
 
     try
@@ -459,5 +471,6 @@
         {
             // => Simple result
-            Database(uri).query("DROP TABLE `"+table+"`").execute();
+            if (!dry_run)
+                Database(uri).query("DROP TABLE `"+table+"`").execute();
             if (verbose>0)
                 cout << "Table `" << table << "` dropped." << endl;
@@ -473,5 +486,5 @@
     try
     {
-        if (create)
+        if (create && !dry_run)
             Database(uri).query(query).execute();
     }
@@ -515,8 +528,16 @@
             continue;
 
-        query += "(\n   0";
+        if (count>0)
+            query += ",\n";
+
+        query += "(\n";
+
         for (auto c=vec.cbegin(); c!=vec.cend(); c++)
         {
-            query += ",\n   "+c->fmt();
+            if (c!=vec.cbegin())
+                query += ",\n";
+
+            query += "   "+c->fmt();
+
             if (print_insert)
                 query += " /* "+c->column+" -> "+c->branch+" */";
@@ -524,12 +545,9 @@
         query += "\n)";  // ON DUPLICATE KEY UPDATE\n";
 
-        if (j!=num-1)
-            query += ",\n";
-
         count ++;
     }
 
     if (verbose>0)
-        cout << count << " out of " << num << " rows read from file [N=" << first << ".." << num-1 << "]." << endl;
+        cout << count << " out of " << num << " row(s) read from file [N=" << first << ".." << num-1 << "]." << endl;
 
     // -------------------------------------------------------------------------
@@ -540,9 +558,10 @@
     try
     {
-        if (!noinsert)
+        if (!noinsert && !dry_run)
             // => Simple result
             Database(uri).query(query).execute();
         else
             cout << "Insert query skipped!" << endl;
+
         if (print_insert)
             cout << query << endl;
@@ -557,5 +576,5 @@
     if (verbose>0)
     {
-        cout << count << " rows inserted.\n\n";
+        cout << count << " row(s) inserted.\n\n";
         cout << "Total execution time: " << Time().UnixTime()-start.UnixTime() << "s\n" << endl;
     }
