Bug #72705 | Add character option to mysql client's prompt | ||
---|---|---|---|
Submitted: | 21 May 2014 9:58 | Modified: | 17 Aug 2015 14:27 |
Reporter: | Hao Liu | Email Updates: | |
Status: | No Feedback | Impact on me: | |
Category: | MySQL Server: Command-line Clients | Severity: | S4 (Feature request) |
Version: | 5.5 5.6 | OS: | Any |
Assigned to: | CPU Architecture: | Any |
[21 May 2014 9:58]
Hao Liu
[21 May 2014 15:05]
Hao Liu
change the Version
[26 May 2014 1:51]
Hao Liu
I will attach the patch: Index: mysql.cc =================================================================== --- mysql.cc (版本 5610) +++ mysql.cc (工作副本) @@ -162,6 +162,8 @@ *current_prompt=0, *delimiter_str= 0, *default_charset= (char*) MYSQL_AUTODETECT_CHARSET_NAME, *opt_init_command= 0; +static char *current_server_charset = NULL; +static char *current_client_charset = NULL; static char *histfile; static char *histfile_tmp; static String glob_buffer,old_buffer; @@ -248,6 +250,7 @@ static void add_int_to_prompt(int toadd); static int get_result_width(MYSQL_RES *res); static int get_field_disp_length(MYSQL_FIELD * field); +static void get_current_charset(); /* A structure which contains information on the commands this program can understand. */ @@ -2772,6 +2775,34 @@ } } +static void get_current_charset() +{ + MYSQL_RES *res; + + if (current_server_charset != NULL) + my_free(current_server_charset); + if (current_client_charset != NULL) + my_free(current_client_charset); + current_server_charset= NULL; + current_client_charset= NULL; + + if (!mysql_query(&mysql, "SELECT @@GLOBAL.character_set_server") && + (res= mysql_use_result(&mysql))) + { + MYSQL_ROW row= mysql_fetch_row(res); + if (row && row[0]) + current_server_charset= my_strdup(row[0], MYF(MY_WME)); + mysql_free_result(res); + } + if (!mysql_query(&mysql, "SELECT @@character_set_client") && + (res= mysql_use_result(&mysql))) + { + MYSQL_ROW row= mysql_fetch_row(res); + if (row && row[0]) + current_client_charset= my_strdup(row[0], MYF(MY_WME)); + mysql_free_result(res); + } +} /*************************************************************************** The different commands ***************************************************************************/ @@ -4836,6 +4867,24 @@ case 'c': add_int_to_prompt(++prompt_counter); break; + case 'K': + if (connected) { + get_current_charset(); + processed_prompt.append(current_server_charset?current_server_charset: + "(none)"); + } + else + processed_prompt.append("not_connected"); + break; + case 'k': + if (connected) { + get_current_charset(); + processed_prompt.append(current_client_charset?current_client_charset: + "(none)"); + } + else + processed_prompt.append("not_connected"); + break; case 'v': if (connected) processed_prompt.append(mysql_get_server_info(&mysql));
[17 Jul 2015 14:27]
Georgi Kodinov
Thanks for your reasonable feature request. Can you please put your patch into the contribution section so we can process it ? If that's easier for you we also take github pull requests.
[18 Aug 2015 1:00]
Bugs System
No feedback was provided for this bug for over a month, so it is being suspended automatically. If you are able to provide the information that was originally requested, please do so and change the status of the bug back to "Open".