Changeset 19150 for trunk/FACT++/src
- Timestamp:
- 08/11/18 14:46:15 (6 years ago)
- Location:
- trunk/FACT++/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/fits2sql.cc
r19148 r19150 67 67 ("ignore-errors", po_switch(), "Adds the IGNORE keyword to the INSERT query (turns errors into warnings, ignores rows with errors)") 68 68 ("const.*", var<string>(), "Insert a constant number into the given column (--const.mycolumn=5). A special case is `/..../N/`") 69 ("delete", po_switch(), "Delete all entries first which fit all constant columns defined by --const") 69 70 ; 70 71 … … 78 79 ("print-insert", po_switch(), "Print the INSERT query (note that it contains all data)") 79 80 ("print-create", po_switch(), "Print the CREATE query") 81 ("print-delete", po_switch(), "Print the DELETE query") 80 82 ("verbose,v", var<uint16_t>(1), "Verbosity (0: quiet, 1: default, 2: more, 3, ...)") 81 83 ; … … 183 185 "regular expression is applied to the filename and N specifies the N-th " 184 186 "sub-sequence which matches. To debug what matches, verbosity can be set to 3.\n" 187 "\n" 188 "Usually the previously defined constant values are helpful to create an index " 189 "which relates unambiguously the inserted data to the file. It might be useful " 190 "to delete all data which belongs to this particular file before new data is " 191 "entered. This can be achieved with the `--delete` directive. It deletes all " 192 "data from the table before inserting new data which fulfills the condition " 193 "defined by the `--const` directives.\n" 185 194 "\n" 186 195 "If a query failed, the query is printed to stderr together with the error message. " … … 309 318 const bool noinsert = conf.Get<bool>("no-insert"); 310 319 const bool dry_run = conf.Get<bool>("dry-run"); 320 const bool run_delete = conf.Get<bool>("delete"); 311 321 312 322 const string engine = conf.Get<string>("engine"); … … 320 330 const bool print_create = conf.Get<bool>("print-create"); 321 331 const bool print_insert = conf.Get<bool>("print-insert"); 332 const bool print_delete = conf.Get<bool>("print-delete"); 322 333 323 334 const vector<Map> mymap = conf.Vec<Map>("map"); … … 394 405 const auto fixed = conf.GetWildcardOptions("const.*"); 395 406 407 string rmquery = "DELETE FROM `"+table+"` WHERE 1"; 396 408 for (auto it=fixed.cbegin(); it!=fixed.cend(); it++) 397 409 { … … 431 443 432 444 vec.emplace_back(name, val); 445 rmquery += " AND `"+name+"`="+val; 433 446 } 434 447 … … 492 505 query += " `"+name; 493 506 if (N>1) 494 query += "["+to_string( i)+"]";507 query += "["+to_string((long long int)i)+"]"; 495 508 query += "` "+sqltype; 496 509 if (col.type=='A') 497 query += '('+to_string( col.num)+')';510 query += '('+to_string((long long int)col.num)+')'; 498 511 query += " NOT NULL COMMENT '"+ic->first; 499 512 if (!col.unit.empty()) … … 619 632 cout << "Table `" << table << "` created." << endl; 620 633 634 635 try 636 { 637 if (run_delete && !fixed.empty() && !drop && !dry_run) 638 { 639 const mysqlpp::SimpleResult res = 640 connection.query(rmquery).execute(); 641 642 if (verbose>0) 643 cout << res.rows() << " row(s) deleted.\n" << endl; 644 } 645 } 646 catch (const exception &e) 647 { 648 cerr << rmquery << "\n\n"; 649 cerr << "SQL query failed: " << e.what() << endl; 650 return 7; 651 } 652 653 if (print_delete) 654 cout << rmquery << endl; 655 621 656 // ------------------------------------------------------------------------- 622 657 … … 642 677 query += " `"+c->column+"`"; 643 678 else 644 query += " `"+c->column+"["+to_string( i)+"]`";679 query += " `"+c->column+"["+to_string((long long int)i)+"]`"; 645 680 646 681 if (N>1 && i!=N-1) -
trunk/FACT++/src/root2sql.cc
r19149 r19150 70 70 ("ignore-errors", po_switch(), "Adds the IGNORE keyword to the INSERT query (turns errors into warnings, ignores rows with errors)") 71 71 ("const.*", var<string>(), "Insert a constant number into the given column (--const.mycolumn=5). A special case is `/..../N/`") 72 ("delete", po_switch(), "Delete all entries first which fit all constant columns defined by --const") 72 73 ; 73 74 … … 81 82 ("print-insert", po_switch(), "Print the INSERT query (note that it contains all data)") 82 83 ("print-create", po_switch(), "Print the CREATE query") 84 ("print-delete", po_switch(), "Print the DELETE query") 83 85 ("verbose,v", var<uint16_t>(1), "Verbosity (0: quiet, 1: default, 2: more, 3, ...)") 84 86 ; … … 190 192 "regular expression is applied to the filename and N specifies the N-th " 191 193 "sub-sequence which matches. To debug what matches, verbosity can be set to 3.\n" 194 "\n" 195 "Usually the previously defined constant values are helpful to create an index " 196 "which relates unambiguously the inserted data to the file. It might be useful " 197 "to delete all data which belongs to this particular file before new data is " 198 "entered. This can be achieved with the `--delete` directive. It deletes all " 199 "data from the table before inserting new data which fulfills the condition " 200 "defined by the `--const` directives.\n" 192 201 "\n" 193 202 "If a query failed, the query is printed to stderr together with the error message. " … … 338 347 const bool noinsert = conf.Get<bool>("no-insert"); 339 348 const bool dry_run = conf.Get<bool>("dry-run"); 349 const bool run_delete = conf.Get<bool>("delete"); 340 350 341 351 const string engine = conf.Get<string>("engine"); … … 351 361 const bool print_create = conf.Get<bool>("print-create"); 352 362 const bool print_insert = conf.Get<bool>("print-insert"); 363 const bool print_delete = conf.Get<bool>("print-delete"); 353 364 354 365 const vector<Map> mymap = conf.Vec<Map>("map"); … … 417 428 const auto fixed = conf.GetWildcardOptions("const.*"); 418 429 430 string rmquery = "DELETE FROM `"+table+"` WHERE 1"; 419 431 for (auto it=fixed.cbegin(); it!=fixed.cend(); it++) 420 432 { … … 454 466 455 467 vec.emplace_back(name, val); 468 rmquery += " AND `"+name+"`="+val; 456 469 } 457 470 … … 473 486 continue; 474 487 } 488 475 489 476 490 string name = o->GetName(); … … 523 537 query += " `"+name; 524 538 if (N>1) 525 query += "["+to_string( i)+"]";539 query += "["+to_string((long long int)i)+"]"; 526 540 query += "` "+sqltype+" NOT NULL COMMENT '"+o->GetTitle()+"'"; 527 541 if (N>1 && i!=N-1) … … 654 668 cout << "Table `" << table << "` created." << endl; 655 669 670 671 try 672 { 673 if (run_delete && !fixed.empty() && !drop && !dry_run) 674 { 675 const mysqlpp::SimpleResult res = 676 connection.query(rmquery).execute(); 677 678 if (verbose>0) 679 cout << res.rows() << " row(s) deleted.\n" << endl; 680 } 681 } 682 catch (const exception &e) 683 { 684 cerr << rmquery << "\n\n"; 685 cerr << "SQL query failed: " << e.what() << endl; 686 return 7; 687 } 688 689 if (print_delete) 690 cout << rmquery << endl; 691 692 656 693 // ------------------------------------------------------------------------- 657 694 … … 677 714 query += " `"+c->column+"`"; 678 715 else 679 query += " `"+c->column+"["+to_string( i)+"]`";716 query += " `"+c->column+"["+to_string((long long int)i)+"]`"; 680 717 681 718 if (N>1 && i!=N-1)
Note:
See TracChangeset
for help on using the changeset viewer.