summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
authorunknown <rburnett@bk-internal.mysql.com>2006-08-04 19:19:26 +0200
committerunknown <rburnett@bk-internal.mysql.com>2006-08-04 19:19:26 +0200
commitd166ede9a3d6637ab95d30b12ec834cf77433942 (patch)
treeb49598e9c6be40ecbc029786563289b786dec5bb /client
parent6017f911e33c3a44e6b7b090215446300c38b7be (diff)
parentcc10958f4984a5fa85956c1de245dc93cb73a43f (diff)
downloadmariadb-git-d166ede9a3d6637ab95d30b12ec834cf77433942.tar.gz
Merge bk-internal.mysql.com:/data0/bk/mysql-5.0
into bk-internal.mysql.com:/data0/bk/mysql-5.0-kt client/mysql.cc: Auto merged mysql-test/r/gis.result: Auto merged
Diffstat (limited to 'client')
-rw-r--r--client/Makefile.am4
-rw-r--r--client/mysql.cc5
-rw-r--r--client/mysqlcheck.c16
-rw-r--r--client/mysqldump.c310
-rw-r--r--client/mysqlimport.c2
-rw-r--r--client/mysqlshow.c27
-rw-r--r--client/mysqltest.c10
7 files changed, 213 insertions, 161 deletions
diff --git a/client/Makefile.am b/client/Makefile.am
index 5787905fd35..b80357f68ea 100644
--- a/client/Makefile.am
+++ b/client/Makefile.am
@@ -47,7 +47,9 @@ mysqltestmanager_pwgen_SOURCES = mysqlmanager-pwgen.c
mysqltestmanagerc_SOURCES= mysqlmanagerc.c $(yassl_dummy_link_fix)
mysqlcheck_SOURCES= mysqlcheck.c $(yassl_dummy_link_fix)
mysqlshow_SOURCES= mysqlshow.c $(yassl_dummy_link_fix)
-mysqldump_SOURCES= mysqldump.c my_user.c $(yassl_dummy_link_fix)
+mysqldump_SOURCES= mysqldump.c my_user.c \
+ $(top_srcdir)/mysys/mf_getdate.c \
+ $(yassl_dummy_link_fix)
mysqlimport_SOURCES= mysqlimport.c $(yassl_dummy_link_fix)
mysql_upgrade_SOURCES= mysql_upgrade.c $(yassl_dummy_link_fix)
sql_src=log_event.h mysql_priv.h log_event.cc my_decimal.h my_decimal.cc
diff --git a/client/mysql.cc b/client/mysql.cc
index 921804a1298..f6dda84b1bb 100644
--- a/client/mysql.cc
+++ b/client/mysql.cc
@@ -2859,7 +2859,7 @@ com_connect(String *buffer, char *line)
bzero(buff, sizeof(buff));
if (buffer)
{
- strmov(buff, line);
+ strmake(buff, line, sizeof(buff));
tmp= get_arg(buff, 0);
if (tmp && *tmp)
{
@@ -3727,6 +3727,9 @@ static const char* construct_prompt()
case 't':
processed_prompt.append('\t');
break;
+ case 'l':
+ processed_prompt.append(delimiter_str);
+ break;
default:
processed_prompt.append(c);
}
diff --git a/client/mysqlcheck.c b/client/mysqlcheck.c
index 804fa14956f..5d87a4fd23c 100644
--- a/client/mysqlcheck.c
+++ b/client/mysqlcheck.c
@@ -458,7 +458,7 @@ static int process_all_tables_in_db(char *database)
LINT_INIT(res);
if (use_db(database))
return 1;
- if (mysql_query(sock, "SHOW TABLES") ||
+ if (mysql_query(sock, "SHOW TABLE STATUS") ||
!((res= mysql_store_result(sock))))
return 1;
@@ -484,8 +484,12 @@ static int process_all_tables_in_db(char *database)
}
for (end = tables + 1; (row = mysql_fetch_row(res)) ;)
{
- end= fix_table_name(end, row[0]);
- *end++= ',';
+ /* Skip tables with an engine of NULL (probably a view). */
+ if (row[1])
+ {
+ end= fix_table_name(end, row[0]);
+ *end++= ',';
+ }
}
*--end = 0;
if (tot_length)
@@ -495,7 +499,11 @@ static int process_all_tables_in_db(char *database)
else
{
while ((row = mysql_fetch_row(res)))
- handle_request_for_tables(row[0], strlen(row[0]));
+ /* Skip tables with an engine of NULL (probably a view). */
+ if (row[1])
+ {
+ handle_request_for_tables(row[0], strlen(row[0]));
+ }
}
mysql_free_result(res);
return 0;
diff --git a/client/mysqldump.c b/client/mysqldump.c
index e3c13bb0451..5ecf334c9f7 100644
--- a/client/mysqldump.c
+++ b/client/mysqldump.c
@@ -83,7 +83,8 @@ static ulong find_set(TYPELIB *lib, const char *x, uint length,
static char *alloc_query_str(ulong size);
static char *field_escape(char *to,const char *from,uint length);
-static my_bool verbose=0,tFlag=0,dFlag=0,quick= 1, extended_insert= 1,
+static my_bool verbose= 0, opt_no_create_info= 0, opt_no_data= 0,
+ quick= 1, extended_insert= 1,
lock_tables=1,ignore_errors=0,flush_logs=0,
opt_drop=1,opt_keywords=0,opt_lock=1,opt_compress=0,
opt_delayed=0,create_options=1,opt_quoted=0,opt_databases=0,
@@ -96,7 +97,7 @@ static my_bool verbose=0,tFlag=0,dFlag=0,quick= 1, extended_insert= 1,
opt_complete_insert= 0, opt_drop_database= 0,
opt_dump_triggers= 0, opt_routines=0, opt_tz_utc=1;
static ulong opt_max_allowed_packet, opt_net_buffer_length;
-static MYSQL mysql_connection,*sock=0;
+static MYSQL mysql_connection,*mysql=0;
static my_bool insert_pat_inited=0;
static DYNAMIC_STRING insert_pat;
static char *opt_password=0,*current_user=0,
@@ -312,9 +313,10 @@ static struct my_option my_long_options[] =
(gptr*) &opt_create_db, (gptr*) &opt_create_db, 0, GET_BOOL, NO_ARG, 0, 0,
0, 0, 0, 0},
{"no-create-info", 't', "Don't write table creation info.",
- (gptr*) &tFlag, (gptr*) &tFlag, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
- {"no-data", 'd', "No row information.", (gptr*) &dFlag, (gptr*) &dFlag, 0,
- GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
+ (gptr*) &opt_no_create_info, (gptr*) &opt_no_create_info, 0, GET_BOOL,
+ NO_ARG, 0, 0, 0, 0, 0, 0},
+ {"no-data", 'd', "No row information.", (gptr*) &opt_no_data,
+ (gptr*) &opt_no_data, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"no-set-names", 'N',
"Deprecated. Use --skip-set-charset instead.",
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
@@ -427,6 +429,30 @@ static my_bool dump_all_views_in_db(char *database);
#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)
SYNOPSIS
@@ -565,6 +591,13 @@ static void write_footer(FILE *sql_file)
fprintf(sql_file,
"/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;\n");
fputs("\n", sql_file);
+ if (opt_comments)
+ {
+ char time_str[20];
+ get_date(time_str, GETDATE_DATE_TIME, 0);
+ fprintf(sql_file, "-- Dump completed on %s\n",
+ time_str);
+ }
check_io(sql_file);
}
} /* write_footer */
@@ -844,9 +877,9 @@ static int mysql_query_with_error_report(MYSQL *mysql_con, MYSQL_RES **res,
if (mysql_query(mysql_con, query) ||
(res && !((*res)= mysql_store_result(mysql_con))))
{
- my_printf_error(0, "%s: Couldn't execute '%s': %s (%d)",
- MYF(0), my_progname, query,
- mysql_error(mysql_con), mysql_errno(mysql_con));
+ my_printf_error(0, "Couldn't execute '%s': %s (%d)", MYF(0),
+ query, mysql_error(mysql_con), mysql_errno(mysql_con));
+ safe_exit(EX_MYSQLERR);
return 1;
}
return 0;
@@ -880,8 +913,8 @@ static void safe_exit(int error)
first_error= error;
if (ignore_errors)
return;
- if (sock)
- mysql_close(sock);
+ if (mysql)
+ mysql_close(mysql);
exit(error);
}
/* safe_exit */
@@ -894,10 +927,8 @@ static int dbConnect(char *host, char *user,char *passwd)
{
char buff[20+FN_REFLEN];
DBUG_ENTER("dbConnect");
- if (verbose)
- {
- fprintf(stderr, "-- Connecting to %s...\n", host ? host : "localhost");
- }
+
+ verbose_msg("-- Connecting to %s...\n", host ? host : "localhost");
mysql_init(&mysql_connection);
if (opt_compress)
mysql_options(&mysql_connection,MYSQL_OPT_COMPRESS,NullS);
@@ -915,7 +946,7 @@ static int dbConnect(char *host, char *user,char *passwd)
mysql_options(&mysql_connection,MYSQL_SHARED_MEMORY_BASE_NAME,shared_memory_base_name);
#endif
mysql_options(&mysql_connection, MYSQL_SET_CHARSET_NAME, default_charset);
- if (!(sock= mysql_real_connect(&mysql_connection,host,user,passwd,
+ if (!(mysql= mysql_real_connect(&mysql_connection,host,user,passwd,
NULL,opt_mysql_port,opt_mysql_unix_port,
0)))
{
@@ -931,12 +962,11 @@ static int dbConnect(char *host, char *user,char *passwd)
As we're going to set SQL_MODE, it would be lost on reconnect, so we
cannot reconnect.
*/
- sock->reconnect= 0;
+ mysql->reconnect= 0;
my_snprintf(buff, sizeof(buff), "/*!40100 SET @@SQL_MODE='%s' */",
compatible_mode_normal_str);
- if (mysql_query_with_error_report(sock, 0, buff))
+ if (mysql_query_with_error_report(mysql, 0, buff))
{
- mysql_close(sock);
safe_exit(EX_MYSQLERR);
return 1;
}
@@ -947,9 +977,8 @@ static int dbConnect(char *host, char *user,char *passwd)
if (opt_tz_utc)
{
my_snprintf(buff, sizeof(buff), "/*!40103 SET TIME_ZONE='+00:00' */");
- if (mysql_query_with_error_report(sock, 0, buff))
+ if (mysql_query_with_error_report(mysql, 0, buff))
{
- mysql_close(sock);
safe_exit(EX_MYSQLERR);
return 1;
}
@@ -963,9 +992,8 @@ static int dbConnect(char *host, char *user,char *passwd)
*/
static void dbDisconnect(char *host)
{
- if (verbose)
- fprintf(stderr, "-- Disconnecting from %s...\n", host ? host : "localhost");
- mysql_close(sock);
+ verbose_msg("-- Disconnecting from %s...\n", host ? host : "localhost");
+ mysql_close(mysql);
} /* dbDisconnect */
@@ -1258,7 +1286,7 @@ static uint dump_routines_for_db(char *db)
DBUG_ENTER("dump_routines_for_db");
DBUG_PRINT("enter", ("db: '%s'", db));
- mysql_real_escape_string(sock, db_name_buff, db, strlen(db));
+ mysql_real_escape_string(mysql, db_name_buff, db, strlen(db));
/* nice comments */
if (opt_comments)
@@ -1269,7 +1297,7 @@ static uint dump_routines_for_db(char *db)
enough privileges to lock mysql.proc.
*/
if (lock_tables)
- mysql_query(sock, "LOCK TABLES mysql.proc READ");
+ mysql_query(mysql, "LOCK TABLES mysql.proc READ");
fprintf(sql_file, "DELIMITER ;;\n");
@@ -1280,7 +1308,7 @@ static uint dump_routines_for_db(char *db)
"SHOW %s STATUS WHERE Db = '%s'",
routine_type[i], db_name_buff);
- if (mysql_query_with_error_report(sock, &routine_list_res, query_buff))
+ if (mysql_query_with_error_report(mysql, &routine_list_res, query_buff))
DBUG_RETURN(1);
if (mysql_num_rows(routine_list_res))
@@ -1294,7 +1322,7 @@ static uint dump_routines_for_db(char *db)
my_snprintf(query_buff, sizeof(query_buff), "SHOW CREATE %s %s",
routine_type[i], routine_name);
- if (mysql_query_with_error_report(sock, &routine_res, query_buff))
+ if (mysql_query_with_error_report(mysql, &routine_res, query_buff))
DBUG_RETURN(1);
while ((row= mysql_fetch_row(routine_res)))
@@ -1376,7 +1404,7 @@ static uint dump_routines_for_db(char *db)
fprintf(sql_file, "DELIMITER ;\n");
if (lock_tables)
- VOID(mysql_query_with_error_report(sock, 0, "UNLOCK TABLES"));
+ VOID(mysql_query_with_error_report(mysql, 0, "UNLOCK TABLES"));
DBUG_RETURN(0);
}
@@ -1418,10 +1446,8 @@ static uint get_table_structure(char *table, char *db, char *table_type,
if (delayed && (*ignore_flag & IGNORE_INSERT_DELAYED))
{
delayed= 0;
- if (verbose)
- fprintf(stderr,
- "-- Warning: Unable to use delayed inserts for table '%s' "
- "because it's of type %s\n", table, table_type);
+ verbose_msg("-- Warning: Unable to use delayed inserts for table '%s' "
+ "because it's of type %s\n", table, table_type);
}
complete_insert= 0;
@@ -1437,8 +1463,7 @@ static uint get_table_structure(char *table, char *db, char *table_type,
insert_option= ((delayed && opt_ignore) ? " DELAYED IGNORE " :
delayed ? " DELAYED " : opt_ignore ? " IGNORE " : "");
- if (verbose)
- fprintf(stderr, "-- Retrieving table structure for table %s...\n", table);
+ verbose_msg("-- Retrieving table structure for table %s...\n", table);
len= my_snprintf(query_buff, sizeof(query_buff),
"SET OPTION SQL_QUOTE_SHOW_CREATE=%d",
@@ -1453,17 +1478,17 @@ static uint get_table_structure(char *table, char *db, char *table_type,
if (opt_order_by_primary)
order_by = primary_key_fields(result_table);
- if (!opt_xml && !mysql_query_with_error_report(sock, 0, query_buff))
+ if (!opt_xml && !mysql_query_with_error_report(mysql, 0, query_buff))
{
/* using SHOW CREATE statement */
- if (!tFlag)
+ if (!opt_no_create_info)
{
/* Make an sql-file, if path was given iow. option -T was given */
char buff[20+FN_REFLEN];
MYSQL_FIELD *field;
my_snprintf(buff, sizeof(buff), "show create table %s", result_table);
- if (mysql_query_with_error_report(sock, 0, buff))
+ if (mysql_query_with_error_report(mysql, 0, buff))
{
safe_exit(EX_MYSQLERR);
DBUG_RETURN(0);
@@ -1499,14 +1524,13 @@ static uint get_table_structure(char *table, char *db, char *table_type,
check_io(sql_file);
}
- result= mysql_store_result(sock);
+ result= mysql_store_result(mysql);
field= mysql_fetch_field_direct(result, 0);
if (strcmp(field->name, "View") == 0)
{
char *scv_buff = NULL;
- if (verbose)
- fprintf(stderr, "-- It's a view, create dummy table for view\n");
+ verbose_msg("-- It's a view, create dummy table for view\n");
/* save "show create" statement for later */
if ((row= mysql_fetch_row(result)) && (scv_buff=row[1]))
@@ -1527,7 +1551,7 @@ static uint get_table_structure(char *table, char *db, char *table_type,
*/
my_snprintf(query_buff, sizeof(query_buff),
"SHOW FIELDS FROM %s", result_table);
- if (mysql_query_with_error_report(sock, 0, query_buff))
+ if (mysql_query_with_error_report(mysql, 0, query_buff))
{
/*
View references invalid or privileged table/col/fun (err 1356),
@@ -1535,7 +1559,7 @@ static uint get_table_structure(char *table, char *db, char *table_type,
a comment with the view's 'show create' statement. (Bug #17371)
*/
- if (mysql_errno(sock) == ER_VIEW_INVALID)
+ if (mysql_errno(mysql) == ER_VIEW_INVALID)
fprintf(sql_file, "\n-- failed on view %s: %s\n\n", result_table, scv_buff ? scv_buff : "");
my_free(scv_buff, MYF(MY_ALLOW_ZERO_PTR));
@@ -1546,7 +1570,7 @@ static uint get_table_structure(char *table, char *db, char *table_type,
else
my_free(scv_buff, MYF(MY_ALLOW_ZERO_PTR));
- if ((result= mysql_store_result(sock)))
+ if ((result= mysql_store_result(mysql)))
{
if (mysql_num_rows(result))
{
@@ -1599,7 +1623,7 @@ static uint get_table_structure(char *table, char *db, char *table_type,
}
my_snprintf(query_buff, sizeof(query_buff), "show fields from %s",
result_table);
- if (mysql_query_with_error_report(sock, &result, query_buff))
+ if (mysql_query_with_error_report(mysql, &result, query_buff))
{
if (path)
my_fclose(sql_file, MYF(MY_WME));
@@ -1649,21 +1673,19 @@ static uint get_table_structure(char *table, char *db, char *table_type,
}
else
{
- if (verbose)
- fprintf(stderr,
- "%s: Warning: Can't set SQL_QUOTE_SHOW_CREATE option (%s)\n",
- my_progname, mysql_error(sock));
+ verbose_msg("%s: Warning: Can't set SQL_QUOTE_SHOW_CREATE option (%s)\n",
+ my_progname, mysql_error(mysql));
my_snprintf(query_buff, sizeof(query_buff), "show fields from %s",
result_table);
- if (mysql_query_with_error_report(sock, &result, query_buff))
+ if (mysql_query_with_error_report(mysql, &result, query_buff))
{
safe_exit(EX_MYSQLERR);
DBUG_RETURN(0);
}
/* Make an sql-file, if path was given iow. option -T was given */
- if (!tFlag)
+ if (!opt_no_create_info)
{
if (path)
{
@@ -1707,7 +1729,7 @@ static uint get_table_structure(char *table, char *db, char *table_type,
ulong *lengths= mysql_fetch_lengths(result);
if (init)
{
- if (!opt_xml && !tFlag)
+ if (!opt_xml && !opt_no_create_info)
{
fputs(",\n",sql_file);
check_io(sql_file);
@@ -1719,7 +1741,7 @@ static uint get_table_structure(char *table, char *db, char *table_type,
if (opt_complete_insert)
dynstr_append(&insert_pat,
quote_name(row[SHOW_FIELDNAME], name_buff, 0));
- if (!tFlag)
+ if (!opt_no_create_info)
{
if (opt_xml)
{
@@ -1749,22 +1771,22 @@ static uint get_table_structure(char *table, char *db, char *table_type,
}
num_fields= mysql_num_rows(result);
mysql_free_result(result);
- if (!tFlag)
+ if (!opt_no_create_info)
{
/* Make an sql-file, if path was given iow. option -T was given */
char buff[20+FN_REFLEN];
uint keynr,primary_key;
my_snprintf(buff, sizeof(buff), "show keys from %s", result_table);
- if (mysql_query_with_error_report(sock, &result, buff))
+ if (mysql_query_with_error_report(mysql, &result, buff))
{
- if (mysql_errno(sock) == ER_WRONG_OBJECT)
+ if (mysql_errno(mysql) == ER_WRONG_OBJECT)
{
/* it is VIEW */
fputs("\t\t<options Comment=\"view\" />\n", sql_file);
goto continue_xml;
}
fprintf(stderr, "%s: Can't get keys for table %s (%s)\n",
- my_progname, result_table, mysql_error(sock));
+ my_progname, result_table, mysql_error(mysql));
if (path)
my_fclose(sql_file, MYF(MY_WME));
safe_exit(EX_MYSQLERR);
@@ -1837,21 +1859,19 @@ static uint get_table_structure(char *table, char *db, char *table_type,
my_snprintf(buff, sizeof(buff), "show table status like %s",
quote_for_like(table, show_name_buff));
- if (mysql_query_with_error_report(sock, &result, buff))
+ if (mysql_query_with_error_report(mysql, &result, buff))
{
- if (mysql_errno(sock) != ER_PARSE_ERROR)
+ if (mysql_errno(mysql) != ER_PARSE_ERROR)
{ /* If old MySQL version */
- if (verbose)
- fprintf(stderr,
- "-- Warning: Couldn't get status information for table %s (%s)\n",
- result_table,mysql_error(sock));
+ verbose_msg("-- Warning: Couldn't get status information for " \
+ "table %s (%s)\n", result_table,mysql_error(mysql));
}
}
else if (!(row= mysql_fetch_row(result)))
{
fprintf(stderr,
"Error: Couldn't read status information for table %s (%s)\n",
- result_table,mysql_error(sock));
+ result_table,mysql_error(mysql));
}
else
{
@@ -1924,7 +1944,7 @@ static void dump_triggers_for_table (char *table, char *db)
"SHOW TRIGGERS LIKE %s",
quote_for_like(table, name_buff));
- if (mysql_query_with_error_report(sock, &result, query_buff))
+ if (mysql_query_with_error_report(mysql, &result, query_buff))
{
if (path)
my_fclose(sql_file, MYF(MY_WME));
@@ -2094,12 +2114,10 @@ static void dump_table(char *table, char *db)
return;
/* Check --no-data flag */
- if (dFlag)
+ if (opt_no_data)
{
- if (verbose)
- fprintf(stderr,
- "-- Skipping dump data for table '%s', --no-data was used\n",
- table);
+ verbose_msg("-- Skipping dump data for table '%s', --no-data was used\n",
+ table);
DBUG_VOID_RETURN;
}
@@ -2112,27 +2130,22 @@ static void dump_table(char *table, char *db)
*/
if (ignore_flag & IGNORE_DATA)
{
- if (verbose)
- fprintf(stderr,
- "-- Warning: Skipping data for table '%s' because it's of type %s\n",
- table, table_type);
+ verbose_msg("-- Warning: Skipping data for table '%s' because " \
+ "it's of type %s\n", table, table_type);
DBUG_VOID_RETURN;
}
/* Check that there are any fields in the table */
if (num_fields == 0)
{
- if (verbose)
- fprintf(stderr,
- "-- Skipping dump data for table '%s', it has no fields\n",
- table);
+ verbose_msg("-- Skipping dump data for table '%s', it has no fields\n",
+ table);
DBUG_VOID_RETURN;
}
result_table= quote_name(table,table_buff, 1);
opt_quoted_table= quote_name(table, table_buff2, 0);
- if (verbose)
- fprintf(stderr, "-- Sending SELECT query...\n");
+ verbose_msg("-- Sending SELECT query...\n");
if (path)
{
char filename[FN_REFLEN], tmp_path[FN_REFLEN];
@@ -2170,9 +2183,9 @@ static void dump_table(char *table, char *db)
if (order_by)
end = strxmov(end, " ORDER BY ", order_by, NullS);
}
- if (mysql_real_query(sock, query, (uint) (end - query)))
+ if (mysql_real_query(mysql, query, (uint) (end - query)))
{
- DB_error(sock, "when executing 'SELECT INTO OUTFILE'");
+ DB_error(mysql, "when executing 'SELECT INTO OUTFILE'");
DBUG_VOID_RETURN;
}
}
@@ -2218,19 +2231,19 @@ static void dump_table(char *table, char *db)
fputs("\n", md_result_file);
check_io(md_result_file);
}
- if (mysql_query_with_error_report(sock, 0, query))
- DB_error(sock, "when retrieving data from server");
+ if (mysql_query_with_error_report(mysql, 0, query))
+ DB_error(mysql, "when retrieving data from server");
if (quick)
- res=mysql_use_result(sock);
+ res=mysql_use_result(mysql);
else
- res=mysql_store_result(sock);
+ res=mysql_store_result(mysql);
if (!res)
{
- DB_error(sock, "when retrieving data from server");
+ DB_error(mysql, "when retrieving data from server");
goto err;
}
- if (verbose)
- fprintf(stderr, "-- Retrieving rows...\n");
+
+ verbose_msg("-- Retrieving rows...\n");
if (mysql_num_fields(res) != num_fields)
{
fprintf(stderr,"%s: Error in field count for table: %s ! Aborting.\n",
@@ -2499,13 +2512,13 @@ static void dump_table(char *table, char *db)
fputs(";\n", md_result_file); /* If not empty table */
fflush(md_result_file);
check_io(md_result_file);
- if (mysql_errno(sock))
+ if (mysql_errno(mysql))
{
my_snprintf(query, QUERY_LENGTH,
"%s: Error %d: %s when dumping table %s at row: %ld\n",
my_progname,
- mysql_errno(sock),
- mysql_error(sock),
+ mysql_errno(mysql),
+ mysql_error(mysql),
result_table,
rownr);
fputs(query,stderr);
@@ -2551,7 +2564,7 @@ static char *getTableName(int reset)
if (!res)
{
- if (!(res = mysql_list_tables(sock,NullS)))
+ if (!(res = mysql_list_tables(mysql,NullS)))
return(NULL);
}
if ((row = mysql_fetch_row(res)))
@@ -2574,7 +2587,7 @@ static int dump_all_databases()
MYSQL_RES *tableres;
int result=0;
- if (mysql_query_with_error_report(sock, &tableres, "SHOW DATABASES"))
+ if (mysql_query_with_error_report(mysql, &tableres, "SHOW DATABASES"))
return 1;
while ((row = mysql_fetch_row(tableres)))
{
@@ -2583,11 +2596,11 @@ static int dump_all_databases()
}
if (seen_views)
{
- if (mysql_query(sock, "SHOW DATABASES") ||
- !(tableres = mysql_store_result(sock)))
+ if (mysql_query(mysql, "SHOW DATABASES") ||
+ !(tableres = mysql_store_result(mysql)))
{
my_printf_error(0, "Error: Couldn't execute 'SHOW DATABASES': %s",
- MYF(0), mysql_error(sock));
+ MYF(0), mysql_error(mysql));
return 1;
}
while ((row = mysql_fetch_row(tableres)))
@@ -2624,13 +2637,13 @@ static int dump_databases(char **db_names)
static int init_dumping(char *database)
{
- if (mysql_get_server_version(sock) >= 50003 &&
+ if (mysql_get_server_version(mysql) >= 50003 &&
!my_strcasecmp(&my_charset_latin1, database, "information_schema"))
return 1;
- if (mysql_select_db(sock, database))
+ if (mysql_select_db(mysql, database))
{
- DB_error(sock, "when selecting the database");
+ DB_error(mysql, "when selecting the database");
return 1; /* If --force */
}
if (!path && !opt_xml)
@@ -2657,7 +2670,7 @@ static int init_dumping(char *database)
"SHOW CREATE DATABASE IF NOT EXISTS %s",
qdatabase);
- if (mysql_query(sock, qbuf) || !(dbinfo = mysql_store_result(sock)))
+ if (mysql_query(mysql, qbuf) || !(dbinfo = mysql_store_result(mysql)))
{
/* Old server version, dump generic CREATE DATABASE */
if (opt_drop_database)
@@ -2725,15 +2738,15 @@ static int dump_all_tables_in_db(char *database)
dynstr_append(&query, quote_name(table, table_buff, 1));
dynstr_append(&query, " READ /*!32311 LOCAL */,");
}
- if (numrows && mysql_real_query(sock, query.str, query.length-1))
- DB_error(sock, "when using LOCK TABLES");
+ if (numrows && mysql_real_query(mysql, query.str, query.length-1))
+ DB_error(mysql, "when using LOCK TABLES");
/* We shall continue here, if --force was given */
dynstr_free(&query);
}
if (flush_logs)
{
- if (mysql_refresh(sock, REFRESH_LOG))
- DB_error(sock, "when doing refresh");
+ if (mysql_refresh(mysql, REFRESH_LOG))
+ DB_error(mysql, "when doing refresh");
/* We shall continue here, if --force was given */
}
while ((table= getTableName(0)))
@@ -2745,12 +2758,12 @@ static int dump_all_tables_in_db(char *database)
my_free(order_by, MYF(MY_ALLOW_ZERO_PTR));
order_by= 0;
if (opt_dump_triggers && ! opt_xml &&
- mysql_get_server_version(sock) >= 50009)
+ mysql_get_server_version(mysql) >= 50009)
dump_triggers_for_table(table, database);
}
}
if (opt_routines && !opt_xml &&
- mysql_get_server_version(sock) >= 50009)
+ mysql_get_server_version(mysql) >= 50009)
{
DBUG_PRINT("info", ("Dumping routines for database %s", database));
dump_routines_for_db(database);
@@ -2761,7 +2774,7 @@ static int dump_all_tables_in_db(char *database)
check_io(md_result_file);
}
if (lock_tables)
- VOID(mysql_query_with_error_report(sock, 0, "UNLOCK TABLES"));
+ VOID(mysql_query_with_error_report(mysql, 0, "UNLOCK TABLES"));
return 0;
} /* dump_all_tables_in_db */
@@ -2784,9 +2797,9 @@ static my_bool dump_all_views_in_db(char *database)
uint numrows;
char table_buff[NAME_LEN*2+3];
- if (mysql_select_db(sock, database))
+ if (mysql_select_db(mysql, database))
{
- DB_error(sock, "when selecting the database");
+ DB_error(mysql, "when selecting the database");
return 1;
}
if (opt_databases || opt_alldbs)
@@ -2812,15 +2825,15 @@ static my_bool dump_all_views_in_db(char *database)
dynstr_append(&query, quote_name(table, table_buff, 1));
dynstr_append(&query, " READ /*!32311 LOCAL */,");
}
- if (numrows && mysql_real_query(sock, query.str, query.length-1))
- DB_error(sock, "when using LOCK TABLES");
+ if (numrows && mysql_real_query(mysql, query.str, query.length-1))
+ DB_error(mysql, "when using LOCK TABLES");
/* We shall continue here, if --force was given */
dynstr_free(&query);
}
if (flush_logs)
{
- if (mysql_refresh(sock, REFRESH_LOG))
- DB_error(sock, "when doing refresh");
+ if (mysql_refresh(mysql, REFRESH_LOG))
+ DB_error(mysql, "when doing refresh");
/* We shall continue here, if --force was given */
}
while ((table= getTableName(0)))
@@ -2831,7 +2844,7 @@ static my_bool dump_all_views_in_db(char *database)
check_io(md_result_file);
}
if (lock_tables)
- VOID(mysql_query_with_error_report(sock, 0, "UNLOCK TABLES"));
+ VOID(mysql_query_with_error_report(mysql, 0, "UNLOCK TABLES"));
return 0;
} /* dump_all_tables_in_db */
@@ -2861,12 +2874,12 @@ static char *get_actual_table_name(const char *old_table_name, MEM_ROOT *root)
my_snprintf(query, sizeof(query), "SHOW TABLES LIKE %s",
quote_for_like(old_table_name, show_name_buff));
- if (mysql_query_with_error_report(sock, 0, query))
+ if (mysql_query_with_error_report(mysql, 0, query))
{
safe_exit(EX_MYSQLERR);
}
- if ((table_res= mysql_store_result(sock)))
+ if ((table_res= mysql_store_result(mysql)))
{
my_ulonglong num_rows= mysql_num_rows(table_res);
if (num_rows > 0)
@@ -2928,16 +2941,16 @@ static int dump_selected_tables(char *db, char **table_names, int tables)
if (lock_tables)
{
- if (mysql_real_query(sock, lock_tables_query.str,
+ if (mysql_real_query(mysql, lock_tables_query.str,
lock_tables_query.length-1))
- DB_error(sock, "when doing LOCK TABLES");
+ DB_error(mysql, "when doing LOCK TABLES");
/* We shall countinue here, if --force was given */
}
dynstr_free(&lock_tables_query);
if (flush_logs)
{
- if (mysql_refresh(sock, REFRESH_LOG))
- DB_error(sock, "when doing refresh");
+ if (mysql_refresh(mysql, REFRESH_LOG))
+ DB_error(mysql, "when doing refresh");
/* We shall countinue here, if --force was given */
}
if (opt_xml)
@@ -2949,7 +2962,7 @@ static int dump_selected_tables(char *db, char **table_names, int tables)
DBUG_PRINT("info",("Dumping table %s", *pos));
dump_table(*pos, db);
if (opt_dump_triggers &&
- mysql_get_server_version(sock) >= 50009)
+ mysql_get_server_version(mysql) >= 50009)
dump_triggers_for_table(*pos, db);
}
@@ -2961,7 +2974,7 @@ static int dump_selected_tables(char *db, char **table_names, int tables)
}
/* obtain dump of routines (procs/functions) */
if (opt_routines && !opt_xml &&
- mysql_get_server_version(sock) >= 50009)
+ mysql_get_server_version(mysql) >= 50009)
{
DBUG_PRINT("info", ("Dumping routines for database %s", db));
dump_routines_for_db(db);
@@ -2975,7 +2988,7 @@ static int dump_selected_tables(char *db, char **table_names, int tables)
check_io(md_result_file);
}
if (lock_tables)
- VOID(mysql_query_with_error_report(sock, 0, "UNLOCK TABLES"));
+ VOID(mysql_query_with_error_report(mysql, 0, "UNLOCK TABLES"));
DBUG_RETURN(0);
} /* dump_selected_tables */
@@ -2988,8 +3001,6 @@ static int do_show_master_status(MYSQL *mysql_con)
(opt_master_data == MYSQL_OPT_MASTER_DATA_COMMENTED_SQL) ? "-- " : "";
if (mysql_query_with_error_report(mysql_con, &master, "SHOW MASTER STATUS"))
{
- my_printf_error(0, "Error: Couldn't execute 'SHOW MASTER STATUS': %s",
- MYF(0), mysql_error(mysql_con));
return 1;
}
else
@@ -3160,7 +3171,7 @@ static void print_value(FILE *file, MYSQL_RES *result, MYSQL_ROW row,
table_type Type of table
GLOBAL VARIABLES
- sock MySQL socket
+ mysql MySQL connection
verbose Write warning messages
RETURN
@@ -3179,14 +3190,12 @@ char check_if_ignore_table(const char *table_name, char *table_type)
DBUG_ASSERT(2*sizeof(table_name) < sizeof(show_name_buff));
my_snprintf(buff, sizeof(buff), "show table status like %s",
quote_for_like(table_name, show_name_buff));
- if (mysql_query_with_error_report(sock, &res, buff))
+ if (mysql_query_with_error_report(mysql, &res, buff))
{
- if (mysql_errno(sock) != ER_PARSE_ERROR)
+ if (mysql_errno(mysql) != ER_PARSE_ERROR)
{ /* If old MySQL version */
- if (verbose)
- fprintf(stderr,
- "-- Warning: Couldn't get status information for table %s (%s)\n",
- table_name,mysql_error(sock));
+ verbose_msg("-- Warning: Couldn't get status information for " \
+ "table %s (%s)\n", table_name,mysql_error(mysql));
DBUG_RETURN(result); /* assume table is ok */
}
}
@@ -3194,7 +3203,7 @@ char check_if_ignore_table(const char *table_name, char *table_type)
{
fprintf(stderr,
"Error: Couldn't read status information for table %s (%s)\n",
- table_name, mysql_error(sock));
+ table_name, mysql_error(mysql));
mysql_free_result(res);
DBUG_RETURN(result); /* assume table is ok */
}
@@ -3222,7 +3231,7 @@ char check_if_ignore_table(const char *table_name, char *table_type)
/*
If these two types, we do want to skip dumping the table
*/
- if (!dFlag &&
+ if (!opt_no_data &&
(!strcmp(table_type,"MRG_MyISAM") || !strcmp(table_type,"MRG_ISAM")))
result= IGNORE_DATA;
}
@@ -3230,6 +3239,7 @@ char check_if_ignore_table(const char *table_name, char *table_type)
DBUG_RETURN(result);
}
+
/*
Get string of comma-separated primary key field names
@@ -3259,12 +3269,12 @@ static char *primary_key_fields(const char *table_name)
my_snprintf(show_keys_buff, sizeof(show_keys_buff),
"SHOW KEYS FROM %s", table_name);
- if (mysql_query(sock, show_keys_buff) ||
- !(res = mysql_store_result(sock)))
+ if (mysql_query(mysql, show_keys_buff) ||
+ !(res = mysql_store_result(mysql)))
{
fprintf(stderr, "Warning: Couldn't read keys from table %s;"
" records are NOT sorted (%s)\n",
- table_name, mysql_error(sock));
+ table_name, mysql_error(mysql));
/* Don't exit, because it's better to print out unsorted records */
goto cleanup;
}
@@ -3369,11 +3379,10 @@ static my_bool get_view_structure(char *table, char* db)
FILE *sql_file = md_result_file;
DBUG_ENTER("get_view_structure");
- if (tFlag) /* Don't write table creation info */
+ if (opt_no_create_info) /* Don't write table creation info */
DBUG_RETURN(0);
- if (verbose)
- fprintf(stderr, "-- Retrieving view structure for table %s...\n", table);
+ verbose_msg("-- Retrieving view structure for table %s...\n", table);
#ifdef NOT_REALLY_USED_YET
sprintf(insert_pat,"SET OPTION SQL_QUOTE_SHOW_CREATE=%d",
@@ -3384,7 +3393,7 @@ static my_bool get_view_structure(char *table, char* db)
opt_quoted_table= quote_name(table, table_buff2, 0);
my_snprintf(query, sizeof(query), "SHOW CREATE TABLE %s", result_table);
- if (mysql_query_with_error_report(sock, &table_res, query))
+ if (mysql_query_with_error_report(mysql, &table_res, query))
{
safe_exit(EX_MYSQLERR);
DBUG_RETURN(0);
@@ -3394,8 +3403,7 @@ static my_bool get_view_structure(char *table, char* db)
field= mysql_fetch_field_direct(table_res, 0);
if (strcmp(field->name, "View") != 0)
{
- if (verbose)
- fprintf(stderr, "-- It's base table, skipped\n");
+ verbose_msg("-- It's base table, skipped\n");
DBUG_RETURN(0);
}
@@ -3430,7 +3438,7 @@ static my_bool get_view_structure(char *table, char* db)
"SELECT CHECK_OPTION, DEFINER, SECURITY_TYPE " \
"FROM information_schema.views " \
"WHERE table_name=\"%s\" AND table_schema=\"%s\"", table, db);
- if (mysql_query(sock, query))
+ if (mysql_query(mysql, query))
{
/*
Use the raw output from SHOW CREATE TABLE if
@@ -3456,7 +3464,7 @@ static my_bool get_view_structure(char *table, char* db)
mysql_free_result(table_res);
/* Get the result from "select ... information_schema" */
- if (!(table_res= mysql_store_result(sock)) ||
+ if (!(table_res= mysql_store_result(mysql)) ||
!(row= mysql_fetch_row(table_res)))
{
safe_exit(EX_MYSQLERR);
@@ -3551,21 +3559,21 @@ int main(int argc, char **argv)
write_header(md_result_file, *argv);
if ((opt_lock_all_tables || opt_master_data) &&
- do_flush_tables_read_lock(sock))
+ do_flush_tables_read_lock(mysql))
goto err;
- if (opt_single_transaction && start_transaction(sock, test(opt_master_data)))
+ if (opt_single_transaction && start_transaction(mysql, test(opt_master_data)))
goto err;
- if (opt_delete_master_logs && do_reset_master(sock))
+ if (opt_delete_master_logs && do_reset_master(mysql))
goto err;
if (opt_lock_all_tables || opt_master_data)
{
- if (flush_logs && mysql_refresh(sock, REFRESH_LOG))
+ if (flush_logs && mysql_refresh(mysql, REFRESH_LOG))
goto err;
flush_logs= 0; /* not anymore; that would not be sensible */
}
- if (opt_master_data && do_show_master_status(sock))
+ if (opt_master_data && do_show_master_status(mysql))
goto err;
- if (opt_single_transaction && do_unlock_tables(sock)) /* unlock but no commit! */
+ if (opt_single_transaction && do_unlock_tables(mysql)) /* unlock but no commit! */
goto err;
if (opt_alldbs)
diff --git a/client/mysqlimport.c b/client/mysqlimport.c
index 1f9b96f91be..67659684c9c 100644
--- a/client/mysqlimport.c
+++ b/client/mysqlimport.c
@@ -521,7 +521,7 @@ int main(int argc, char **argv)
return(1); /* purecov: deadcode */
}
- if (mysql_query(sock, "set @@character_set_database=binary;"))
+ if (mysql_query(sock, "/*!40101 set @@character_set_database=binary */;"))
{
db_error(sock); /* We shall countinue here, if --force was given */
return(1);
diff --git a/client/mysqlshow.c b/client/mysqlshow.c
index d090495ff81..40405c53565 100644
--- a/client/mysqlshow.c
+++ b/client/mysqlshow.c
@@ -344,7 +344,7 @@ list_dbs(MYSQL *mysql,const char *wild)
char query[255];
MYSQL_FIELD *field;
MYSQL_RES *result;
- MYSQL_ROW row, rrow;
+ MYSQL_ROW row= NULL, rrow;
if (!(result=mysql_list_dbs(mysql,wild)))
{
@@ -352,6 +352,26 @@ list_dbs(MYSQL *mysql,const char *wild)
mysql_error(mysql));
return 1;
}
+
+ /*
+ If a wildcard was used, but there was only one row and it's name is an
+ exact match, we'll assume they really wanted to see the contents of that
+ database. This is because it is fairly common for database names to
+ contain the underscore (_), like INFORMATION_SCHEMA.
+ */
+ if (wild && mysql_num_rows(result) == 1)
+ {
+ row= mysql_fetch_row(result);
+ if (!my_strcasecmp(&my_charset_latin1, row[0], wild))
+ {
+ mysql_free_result(result);
+ if (opt_status)
+ return list_table_status(mysql, wild, NULL);
+ else
+ return list_tables(mysql, wild, NULL);
+ }
+ }
+
if (wild)
printf("Wildcard: %s\n",wild);
@@ -368,7 +388,8 @@ list_dbs(MYSQL *mysql,const char *wild)
else
print_header(header,length,"Tables",6,"Total Rows",12,NullS);
- while ((row = mysql_fetch_row(result)))
+ /* The first row may have already been read up above. */
+ while (row || (row= mysql_fetch_row(result)))
{
counter++;
@@ -422,6 +443,8 @@ list_dbs(MYSQL *mysql,const char *wild)
print_row(row[0],length,tables,6,NullS);
else
print_row(row[0],length,tables,6,rows,12,NullS);
+
+ row= NULL;
}
print_trailer(length,
diff --git a/client/mysqltest.c b/client/mysqltest.c
index 352971c4c38..549c6e85837 100644
--- a/client/mysqltest.c
+++ b/client/mysqltest.c
@@ -177,7 +177,7 @@ typedef struct
static test_file file_stack[MAX_INCLUDE_DEPTH];
static test_file* cur_file;
static test_file* file_stack_end;
-uint start_lineno; /* Start line of query */
+uint start_lineno= 0; /* Start line of query */
static char TMPDIR[FN_REFLEN];
static char delimiter[MAX_DELIMITER]= DEFAULT_DELIMITER;
@@ -4757,6 +4757,14 @@ int main(int argc, char **argv)
q->require_file=require_file;
save_file[0]=0;
}
+ /*
+ To force something being sent as a query to the mysqld one can
+ use the prefix "query". Remove "query" from string before executing
+ */
+ if (strncmp(q->query, "query ", 6) == 0)
+ {
+ q->query= q->first_argument;
+ }
run_query(&cur_con->mysql, q, flags);
query_executed= 1;
q->last_argument= q->end;