add aliases for \<letter> interactive client commands

initial implementation for:
  * \d aka SHOW TABLES
  * \l aka SHOW DATABASES
  * \c aka USE

Replace prefix of interactive `input` string with an aliased command
inside of the loop of `ClientBase::runInteractive()` in order to allow
command parameters, like `\c db_name`.

See issue #9339
This commit is contained in:
Pavel Medvedev 2021-10-30 08:44:31 +02:00
parent 2bb586bed3
commit f4e3d053c2

View File

@ -61,6 +61,14 @@ namespace DB
static const NameSet exit_strings{"exit", "quit", "logout", "учше", "йгше", "дщпщге", "exit;", "quit;", "logout;", "учшеж", "йгшеж", "дщпщгеж", "q", "й", "\\q", "\\Q", "\\й", "\\Й", ":q", "Жй"};
static const std::initializer_list<std::pair<String, String>> backslash_aliases
{
{ "\\l", "SHOW DATABASES" },
{ "\\d", "SHOW TABLES" },
{ "\\c", "USE" },
};
namespace ErrorCodes
{
extern const int BAD_ARGUMENTS;
@ -1356,6 +1364,17 @@ void ClientBase::runInteractive()
has_vertical_output_suffix = true;
}
for (const auto& [alias, command] : backslash_aliases)
{
if (input.starts_with(alias))
{
// append the rest of input to the command
// for parameters support, e.g. \c db_name -> USE db_name
input = command + input.substr(alias.size());
break;
}
}
try
{
if (!processQueryText(input))