| Bug #44732 | mysql client should printing warnings on stderr in batch mode | ||
|---|---|---|---|
| Submitted: | 7 May 2009 23:34 | ||
| Reporter: | Jim Winstead | Email Updates: | |
| Status: | Verified | Impact on me: | |
| Category: | MySQL Server: Command-line Clients | Severity: | S3 (Non-critical) |
| Version: | 5.1 | OS: | Any |
| Assigned to: | Assigned Account | CPU Architecture: | Any |
[7 May 2009 23:34]
Jim Winstead
[18 May 2010 20:43]
Hartmut Holzgraefe
proposed patch:
--- mysql-5.1.46/client/mysql.cc 2010-04-06 16:03:48.000000000 +0200
+++ mysql-5.1.46-bug44732/client/mysql.cc 2010-05-18 21:41:41.000000000 +0200
@@ -3570,6 +3570,7 @@
MYSQL_RES *result;
MYSQL_ROW cur;
my_ulonglong num_rows;
+ FILE *out;
/* Save current error before calling "show warnings" */
uint error= mysql_errno(&mysql);
@@ -3595,12 +3596,18 @@
goto end;
/* Print the warnings */
- init_pager();
+ if (status.batch) {
+ out = stderr;
+ } else {
+ init_pager();
+ out = PAGER;
+ }
do
{
- tee_fprintf(PAGER, "%s (Code %s): %s\n", cur[0], cur[1], cur[2]);
+ tee_fprintf(out, "%s (Code %s): %s\n", cur[0], cur[1], cur[2]);
} while ((cur= mysql_fetch_row(result)));
- end_pager();
+ if (!status.batch)
+ end_pager();
end:
mysql_free_result(result);
[26 May 2010 23:03]
Jim Winstead
the patch can be even simpler, since init_pager() etc won't actually do anything when status.batch is set.
=== modified file 'client/mysql.cc'
--- client/mysql.cc 2010-03-11 13:16:54 +0000
+++ client/mysql.cc 2010-05-25 22:01:48 +0000
@@ -3598,7 +3598,9 @@ static void print_warnings()
init_pager();
do
{
- tee_fprintf(PAGER, "%s (Code %s): %s\n", cur[0], cur[1], cur[2]);
+ /* In batch mode, we print warnings to stderr instead of stdout. */
+ tee_fprintf(status.batch ? stderr : PAGER,
+ "%s (Code %s): %s\n", cur[0], cur[1], cur[2]);
} while ((cur= mysql_fetch_row(result)));
end_pager();
