From d1521496ccfab7bf890ece4466407a05c3386d4a Mon Sep 17 00:00:00 2001 From: Timothy Stack Date: Wed, 13 Jul 2022 22:24:49 -0700 Subject: [PATCH] [docs] fill out search-table docs --- docs/requirements.txt | 3 ++- docs/source/usage.rst | 16 ++++++++++++++-- src/command_executor.cc | 16 ++++++++++++++++ src/formats/vmw_log.json | 4 ++++ test/expected/expected.am | 2 ++ ..._5fe26fe4fc22f23f8dbe3a6aab394602886f2971.err | 5 +++++ ..._5fe26fe4fc22f23f8dbe3a6aab394602886f2971.out | 0 test/test_sql.sh | 3 +++ 8 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 test/expected/test_sql.sh_5fe26fe4fc22f23f8dbe3a6aab394602886f2971.err create mode 100644 test/expected/test_sql.sh_5fe26fe4fc22f23f8dbe3a6aab394602886f2971.out diff --git a/docs/requirements.txt b/docs/requirements.txt index ee007c12..66837404 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -1,4 +1,5 @@ -Sphinx>=3.4.3 +sphinx>=4.3.0 sphinx-jsonschema sphinx-prompt pathlib +sphinx-rtd-theme>=0.5.1 diff --git a/docs/source/usage.rst b/docs/source/usage.rst index 2b614cb0..e30fb570 100644 --- a/docs/source/usage.rst +++ b/docs/source/usage.rst @@ -177,15 +177,27 @@ Log level ^^^^^^^^^ To hide messages below a certain log level, you can use the -:ref:`:set-min-log-level`. +:ref:`:set-min-log-level` command. .. _search_tables: Search Tables ------------- -TBD +Search tables allow you to access arbitrary data in log messages through +SQLite virtual tables. If there is some data in a log message that you can +match with a regular expression, you can create a search-table that matches +that data and any capture groups will be plumbed through as columns in the +search table. +Creating a search table can be done interactively using the +:ref:`:create-search-table` command or by adding it to +a :ref:`log format definition`. The main difference between +the two is that tables defined as part of a format will only search messages +from log files with that format and the tables will include log message +columns defined in that format. Whereas a table created with the command +will search messages from all different formats and no format-specific +columns will be included in the table. .. _taking_notes: diff --git a/src/command_executor.cc b/src/command_executor.cc index 44345e77..c53edcfb 100644 --- a/src/command_executor.cc +++ b/src/command_executor.cc @@ -209,6 +209,22 @@ execute_sql(exec_context& ec, const std::string& sql, std::string& alt_msg) for (int lpc = 0; lpc < param_count; lpc++) { std::map::iterator ov_iter; const auto* name = sqlite3_bind_parameter_name(stmt.in(), lpc + 1); + if (name == nullptr) { + auto um + = lnav::console::user_message::error( + "invalid SQL statement") + .with_reason( + "using a question-mark (?) for bound variables " + "is not supported, only named bound parameters " + "are supported") + .with_help( + "named parameters start with a dollar-sign " + "($) or colon (:) followed by the variable name"); + ec.add_error_context(um); + + return Err(um); + } + ov_iter = ec.ec_override.find(name); if (ov_iter != ec.ec_override.end()) { sqlite3_bind_text(stmt.in(), diff --git a/src/formats/vmw_log.json b/src/formats/vmw_log.json index 238ef15a..a23d3212 100644 --- a/src/formats/vmw_log.json +++ b/src/formats/vmw_log.json @@ -98,6 +98,10 @@ "pattern": "/SessionStats/SessionPool/Session/Id='(?[^']+)'/Username='(?[^']+)'/ClientIP='(?[^']+)'(?[^ ]+) (?[^\\n]+)", "glob": "*/vpxd-profile*" }, + "vpxd_session_pool_stats": { + "pattern": "/SessionStats/SessionPool/Id='(?[^']+)'/Username='(?[^']+)'(?[^ ]+) (?[^\\n]+)", + "glob": "*/vpxd-profile*" + }, "vpx_lro_begin": { "pattern": "\\[VpxLRO\\] -- BEGIN (?\\S+) -- (?\\S*) -- (?\\S*) -- (?:(?[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})(?:\\((?[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})\\))?)?" }, diff --git a/test/expected/expected.am b/test/expected/expected.am index 59d04b19..2693cf8a 100644 --- a/test/expected/expected.am +++ b/test/expected/expected.am @@ -420,6 +420,8 @@ EXPECTED_FILES = \ $(srcdir)/%reldir%/test_sql.sh_57edc93426e6767aa44ab2356c55327553dcdc8d.out \ $(srcdir)/%reldir%/test_sql.sh_5801770f3e0ecc1d62c7a97116d6da1981bbc7bd.err \ $(srcdir)/%reldir%/test_sql.sh_5801770f3e0ecc1d62c7a97116d6da1981bbc7bd.out \ + $(srcdir)/%reldir%/test_sql.sh_5fe26fe4fc22f23f8dbe3a6aab394602886f2971.err \ + $(srcdir)/%reldir%/test_sql.sh_5fe26fe4fc22f23f8dbe3a6aab394602886f2971.out \ $(srcdir)/%reldir%/test_sql.sh_62eb85c9569e71a630d72065238559528a16114c.err \ $(srcdir)/%reldir%/test_sql.sh_62eb85c9569e71a630d72065238559528a16114c.out \ $(srcdir)/%reldir%/test_sql.sh_662b5f9b17aa69a8e3aa9a18acb30d9acf6e2837.err \ diff --git a/test/expected/test_sql.sh_5fe26fe4fc22f23f8dbe3a6aab394602886f2971.err b/test/expected/test_sql.sh_5fe26fe4fc22f23f8dbe3a6aab394602886f2971.err new file mode 100644 index 00000000..dfe4674d --- /dev/null +++ b/test/expected/test_sql.sh_5fe26fe4fc22f23f8dbe3a6aab394602886f2971.err @@ -0,0 +1,5 @@ +✘ error: invalid SQL statement + reason: using a question-mark (?) for bound variables is not supported, only named bound parameters are supported + --> command-option:1 + | ;SELECT 1 = ?  + = help: named parameters start with a dollar-sign ($) or colon (:) followed by the variable name diff --git a/test/expected/test_sql.sh_5fe26fe4fc22f23f8dbe3a6aab394602886f2971.out b/test/expected/test_sql.sh_5fe26fe4fc22f23f8dbe3a6aab394602886f2971.out new file mode 100644 index 00000000..e69de29b diff --git a/test/test_sql.sh b/test/test_sql.sh index 5c295b1e..f82cd37e 100644 --- a/test/test_sql.sh +++ b/test/test_sql.sh @@ -5,6 +5,9 @@ export YES_COLOR=1 lnav_test="${top_builddir}/src/lnav-test" unset XDG_CONFIG_HOME +run_cap_test ${lnav_test} -nN \ + -c ";SELECT 1 = ?" + run_cap_test ${lnav_test} -n \ -c ";.read nonexistent-file" \ ${test_dir}/logfile_empty.0