diff options
author | Dan Ungureanu <udan1107@gmail.com> | 2016-03-08 22:43:14 +0200 |
---|---|---|
committer | Sergey Vojtovich <svoj@mariadb.org> | 2016-05-10 13:40:35 +0400 |
commit | eca060775e2465dd1be7f3bb252b308f05c937d0 (patch) | |
tree | 5abe335a896983df4b3d7dbdc2a16b26e1597c43 /client | |
parent | f2afeb38262828fcfe15329c2c28baeb2ad56d66 (diff) | |
download | mariadb-git-eca060775e2465dd1be7f3bb252b308f05c937d0.tar.gz |
MDEV-505: feature request: add \H option for mysql client prompt
Introduce `\H` option which behaves mostly like `\h`. The only exception is
when the client connects to the server hosted on localhost. In this case, the
hostname will be used instead.
Diffstat (limited to 'client')
-rw-r--r-- | client/mysql.cc | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/client/mysql.cc b/client/mysql.cc index 9c6320fe10a..f08a33207f7 100644 --- a/client/mysql.cc +++ b/client/mysql.cc @@ -5112,17 +5112,29 @@ static const char *construct_prompt() processed_prompt.append("unknown"); break; case 'h': + case 'H': { - const char *prompt; - prompt= connected ? mysql_get_host_info(&mysql) : "not_connected"; - if (strstr(prompt, "Localhost")) - processed_prompt.append("localhost"); - else - { - const char *end=strcend(prompt,' '); - processed_prompt.append(prompt, (uint) (end-prompt)); - } - break; + const char *prompt; + prompt= connected ? mysql_get_host_info(&mysql) : "not_connected"; + if (strstr(prompt, "Localhost")) + { + if (*c == 'h') + processed_prompt.append("localhost"); + else + { + char hostname[HOST_NAME_MAX]; + if (gethostname(hostname, sizeof(hostname)) == 0) + processed_prompt.append(hostname); + else + processed_prompt.append("gethostname(2) failed"); + } + } + else + { + const char *end=strcend(prompt,' '); + processed_prompt.append(prompt, (uint) (end-prompt)); + } + break; } case 'p': { |