Changeset 19117
- Timestamp:
- 07/31/18 21:58:43 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/rootifysql.cc
r19111 r19117 42 42 ("var.*", var<string>(), "Predefined SQL user variables (@VAR)") 43 43 ("env.*", vars<string>(), "Predefined environment for substitutions in the query ($ENV)") 44 ("list.*", var<string>(), "Predefined environment for substitutions in the query ($ENV). The list is read from the given file (one list entry per line)") 44 45 ("verbose,v", var<uint16_t>(1), "Verbosity (0: quiet, 1: default, 2: more, 3, ...)") 45 46 ; … … 90 91 "If you specifiy one environmentvariable more than once, a list is created. " 91 92 "For example --env.TEST=1 --env.TEST=2 --env.TEST=3 would substitute " 92 "$TEST or ${TEST} by '1, 2, 3'. This is useful for the SQL `IN` keyword.\n" 93 "$TEST or ${TEST} by '1, 2, 3'. This is useful for the SQL `IN` keyword. " 94 "You can also read the values for an enviroment substitution from a file " 95 "(one element per line), e.g. --env.TEST=file.txt\n" 93 96 "\n" 94 97 "Comments in the query-file can be placed according to the SQL standard inline " … … 402 405 if (!fin) 403 406 { 404 cerr << "Could not open '" << file << "': " << strerror(errno) << endl;407 cerr << "Could not open query in '" << file << "': " << strerror(errno) << endl; 405 408 return 1; 406 409 } … … 416 419 // ------------------------------------------------------------------------- 417 420 418 const auto envs = conf.GetWildcardOptions("env.*"); 421 map<string, vector<string>> envs; 422 for (const auto &env : conf.GetWildcardOptions("env.*")) 423 envs.emplace(env.substr(4), conf.Vec<string>(env)); 424 425 for (const auto &env : conf.GetWildcardOptions("list.*")) 426 { 427 const string fname = conf.Get<string>(env); 428 429 ifstream fin(fname); 430 if (!fin) 431 { 432 cerr << "Could not open environment in '" << fname << "': " << strerror(errno) << endl; 433 return 3; 434 } 435 436 const string &ident = env.substr(5); 437 438 string repl; 439 for (string line; getline(fin, line); ) 440 envs[ident].push_back(line); 441 } 419 442 420 443 for (const auto &env : envs) 421 444 { 422 regex r1("\\$\\{"+env.substr(4)+"\\}"); 423 regex r2("\\$"+env.substr(4)+"\\b"); 424 425 const string repl = boost::join(conf.Vec<string>(env), ", "); 426 427 query = regex_replace(query, r1, repl); 428 query = regex_replace(query, r2, repl); 445 regex rexpr("\\$\\{"+env.first+"\\}|\\$"+env.first+"\\b"); 446 query = regex_replace(query, rexpr, boost::join(env.second, ", ")); 429 447 } 430 448
Note:
See TracChangeset
for help on using the changeset viewer.