Add function verbose_msg

parent 2ea50d6d
...@@ -426,6 +426,30 @@ static my_bool dump_all_views_in_db(char *database); ...@@ -426,6 +426,30 @@ static my_bool dump_all_views_in_db(char *database);
#include <help_start.h> #include <help_start.h>
/*
Print the supplied message if in verbose mode
SYNOPSIS
verbose_msg()
fmt format specifier
... variable number of parameters
*/
static void verbose_msg(const char *fmt, ...)
{
va_list args;
DBUG_ENTER("verbose_msg");
if (!verbose)
DBUG_VOID_RETURN;
va_start(args, fmt);
vfprintf(stderr, fmt, args);
va_end(args);
DBUG_VOID_RETURN;
}
/* /*
exit with message if ferror(file) exit with message if ferror(file)
...@@ -894,10 +918,8 @@ static int dbConnect(char *host, char *user,char *passwd) ...@@ -894,10 +918,8 @@ static int dbConnect(char *host, char *user,char *passwd)
{ {
char buff[20+FN_REFLEN]; char buff[20+FN_REFLEN];
DBUG_ENTER("dbConnect"); DBUG_ENTER("dbConnect");
if (verbose)
{ verbose_msg("-- Connecting to %s...\n", host ? host : "localhost");
fprintf(stderr, "-- Connecting to %s...\n", host ? host : "localhost");
}
mysql_init(&mysql_connection); mysql_init(&mysql_connection);
if (opt_compress) if (opt_compress)
mysql_options(&mysql_connection,MYSQL_OPT_COMPRESS,NullS); mysql_options(&mysql_connection,MYSQL_OPT_COMPRESS,NullS);
...@@ -963,8 +985,7 @@ static int dbConnect(char *host, char *user,char *passwd) ...@@ -963,8 +985,7 @@ static int dbConnect(char *host, char *user,char *passwd)
*/ */
static void dbDisconnect(char *host) static void dbDisconnect(char *host)
{ {
if (verbose) verbose_msg("-- Disconnecting from %s...\n", host ? host : "localhost");
fprintf(stderr, "-- Disconnecting from %s...\n", host ? host : "localhost");
mysql_close(sock); mysql_close(sock);
} /* dbDisconnect */ } /* dbDisconnect */
...@@ -1418,9 +1439,7 @@ static uint get_table_structure(char *table, char *db, char *table_type, ...@@ -1418,9 +1439,7 @@ static uint get_table_structure(char *table, char *db, char *table_type,
if (delayed && (*ignore_flag & IGNORE_INSERT_DELAYED)) if (delayed && (*ignore_flag & IGNORE_INSERT_DELAYED))
{ {
delayed= 0; delayed= 0;
if (verbose) verbose_msg("-- Warning: Unable to use delayed inserts for table '%s' "
fprintf(stderr,
"-- Warning: Unable to use delayed inserts for table '%s' "
"because it's of type %s\n", table, table_type); "because it's of type %s\n", table, table_type);
} }
...@@ -1437,8 +1456,7 @@ static uint get_table_structure(char *table, char *db, char *table_type, ...@@ -1437,8 +1456,7 @@ static uint get_table_structure(char *table, char *db, char *table_type,
insert_option= ((delayed && opt_ignore) ? " DELAYED IGNORE " : insert_option= ((delayed && opt_ignore) ? " DELAYED IGNORE " :
delayed ? " DELAYED " : opt_ignore ? " IGNORE " : ""); delayed ? " DELAYED " : opt_ignore ? " IGNORE " : "");
if (verbose) verbose_msg("-- Retrieving table structure for table %s...\n", table);
fprintf(stderr, "-- Retrieving table structure for table %s...\n", table);
len= my_snprintf(query_buff, sizeof(query_buff), len= my_snprintf(query_buff, sizeof(query_buff),
"SET OPTION SQL_QUOTE_SHOW_CREATE=%d", "SET OPTION SQL_QUOTE_SHOW_CREATE=%d",
...@@ -1505,8 +1523,7 @@ static uint get_table_structure(char *table, char *db, char *table_type, ...@@ -1505,8 +1523,7 @@ static uint get_table_structure(char *table, char *db, char *table_type,
{ {
char *scv_buff = NULL; char *scv_buff = NULL;
if (verbose) verbose_msg("-- It's a view, create dummy table for view\n");
fprintf(stderr, "-- It's a view, create dummy table for view\n");
/* save "show create" statement for later */ /* save "show create" statement for later */
if ((row= mysql_fetch_row(result)) && (scv_buff=row[1])) if ((row= mysql_fetch_row(result)) && (scv_buff=row[1]))
...@@ -1649,9 +1666,7 @@ static uint get_table_structure(char *table, char *db, char *table_type, ...@@ -1649,9 +1666,7 @@ static uint get_table_structure(char *table, char *db, char *table_type,
} }
else else
{ {
if (verbose) verbose_msg("%s: Warning: Can't set SQL_QUOTE_SHOW_CREATE option (%s)\n",
fprintf(stderr,
"%s: Warning: Can't set SQL_QUOTE_SHOW_CREATE option (%s)\n",
my_progname, mysql_error(sock)); my_progname, mysql_error(sock));
my_snprintf(query_buff, sizeof(query_buff), "show fields from %s", my_snprintf(query_buff, sizeof(query_buff), "show fields from %s",
...@@ -1841,10 +1856,8 @@ static uint get_table_structure(char *table, char *db, char *table_type, ...@@ -1841,10 +1856,8 @@ static uint get_table_structure(char *table, char *db, char *table_type,
{ {
if (mysql_errno(sock) != ER_PARSE_ERROR) if (mysql_errno(sock) != ER_PARSE_ERROR)
{ /* If old MySQL version */ { /* If old MySQL version */
if (verbose) verbose_msg("-- Warning: Couldn't get status information for " \
fprintf(stderr, "table %s (%s)\n", result_table,mysql_error(sock));
"-- Warning: Couldn't get status information for table %s (%s)\n",
result_table,mysql_error(sock));
} }
} }
else if (!(row= mysql_fetch_row(result))) else if (!(row= mysql_fetch_row(result)))
...@@ -2096,9 +2109,7 @@ static void dump_table(char *table, char *db) ...@@ -2096,9 +2109,7 @@ static void dump_table(char *table, char *db)
/* Check --no-data flag */ /* Check --no-data flag */
if (dFlag) if (dFlag)
{ {
if (verbose) verbose_msg("-- Skipping dump data for table '%s', --no-data was used\n",
fprintf(stderr,
"-- Skipping dump data for table '%s', --no-data was used\n",
table); table);
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
...@@ -2112,18 +2123,14 @@ static void dump_table(char *table, char *db) ...@@ -2112,18 +2123,14 @@ static void dump_table(char *table, char *db)
*/ */
if (ignore_flag & IGNORE_DATA) if (ignore_flag & IGNORE_DATA)
{ {
if (verbose) verbose_msg("-- Warning: Skipping data for table '%s' because " \
fprintf(stderr, "it's of type %s\n", table, table_type);
"-- Warning: Skipping data for table '%s' because it's of type %s\n",
table, table_type);
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
/* Check that there are any fields in the table */ /* Check that there are any fields in the table */
if (num_fields == 0) if (num_fields == 0)
{ {
if (verbose) verbose_msg("-- Skipping dump data for table '%s', it has no fields\n",
fprintf(stderr,
"-- Skipping dump data for table '%s', it has no fields\n",
table); table);
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
...@@ -2131,8 +2138,7 @@ static void dump_table(char *table, char *db) ...@@ -2131,8 +2138,7 @@ static void dump_table(char *table, char *db)
result_table= quote_name(table,table_buff, 1); result_table= quote_name(table,table_buff, 1);
opt_quoted_table= quote_name(table, table_buff2, 0); opt_quoted_table= quote_name(table, table_buff2, 0);
if (verbose) verbose_msg("-- Sending SELECT query...\n");
fprintf(stderr, "-- Sending SELECT query...\n");
if (path) if (path)
{ {
char filename[FN_REFLEN], tmp_path[FN_REFLEN]; char filename[FN_REFLEN], tmp_path[FN_REFLEN];
...@@ -2229,8 +2235,8 @@ static void dump_table(char *table, char *db) ...@@ -2229,8 +2235,8 @@ static void dump_table(char *table, char *db)
DB_error(sock, "when retrieving data from server"); DB_error(sock, "when retrieving data from server");
goto err; goto err;
} }
if (verbose)
fprintf(stderr, "-- Retrieving rows...\n"); verbose_msg("-- Retrieving rows...\n");
if (mysql_num_fields(res) != num_fields) if (mysql_num_fields(res) != num_fields)
{ {
fprintf(stderr,"%s: Error in field count for table: %s ! Aborting.\n", fprintf(stderr,"%s: Error in field count for table: %s ! Aborting.\n",
...@@ -3172,10 +3178,8 @@ char check_if_ignore_table(const char *table_name, char *table_type) ...@@ -3172,10 +3178,8 @@ char check_if_ignore_table(const char *table_name, char *table_type)
{ {
if (mysql_errno(sock) != ER_PARSE_ERROR) if (mysql_errno(sock) != ER_PARSE_ERROR)
{ /* If old MySQL version */ { /* If old MySQL version */
if (verbose) verbose_msg("-- Warning: Couldn't get status information for " \
fprintf(stderr, "table %s (%s)\n", table_name,mysql_error(sock));
"-- Warning: Couldn't get status information for table %s (%s)\n",
table_name,mysql_error(sock));
DBUG_RETURN(result); /* assume table is ok */ DBUG_RETURN(result); /* assume table is ok */
} }
} }
...@@ -3361,8 +3365,7 @@ static my_bool get_view_structure(char *table, char* db) ...@@ -3361,8 +3365,7 @@ static my_bool get_view_structure(char *table, char* db)
if (tFlag) /* Don't write table creation info */ if (tFlag) /* Don't write table creation info */
DBUG_RETURN(0); DBUG_RETURN(0);
if (verbose) verbose_msg("-- Retrieving view structure for table %s...\n", table);
fprintf(stderr, "-- Retrieving view structure for table %s...\n", table);
#ifdef NOT_REALLY_USED_YET #ifdef NOT_REALLY_USED_YET
sprintf(insert_pat,"SET OPTION SQL_QUOTE_SHOW_CREATE=%d", sprintf(insert_pat,"SET OPTION SQL_QUOTE_SHOW_CREATE=%d",
...@@ -3383,8 +3386,7 @@ static my_bool get_view_structure(char *table, char* db) ...@@ -3383,8 +3386,7 @@ static my_bool get_view_structure(char *table, char* db)
field= mysql_fetch_field_direct(table_res, 0); field= mysql_fetch_field_direct(table_res, 0);
if (strcmp(field->name, "View") != 0) if (strcmp(field->name, "View") != 0)
{ {
if (verbose) verbose_msg("-- It's base table, skipped\n");
fprintf(stderr, "-- It's base table, skipped\n");
DBUG_RETURN(0); DBUG_RETURN(0);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment