[cleanup] some minor fixes

This commit is contained in:
Timothy Stack 2021-01-17 23:29:08 -08:00
parent 56bee6f4c9
commit 076d730fa2
4 changed files with 16 additions and 10 deletions

View File

@ -192,9 +192,9 @@ Result<string, string> execute_sql(exec_context &ec, const string &sql, string &
SQLITE_TRANSIENT);
}
else if (name[0] == '$') {
map<string, string> &lvars = ec.ec_local_vars.top();
map<string, string> &gvars = ec.ec_global_vars;
map<string, string>::iterator local_var, global_var;
const auto &lvars = ec.ec_local_vars.top();
const auto &gvars = ec.ec_global_vars;
map<string, string>::const_iterator local_var, global_var;
const char *env_value;
if (lnav_data.ld_window) {
@ -297,13 +297,18 @@ Result<string, string> execute_sql(exec_context &ec, const string &sql, string &
auto &vars = ec.ec_local_vars.top();
for (unsigned int lpc = 0; lpc < dls.dls_headers.size(); lpc++) {
const string &column_name = dls.dls_headers[lpc].hm_name;
const auto &column_name = dls.dls_headers[lpc].hm_name;
if (sql_ident_needs_quote(column_name.c_str())) {
continue;
}
vars[column_name] = dls.dls_rows[0][lpc];
const auto* value = dls.dls_rows[0][lpc];
if (value == nullptr) {
continue;
}
vars[column_name] = value;
}
}
@ -491,7 +496,7 @@ Result<string, string> execute_file(exec_context &ec, const string &path_and_arg
ec.ec_local_vars.push({});
auto script_name = split_args[0];
map<string, string> &vars = ec.ec_local_vars.top();
auto& vars = ec.ec_local_vars.top();
char env_arg_name[32];
string star, open_error = "file not found";
@ -514,7 +519,6 @@ Result<string, string> execute_file(exec_context &ec, const string &path_and_arg
vars["__all__"] = star;
vector<script_metadata> paths_to_exec;
map<string, const char *>::iterator internal_iter;
find_format_scripts(lnav_data.ld_config_paths, scripts);
auto iter = scripts.as_scripts.find(script_name);

View File

@ -46,13 +46,14 @@
struct exec_context;
typedef int (*sql_callback_t)(exec_context &ec, sqlite3_stmt *stmt);
int sql_callback(exec_context &ec, sqlite3_stmt *stmt);
typedef std::future<std::string> (*pipe_callback_t)(
exec_context &ec, const std::string &cmdline, auto_fd &fd);
struct exec_context {
exec_context(std::vector<logline_value> *line_values = nullptr,
sql_callback_t sql_callback = nullptr,
sql_callback_t sql_callback = ::sql_callback,
pipe_callback_t pipe_callback = nullptr)
: ec_top_line(vis_line_t(0)),
ec_dry_run(false),
@ -134,7 +135,6 @@ Result<std::string, std::string> execute_file(exec_context &ec, const std::strin
Result<std::string, std::string> execute_any(exec_context &ec, const std::string &cmdline);
void execute_init_commands(exec_context &ec, std::vector<std::pair<Result<std::string, std::string>, std::string> > &msgs);
int sql_callback(exec_context &ec, sqlite3_stmt *stmt);
std::future<std::string> pipe_callback(
exec_context &ec, const std::string &cmdline, auto_fd &fd);

View File

@ -162,7 +162,7 @@ bool handle_keyseq(const char *keyseq)
string expanded_msg;
if (lexer.eval(expanded_msg, {
&ec.ec_local_vars.top(),
&vars,
&ec.ec_global_vars,
})) {
lnav_data.ld_rl_view->set_alt_value(expanded_msg);

View File

@ -367,6 +367,8 @@ void execute_examples()
case help_context_t::HC_SQL_INFIX:
case help_context_t::HC_SQL_FUNCTION:
case help_context_t::HC_SQL_TABLE_VALUED_FUNCTION: {
exec_context ec;
execute_sql(ec, ex.he_cmd, alt_msg);
if (dls.dls_rows.size() == 1 &&