Changeset 19103 for trunk/FACT++
- Timestamp:
- 07/31/18 13:48:35 (6 years ago)
- Location:
- trunk/FACT++/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/fits2sql.cc
r19102 r19103 66 66 ("engine", var<string>("InnoDB"), "Database engine to be used when a new table is created") 67 67 ("duplicate", var<string>(""), "Specifies an assignment_list for an 'ON DUPLICATE KEY UPDATE' expression") 68 ("ignore-errors", po_switch(), "Adds the IGNORE keyword to the INSERT query (turns errors into warnings, ignores rows with errors)") 68 69 ; 69 70 … … 153 154 "with the identical primary key, e.g. --duplicate='MyPrimary=VALUES(MyPrimary)'. " 154 155 "For more details, see the MySQL manual.\n" 156 "\n" 157 "Another possibility is to add the IGNORE keyword to the INSERT query by " 158 "--ignore-errors, which essentially ignores all errors and turns them into " 159 "warnings which are printed after the query succeeded.\n" 155 160 "\n" 156 161 "For debugging purpose, or to just create or drop a table, the final insert " … … 278 283 const string duplicate = conf.Get<string>("duplicate"); 279 284 285 const bool ignore_errors = conf.Get<bool>("ignore-errors"); 286 280 287 const bool print_extensions = conf.Get<bool>("print-extensions"); 281 288 const bool print_columns = conf.Get<bool>("print-columns"); … … 312 319 { 313 320 cout << "\nTables:\n - " << boost::join(f.GetTables(), "\n - ") << '\n' << endl; 314 return 2;321 return 3; 315 322 } 316 323 … … 429 436 // Checking for database connection 430 437 438 Database connection(uri); 439 431 440 try 432 441 { 433 442 if (!force) 434 Database(uri).connected();443 connection.connected(); 435 444 } 436 445 catch (const exception &e) 437 446 { 438 447 cerr << "SQL connection failed: " << e.what() << endl; 439 return 3;448 return 4; 440 449 } 441 450 … … 463 472 // => Simple result 464 473 if (!dry_run) 465 Database(uri).query("DROP TABLE `"+table+"`").execute();474 connection.query("DROP TABLE `"+table+"`").execute(); 466 475 if (verbose>0) 467 476 cout << "Table `" << table << "` dropped." << endl; … … 472 481 cerr << "DROP TABLE `" << table << "`\n\n"; 473 482 cerr << "SQL query failed:\n" << e.what() << endl; 474 return 4;483 return 5; 475 484 } 476 485 … … 478 487 { 479 488 if (create && !dry_run) 480 Database(uri).query(query).execute();489 connection.query(query).execute(); 481 490 } 482 491 catch (const exception &e) … … 484 493 cerr << query << "\n\n"; 485 494 cerr << "SQL query failed:\n" << e.what() << endl; 486 return 5;495 return 6; 487 496 } 488 497 … … 499 508 500 509 //query = update ? "UPDATE" : "INSERT"; 501 query = "INSERT `"+table+"`\n" 510 query = "INSERT "; 511 if (ignore_errors) 512 query += "IGNORE "; 513 query += "`"+table+"`\n" 502 514 "(\n"; 503 515 … … 580 592 if (!noinsert && !dry_run) 581 593 // => Simple result 582 Database(uri).query(query).execute();594 connection.query(query).execute(); 583 595 else 584 596 cout << "Insert query skipped!" << endl; … … 592 604 cerr << query << "\n\n"; 593 605 cerr << "SQL query failed (" << query.length() << " bytes):\n" << e.what() << endl; 594 return 6;606 return 7; 595 607 } 596 608 … … 599 611 cout << count << " row(s) inserted.\n\n"; 600 612 cout << "Total execution time: " << Time().UnixTime()-start.UnixTime() << "s\n" << endl; 601 /* 613 602 614 try 603 615 { … … 613 625 614 626 cout << roww["Level"] << '[' << roww["Code"] << "]: "; 615 cout << roww["Message"] << '\n' << endl;627 cout << roww["Message"] << '\n'; 616 628 } 629 cout << endl; 617 630 618 631 } … … 621 634 cerr << "\nSHOW WARNINGS\n\n"; 622 635 cerr << "SQL query failed:\n" << e.what() << endl; 623 return 6;624 } */636 return 8; 637 } 625 638 } 626 639 -
trunk/FACT++/src/root2sql.cc
r19102 r19103 62 62 ("engine", var<string>("InnoDB"), "Database engine to be used when a new table is created") 63 63 ("duplicate", var<string>(""), "Specifies an assignment_list for an 'ON DUPLICATE KEY UPDATE' expression") 64 ("ignore-errors", po_switch(), "Adds the IGNORE keyword to the INSERT query (turns errors into warnings, ignores rows with errors)") 64 65 ; 65 66 … … 159 160 "end.\n" 160 161 "\n" 162 "Another possibility is to add the IGNORE keyword to the INSERT query by " 163 "--ignore-errors, which essentially ignores all errors and turns them into " 164 "warnings which are printed after the query succeeded.\n" 165 "\n" 161 166 "Using a higher verbosity level (-v), an overview of the written columns or all " 162 167 "processed leaves is printed depending on the verbosity level. The output looks " … … 301 306 const string duplicate = conf.Get<string>("duplicate"); 302 307 308 const bool ignore_errors = conf.Get<bool>("ignore-errors"); 309 303 310 const bool print_branches = conf.Get<bool>("print-branches"); 304 311 const bool print_leaves = conf.Get<bool>("print-leaves"); … … 452 459 // Checking for database connection 453 460 461 Database connection(uri); 462 454 463 try 455 464 { 456 465 if (!force) 457 Database(uri).connected();466 connection.connected(); 458 467 } 459 468 catch (const exception &e) … … 485 494 // => Simple result 486 495 if (!dry_run) 487 Database(uri).query("DROP TABLE `"+table+"`").execute();496 connection.query("DROP TABLE `"+table+"`").execute(); 488 497 if (verbose>0) 489 498 cout << "Table `" << table << "` dropped." << endl; … … 500 509 { 501 510 if (create && !dry_run) 502 Database(uri).query(query).execute();511 connection.query(query).execute(); 503 512 } 504 513 catch (const exception &e) … … 521 530 522 531 //query = update ? "UPDATE" : "INSERT"; 523 query = "INSERT `"+table+"`\n" 532 query = "INSERT "; 533 if (ignore_errors) 534 query += "IGNORE "; 535 query += "`"+table+"`\n" 524 536 "(\n"; 525 537 … … 589 601 if (!noinsert && !dry_run) 590 602 // => Simple result 591 Database(uri).query(query).execute();603 connection.query(query).execute(); 592 604 else 593 605 cout << "Insert query skipped!" << endl; … … 608 620 cout << count << " row(s) inserted.\n\n"; 609 621 cout << "Total execution time: " << Time().UnixTime()-start.UnixTime() << "s\n" << endl; 610 /* 622 611 623 try 612 624 { … … 622 634 623 635 cout << roww["Level"] << '[' << roww["Code"] << "]: "; 624 cout << roww["Message"] << '\n' << endl;636 cout << roww["Message"] << '\n'; 625 637 } 638 cout << endl; 626 639 627 640 } … … 630 643 cerr << "\nSHOW WARNINGS\n\n"; 631 644 cerr << "SQL query failed:\n" << e.what() << endl; 632 return 6; 633 }*/ 634 } 635 645 return 7; 646 } 647 } 636 648 637 649 return 0;
Note:
See TracChangeset
for help on using the changeset viewer.