summaryrefslogtreecommitdiff
path: root/client/mysql.cc
diff options
context:
space:
mode:
authortsmith@ramayana.hindu.god <>2007-11-20 17:03:56 -0700
committertsmith@ramayana.hindu.god <>2007-11-20 17:03:56 -0700
commit6a193c5528f949c370654430abc1143a42535d99 (patch)
treea4b9c6ce4620ddc501299222ae6d6efb804994f9 /client/mysql.cc
parentb0d01ab27d686b1fb545e9dc961ec7b4778ce226 (diff)
downloadmariadb-git-6a193c5528f949c370654430abc1143a42535d99.tar.gz
Bug #25146: Some warnings/errors not shown when using --show-warnings
In several cases, an error when processing the query would cause mysql to return to the top level without printing warnings. Fix is to always print any available warnings before returning to the top level.
Diffstat (limited to 'client/mysql.cc')
-rw-r--r--client/mysql.cc52
1 files changed, 29 insertions, 23 deletions
diff --git a/client/mysql.cc b/client/mysql.cc
index 1dd33593b83..a44774cdeb8 100644
--- a/client/mysql.cc
+++ b/client/mysql.cc
@@ -2126,33 +2126,26 @@ com_go(String *buffer,char *line __attribute__((unused)))
}
#endif
- if (error)
- {
- executing_query= 0;
- buffer->length(0); // Remove query on error
- return error;
- }
- error=0;
buffer->length(0);
+ if (error)
+ goto end;
+
do
{
if (quick)
{
if (!(result=mysql_use_result(&mysql)) && mysql_field_count(&mysql))
{
- executing_query= 0;
- return put_error(&mysql);
+ error= put_error(&mysql);
+ goto end;
}
}
else
{
error= mysql_store_result_for_lazy(&result);
if (error)
- {
- executing_query= 0;
- return error;
- }
+ goto end;
}
if (verbose >= 3 || !opt_silent)
@@ -2229,12 +2222,10 @@ com_go(String *buffer,char *line __attribute__((unused)))
if (err >= 1)
error= put_error(&mysql);
+end:
+
if (show_warnings == 1 && warnings >= 1) /* Show warnings if any */
- {
- init_pager();
print_warnings();
- end_pager();
- }
if (!error && !status.batch &&
(mysql.server_status & SERVER_STATUS_DB_DROPPED))
@@ -2658,6 +2649,9 @@ static void print_warnings()
MYSQL_RES *result;
MYSQL_ROW cur;
my_ulonglong num_rows;
+
+ /* Save current error before calling "show warnings" */
+ uint error= mysql_errno(&mysql);
/* Get the warnings */
query= "show warnings";
@@ -2666,16 +2660,28 @@ static void print_warnings()
/* Bail out when no warnings */
if (!(num_rows= mysql_num_rows(result)))
- {
- mysql_free_result(result);
- return;
- }
+ goto end;
+
+ cur= mysql_fetch_row(result);
+
+ /*
+ Don't print a duplicate of the current error. It is possible for SHOW
+ WARNINGS to return multiple errors with the same code, but different
+ messages. To be safe, skip printing the duplicate only if it is the only
+ warning.
+ */
+ if (!cur || num_rows == 1 && error == (uint) strtoul(cur[1], NULL, 10))
+ goto end;
/* Print the warnings */
- while ((cur= mysql_fetch_row(result)))
+ init_pager();
+ do
{
tee_fprintf(PAGER, "%s (Code %s): %s\n", cur[0], cur[1], cur[2]);
- }
+ } while ((cur= mysql_fetch_row(result)));
+ end_pager();
+
+end:
mysql_free_result(result);
}