Changeset 19063
- Timestamp:
- 07/18/18 16:54:12 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/root2sql.cc
r19062 r19063 24 24 std::istream &operator>>(std::istream &in, Map &m) 25 25 { 26 string txt(istreambuf_iterator<char>(in), {}); 26 const istreambuf_iterator<char> eos; 27 string txt(istreambuf_iterator<char>(in), eos); 27 28 28 29 const boost::regex expr("((.*)[^\\\\])/(.*)"); … … 42 43 po::options_description control("Root to SQL"); 43 44 control.add_options() 44 ("uri,u", var<string>()->required(), "Database link as in\n\tuser:password@server[:port]/database.") 45 ("uri,u", var<string>() 46 #if BOOST_VERSION >= 104200 47 ->required() 48 #endif 49 , "Database link as in\n\tuser:password@server[:port]/database.") 45 50 ("file", var<string>(""), "The root file to read from") 51 ("force", po_switch(), "Force processing even if there is no database connection") 46 52 ("create", po_switch(), "Create the database if not existing") 47 53 ("drop", po_switch(), "Drop the table (implies create)") … … 101 107 "once. They are applied in sequence. A single match does not stop the sequence.\n" 102 108 "\n" 103 "Sometimes it might also be convenient to skip a leaf. T is can be done with "109 "Sometimes it might also be convenient to skip a leaf. This can be done with " 104 110 "the --ignore resource. If the given regular expresion yield a match, the " 105 111 "leaf will be ignored. Note that the regular expression work on the raw-name " … … 139 145 "end.\n" 140 146 "\n" 141 "Using a higher verbosity level , an overview of the written columns or all "147 "Using a higher verbosity level (-v), an overview of the written columns or all " 142 148 "processed leaves is printed depending on the verbosity level. The output looks " 143 149 "like the following\n" … … 265 271 const int64_t max = conf.Get<int64_t>("max"); 266 272 273 const bool force = conf.Get<bool>("force"); 267 274 const bool drop = conf.Get<bool>("drop"); 268 275 const bool create = conf.Get<bool>("create") || drop; … … 354 361 355 362 bool found = false; 356 for ( const auto &b: _ignore)363 for (auto b=_ignore.cbegin(); b!=_ignore.cend(); b++) 357 364 { 358 if (boost::regex_match(name, boost::regex( b)))365 if (boost::regex_match(name, boost::regex(*b))) 359 366 { 360 367 found = true; … … 380 387 cout << '\n' << o->GetName() << " [" << L->GetTypeName() << "]"; 381 388 382 for ( const auto &m: mymap)383 name = boost::regex_replace(name, boost::regex(m .first), m.second);389 for (auto m=mymap.cbegin(); m!=mymap.cend(); m++) 390 name = boost::regex_replace(name, boost::regex(m->first), m->second); 384 391 385 392 if (verbose>1) … … 388 395 string sqltype = it->second.second; 389 396 390 for ( const auto &m: sqltypes)391 if (m .first==name)392 sqltype = m .second;397 for (auto m=sqltypes.cbegin(); m!=sqltypes.cend(); m++) 398 if (m->first==name) 399 sqltype = m->second; 393 400 394 401 query += ",\n `"+name+"` "+sqltype+" NOT NULL COMMENT '"+o->GetName()+"'"; … … 408 415 // Setiing up branch status (must be after all SetBranchAddress) 409 416 T->SetBranchStatus("*", 0); 410 for ( const auto &c: vec)411 T->SetBranchStatus(c .branch.c_str(), 1);417 for (auto c=vec.cbegin(); c!=vec.cend(); c++) 418 T->SetBranchStatus(c->branch.c_str(), 1); 412 419 413 420 if (has_datatype) … … 416 423 if (verbose>0) 417 424 cout << "Rows with DataType.fVal!=1 will be skipped." << endl; 425 } 426 427 // ------------------------------------------------------------------------- 428 429 try 430 { 431 if (!force) 432 Database(uri).connected(); 433 } 434 catch (const exception &e) 435 { 436 cerr << "SQL connection failed: " << e.what() << endl; 437 return 3; 418 438 } 419 439 … … 448 468 cerr << "DROP TABLE `" << table << "`\n\n"; 449 469 cerr << "SQL query failed:\n" << e.what() << endl; 450 return 3;470 return 4; 451 471 } 452 472 … … 460 480 cerr << query << "\n\n"; 461 481 cerr << "SQL query failed:\n" << e.what() << endl; 462 return 4;482 return 5; 463 483 } 464 484 … … 479 499 " `Night`"; 480 500 481 for ( const auto &c: vec)482 query += ",\n `"+c .column+"`";501 for (auto c=vec.cbegin(); c!=vec.cend(); c++) 502 query += ",\n `"+c->column+"`"; 483 503 484 504 query += … … 496 516 497 517 query += "(\n 0"; 498 for (const auto &c: vec) 499 query += ",\n "+c.fmt()+" /* "+c.column+" -> "+c.branch+" */"; 518 for (auto c=vec.cbegin(); c!=vec.cend(); c++) 519 { 520 query += ",\n "+c->fmt(); 521 if (print_insert) 522 query += " /* "+c->column+" -> "+c->branch+" */"; 523 } 500 524 query += "\n)"; // ON DUPLICATE KEY UPDATE\n"; 501 525 … … 528 552 cerr << query << "\n\n"; 529 553 cerr << "SQL query failed:\n" << e.what() << endl; 530 return 5;554 return 6; 531 555 } 532 556
Note:
See TracChangeset
for help on using the changeset viewer.