Hello Kristofer,
Please see my minor comments below.
Thank you,
Gleb.
Kristofer Pettersson wrote:
> #At file:///Users/thek/Development/mysql-5.0-bugteam/ based on
> revid:joro@stripped
>
> 2994 Kristofer Pettersson 2009-07-03
> Bug#37274 client 'status' command doesn't print all info after losing
> connection to
> server
>
> If the server connection was lost during repeated status commands,
> the client would fail to detect this and the client output would be
> inconsistent.
>
> This patch fixes this issue by making sure that the server is online
> before the client attempts to execute the status command.
>
> The patch is based on a contribution originally suggested by Andrew Hutchings.
> @ client/mysql.cc
> * Replace variable "connected" with a call to mysql_real_query_for_lazy()
> will attempt to reconnect to server on if there is a failure.
>
> modified:
> client/mysql.cc
> === modified file 'client/mysql.cc'
> --- a/client/mysql.cc 2009-06-29 14:00:47 +0000
> +++ b/client/mysql.cc 2009-07-03 09:35:04 +0000
> @@ -4263,42 +4263,39 @@ com_status(String *buffer __attribute__(
> ulonglong id;
> MYSQL_RES *result;
> LINT_INIT(result);
> + const char *query;
> +
> + query= "select DATABASE(), USER() limit 1";
> + if (mysql_real_query_for_lazy(query, strlen(query)))
IMO it is better to use STRING_WITH_LENGTH macro.
> + return 0;
>
> tee_puts("--------------", stdout);
> usage(1); /* Print version */
The current client prints this things always, but your patch does not.
Is it ok?
> - if (connected)
> + tee_fprintf(stdout, "\nConnection id:\t\t%lu\n",mysql_thread_id(&mysql));
> + /*
> + Don't remove "limit 1",
> + it is protection againts SQL_SELECT_LIMIT=0
> + */
> + query= "select DATABASE(), USER() limit 1";
The last string is not necessary.
> + if (mysql_store_result_for_lazy(&result))
> {
> - tee_fprintf(stdout, "\nConnection id:\t\t%lu\n",mysql_thread_id(&mysql));
> - /*
> - Don't remove "limit 1",
> - it is protection againts SQL_SELECT_LIMIT=0
> - */
> - if (!mysql_query(&mysql,"select DATABASE(), USER() limit 1") &&
> - (result=mysql_use_result(&mysql)))
> + MYSQL_ROW cur=mysql_fetch_row(result);
> + if (cur)
> {
> - MYSQL_ROW cur=mysql_fetch_row(result);
> - if (cur)
> - {
> - tee_fprintf(stdout, "Current database:\t%s\n", cur[0] ? cur[0] : "");
> - tee_fprintf(stdout, "Current user:\t\t%s\n", cur[1]);
> - }
> - mysql_free_result(result);
> - }
> -#ifdef HAVE_OPENSSL
> - if ((status_str= mysql_get_ssl_cipher(&mysql)))
> - tee_fprintf(stdout, "SSL:\t\t\tCipher in use is %s\n",
> - status_str);
> - else
> -#endif /* HAVE_OPENSSL */
> - tee_puts("SSL:\t\t\tNot in use", stdout);
> + tee_fprintf(stdout, "Current database:\t%s\n", cur[0] ? cur[0] : "");
> + tee_fprintf(stdout, "Current user:\t\t%s\n", cur[1]);
> + }
> + mysql_free_result(result);
> }
> +
> +#ifdef HAVE_OPENSSL
> + if ((status_str= mysql_get_ssl_cipher(&mysql)))
> + tee_fprintf(stdout, "SSL:\t\t\tCipher in use is %s\n",
> + status_str);
> else
> - {
> - vidattr(A_BOLD);
> - tee_fprintf(stdout, "\nNo connection\n");
> - vidattr(A_NORMAL);
> - return 0;
> - }
> +#endif /* HAVE_OPENSSL */
> + tee_puts("SSL:\t\t\tNot in use", stdout);
> +
> if (skip_updates)
> {
> vidattr(A_BOLD);
> @@ -4317,8 +4314,14 @@ com_status(String *buffer __attribute__(
> tee_fprintf(stdout, "Insert id:\t\t%s\n", llstr(id, buff));
>
> /* "limit 1" is protection against SQL_SELECT_LIMIT=0 */
> - if (!mysql_query(&mysql,"select @@character_set_client,
> @@character_set_connection, @@character_set_server, @@character_set_database limit 1")
> &&
> - (result=mysql_use_result(&mysql)))
> + query= "select @@character_set_client, @@character_set_connection, "
> + "@@character_set_server, @@character_set_database limit 1";
> + if (mysql_real_query_for_lazy(query, strlen(query)))
STRING_WITH_LENGTH as above.
> + {
> + if (mysql_errno(&mysql) == CR_SERVER_GONE_ERROR)
> + return 0;
> + }
> + if (mysql_store_result_for_lazy(&result))
> {
> MYSQL_ROW cur=mysql_fetch_row(result);
> if (cur)
>
>
>
> ------------------------------------------------------------------------
>
>