- Timestamp:
- 07/21/18 15:41:30 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/root2sql.cc
r19063 r19072 60 60 ("first", var<int64_t>(int64_t(0)), "First event to start with (default: 0), mainly for test purpose") 61 61 ("max", var<int64_t>(int64_t(0)), "Maximum number of events to process (0: all), mainly for test purpose") 62 ("engine", var<string>("MyISAM"), "Database engine to be used when a new table is created") 63 ; 64 65 po::options_description debug("Debug options"); 66 debug.add_options() 62 67 ("no-insert", po_switch(), "Does not insert any data into the table") 63 (" engine", var<string>("MyISAM"), "Database engine to be used when a new table is created")68 ("dry-run", po_switch(), "Skip any query which changes the databse (might result in consecutive failures)") 64 69 ("print-branches", po_switch(), "Print the branches found in the tree") 65 70 ("print-leaves", po_switch(), "Print the leaves found in the tree (this is what is processed)") … … 73 78 74 79 conf.AddOptions(control); 80 conf.AddOptions(debug); 75 81 conf.SetArgumentPositions(p); 76 82 } … … 223 229 switch (type) 224 230 { 225 case kFloat: str << setprecision(8) << *reinterpret_cast<Float_t*>(ptr); break;231 case kFloat: str << setprecision(8) << *reinterpret_cast<Float_t*>(ptr); break; 226 232 case kDouble: str << setprecision(16) << *reinterpret_cast<Double_t*>(ptr); break; 227 233 case kInt16: str << *reinterpret_cast<Short_t*>(ptr); break; … … 235 241 } 236 242 243 if (str.str()=="nan" || str.str()=="-nan" || str.str()=="inf" || str.str()=="-inf") 244 return "NULL"; 245 237 246 return str.str(); 238 247 } … … 275 284 const bool create = conf.Get<bool>("create") || drop; 276 285 const bool noinsert = conf.Get<bool>("no-insert"); 286 const bool dry_run = conf.Get<bool>("dry-run"); 277 287 278 288 const string engine = conf.Get<string>("engine"); … … 343 353 "CREATE TABLE IF NOT EXISTS `"+table+"`\n" 344 354 "(\n" 345 " `Night` SMALLINT UNSIGNED NOT NULL";346 355 347 356 vector<Container> vec; … … 399 408 sqltype = m->second; 400 409 401 query += ",\n `"+name+"` "+sqltype+" NOT NULL COMMENT '"+o->GetName()+"'"; 410 if (!vec.empty()) 411 query += ",\n"; 412 query += " `"+name+"` "+sqltype+" NOT NULL COMMENT '"+o->GetName()+"'"; 402 413 403 414 vec.emplace_back(o->GetName(), name, it->second.first); … … 426 437 427 438 // ------------------------------------------------------------------------- 439 // Checking for database connection 428 440 429 441 try … … 459 471 { 460 472 // => Simple result 461 Database(uri).query("DROP TABLE `"+table+"`").execute(); 473 if (!dry_run) 474 Database(uri).query("DROP TABLE `"+table+"`").execute(); 462 475 if (verbose>0) 463 476 cout << "Table `" << table << "` dropped." << endl; … … 473 486 try 474 487 { 475 if (create )488 if (create && !dry_run) 476 489 Database(uri).query(query).execute(); 477 490 } … … 515 528 continue; 516 529 517 query += "(\n 0"; 530 if (count>0) 531 query += ",\n"; 532 533 query += "(\n"; 534 518 535 for (auto c=vec.cbegin(); c!=vec.cend(); c++) 519 536 { 520 query += ",\n "+c->fmt(); 537 if (c!=vec.cbegin()) 538 query += ",\n"; 539 540 query += " "+c->fmt(); 541 521 542 if (print_insert) 522 543 query += " /* "+c->column+" -> "+c->branch+" */"; … … 524 545 query += "\n)"; // ON DUPLICATE KEY UPDATE\n"; 525 546 526 if (j!=num-1)527 query += ",\n";528 529 547 count ++; 530 548 } 531 549 532 550 if (verbose>0) 533 cout << count << " out of " << num << " row sread from file [N=" << first << ".." << num-1 << "]." << endl;551 cout << count << " out of " << num << " row(s) read from file [N=" << first << ".." << num-1 << "]." << endl; 534 552 535 553 // ------------------------------------------------------------------------- … … 540 558 try 541 559 { 542 if (!noinsert )560 if (!noinsert && !dry_run) 543 561 // => Simple result 544 562 Database(uri).query(query).execute(); 545 563 else 546 564 cout << "Insert query skipped!" << endl; 565 547 566 if (print_insert) 548 567 cout << query << endl; … … 557 576 if (verbose>0) 558 577 { 559 cout << count << " row sinserted.\n\n";578 cout << count << " row(s) inserted.\n\n"; 560 579 cout << "Total execution time: " << Time().UnixTime()-start.UnixTime() << "s\n" << endl; 561 580 }
Note:
See TracChangeset
for help on using the changeset viewer.