- Timestamp:
- 07/22/18 15:38:55 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/rootifysql.cc
r18961 r19074 3 3 #include <regex> 4 4 5 #include <boost/algorithm/string/join.hpp> 6 7 #include "tools.h" 5 8 #include "Time.h" 6 9 #include "Configuration.h" … … 33 36 ("no-fill", po_switch(), "Do not fill events into the root file (mainly for debugging purposes, e.g. performance studies)") 34 37 ("delimiter", var<string>(""), "The delimiter used if contents are displayed with --display (default=\\t)") 38 ("var.*", var<string>(), "Predefined user variables") 35 39 ("verbose,v", var<uint16_t>(1), "Verbosity (0: quiet, 1: default, 2: more, 3, ...)") 36 40 ; … … 70 74 "As a trick, the rootify.sql file can be made excutable (chmod u+x rootify.sql). " 71 75 "If the first line contains '#!rootifysql', the script can be executed directly.\n" 76 "\n" 77 "You can use variables in your sql query like @MyVar and define them on the " 78 "command line. In this example with --var.MyVar=5\n" 72 79 "\n" 73 80 "Comments in the query-file can be placed according to the SQL standard inline " … … 113 120 // ------------------------------------------------------------------------- 114 121 122 const auto vars = conf.GetWildcardOptions("var.*"); 123 124 vector<string> variables; 125 for (const auto &var : vars) 126 variables.emplace_back('@'+var.substr(4)+":="+Tools::Trim(conf.Get<string>(var))); 127 115 128 if (verbose>0) 116 129 cout << "\n--------------------- Rootify SQL ----------------------" << endl; … … 165 178 } 166 179 } 167 // ------------------------------------------------------------------------- 180 181 Time start2; 182 183 // --------------------------- Connect to database ------------------------------------------------- 168 184 169 185 if (query.back()!='\n') 170 186 query += '\n'; 171 187 188 if (verbose>0) 189 cout << "Connecting to database..." << endl; 190 191 192 Database connection(uri); // Keep alive while fetching rows 193 194 // -------------------------- Set user defined variables ------------------- 195 if (variables.size()>0) 196 { 197 if (verbose>0) 198 cout << "Setting user defined variables..." << endl; 199 200 const string varset = 201 "SET\n "+boost::algorithm::join(variables, ",\n "); 202 203 try 204 { 205 connection.query(varset).execute(); 206 } 207 catch (const exception &e) 208 { 209 cerr << varset << "\n\n"; 210 cerr << "SQL query failed:\n" << e.what() << endl; 211 return 5; 212 } 213 214 if (verbose>2) 215 cout << '\n' << varset << '\n' << endl; 216 } 217 218 // -------------------------- Request data from database ------------------- 219 if (verbose>0) 220 cout << "Requesting data..." << endl; 221 172 222 if (verbose>2) 173 223 cout << '\n' << query << endl; 174 224 175 if (verbose>0)176 cout << "Requesting data..." << endl;177 178 Time start2;179 180 // -------------------------- Request data from database -------------------181 Database connection(uri); // Keep alive while fetching rows182 183 225 const mysqlpp::UseQueryResult res = 184 226 connection.query(query).use(); 227 185 228 // ------------------------------------------------------------------------- 186 229 … … 191 234 TFile tfile(path, update?"UPDATE":(force?"RECREATE":"CREATE"), "Rootify SQL", compression); 192 235 if (tfile.IsZombie()) 193 return 5;236 return 6; 194 237 195 238 // ------------------------------------------------------------------------- … … 200 243 { 201 244 cerr << "Empty set returned... nothing to write." << endl; 202 return 6;245 return 7; 203 246 } 204 247
Note:
See TracChangeset
for help on using the changeset viewer.