Changeset 19235
- Timestamp:
- 10/14/18 16:04:25 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/rootifysql.cc
r19205 r19235 28 28 ("ignore-null,i", po_switch(), "Do not skip rows containing any NULL field") 29 29 ("display,d", po_switch(), "Displays contents on the screen (most usefull in combination with mysql statements as SHOW or EXPLAIN)") 30 ("write,w", var<string>(""), "Write output to an ascii file")31 ("delimiter", var<string>(), "The delimiter used if contents are displayed with --display (default=\\t)")32 30 ("explain", po_switch(), "Requests an EXPLAIN from the server (shows the server optimized query)\nsee also https://dev.mysql.com/doc/refman/explain-output.html") 33 31 ("profiling", po_switch(), "Turn on profiling and print profile") … … 37 35 ("print-connection", po_switch(), "Print database connection information") 38 36 ("verbose,v", var<uint16_t>(1), "Verbosity (0: quiet, 1: default, 2: more, 3, ...)") 37 ; 38 39 po::options_description ascii("ASCII output"); 40 ascii.add_options() 41 ("write,w", var<string>(""), "Write output to an ascii file") 42 ("delimiter", var<string>(), "The delimiter used if contents are displayed with --display (default=\\t)") 43 ("copy-shabang", po_switch(), "Copy the sha-bang line if exists to the output file") 44 ("copy-header", po_switch(), "Copy the header (all line starting with '#' up to the first non-comment line to the output file") 45 ("copy-query", po_switch(), "Copy the query to the ascii output file") 46 ("copy-comments", po_switch(), "Copy all lines starting with '#' to the output file which are not part of header") 47 ("copy-all", po_switch(), "An alias for --copy-header --copy-query --copy-comments") 39 48 ; 40 49 … … 56 65 57 66 conf.AddOptions(control); 67 conf.AddOptions(ascii); 58 68 conf.AddOptions(root); 59 69 conf.SetArgumentPositions(p); … … 481 491 const uint16_t compression = conf.Get<uint16_t>("compression"); 482 492 const string delimiter = conf.Has("delimiter") ? conf.Get<string>("delimiter") : "\t"; 493 494 const bool copy_all = conf.Get<bool>("copy-all"); 495 const bool copy_shabang = conf.Get<bool>("copy-shabang"); 496 const bool copy_header = copy_all || conf.Get<bool>("copy-header"); 497 const bool copy_query = copy_all || conf.Get<bool>("copy-query"); 498 const bool copy_comments = copy_all || conf.Get<bool>("copy-comments"); 499 483 500 const vector<string> _ignore = conf.Vec<string>("ignore"); 484 501 const bool print_connection = conf.Get<bool>("print-connection"); … … 513 530 return 4; 514 531 } 532 515 533 getline(fin, query, (char)fin.eof()); 516 534 } … … 861 879 } 862 880 881 // ------------------------------------------------------------------------- 882 883 string contents; 884 885 istringstream istr(query); 886 size_t line = 0; 887 bool header = true; 888 while (istr) 889 { 890 string ibuf; 891 getline(istr, ibuf); 892 const string sbuf = Tools::Trim(ibuf); 893 894 const bool shabang = line==0 && ibuf[0]=='#' && ibuf[1]=='!'; 895 const bool comment = sbuf[0]=='#' && !shabang; 896 const bool isquery = !shabang && !comment; 897 if (isquery) 898 header = false; 899 900 line++; 901 902 if ((copy_shabang && shabang) || 903 (copy_header && comment && header) || 904 (copy_query && isquery) || 905 (copy_comments && comment && !header)) 906 contents += '#' + ibuf + '\n'; 907 908 } 909 863 910 ofstream fout(write); 864 911 if (!write.empty() && !fout) … … 868 915 { 869 916 cout << endl; 917 cout << contents << endl; 870 918 cout << "# " << row.field_list(delimiter.c_str()) << endl; 871 919 } 872 920 873 921 if (!write.empty()) 922 { 923 fout << contents; 874 924 fout << "# " << row.field_list(delimiter.c_str()) << endl; 925 } 875 926 876 927 // ---------------------- Fill TTree with DB data --------------------------
Note:
See TracChangeset
for help on using the changeset viewer.