summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
authorNirbhay Choubey <nirbhay@mariadb.com>2015-12-19 14:24:38 -0500
committerNirbhay Choubey <nirbhay@mariadb.com>2015-12-19 14:24:38 -0500
commitdad555a09c8d590132c77c192a18d7fc1f8fe91e (patch)
tree38fb545e5df0a24333b8284c816f5bea95d19a03 /client
parent18173ddfc4081407832d9a6703d1b8356b7defe9 (diff)
parent90ea0145856338221803ebb9b446ed2a6e082412 (diff)
downloadmariadb-git-dad555a09c8d590132c77c192a18d7fc1f8fe91e.tar.gz
Merge tag 'mariadb-10.0.23' into 10.0-galera
Diffstat (limited to 'client')
-rw-r--r--client/mysql.cc2
-rw-r--r--client/mysql_plugin.c10
-rw-r--r--client/mysql_upgrade.c92
-rw-r--r--client/mysqlbinlog.cc38
-rw-r--r--client/mysqldump.c206
-rw-r--r--client/mysqlshow.c47
-rw-r--r--client/mysqlslap.c29
-rw-r--r--client/mysqltest.cc2
8 files changed, 269 insertions, 157 deletions
diff --git a/client/mysql.cc b/client/mysql.cc
index 60bed6b0d6a..71eac780262 100644
--- a/client/mysql.cc
+++ b/client/mysql.cc
@@ -1108,7 +1108,7 @@ inline int get_command_index(char cmd_char)
All client-specific commands are in the first part of commands array
and have a function to implement it.
*/
- for (uint i= 0; *commands[i].func; i++)
+ for (uint i= 0; commands[i].func; i++)
if (commands[i].cmd_char == cmd_char)
return i;
return -1;
diff --git a/client/mysql_plugin.c b/client/mysql_plugin.c
index 034f021109a..ebf04c9a8c3 100644
--- a/client/mysql_plugin.c
+++ b/client/mysql_plugin.c
@@ -1,5 +1,5 @@
/*
- Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
+ Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -404,7 +404,7 @@ exit:
static void usage(void)
{
PRINT_VERSION;
- puts("Copyright (c) 2011, Oracle and/or its affiliates. "
+ puts("Copyright (c) 2011, 2015, Oracle and/or its affiliates. "
"All rights reserved.\n");
puts("Enable or disable plugins.");
printf("\nUsage: %s [options] <plugin> ENABLE|DISABLE\n\nOptions:\n",
@@ -755,6 +755,11 @@ static int check_options(int argc, char **argv, char *operation)
/* read the plugin config file and check for match against argument */
else
{
+ if (strlen(argv[i]) + 4 + 1 > FN_REFLEN)
+ {
+ fprintf(stderr, "ERROR: argument is too long.\n");
+ return 1;
+ }
strcpy(plugin_name, argv[i]);
strcpy(config_file, argv[i]);
strcat(config_file, ".ini");
@@ -846,6 +851,7 @@ static int process_options(int argc, char *argv[], char *operation)
if (opt_basedir[i-1] != FN_LIBCHAR || opt_basedir[i-1] != FN_LIBCHAR2)
{
char buff[FN_REFLEN];
+ memset(buff, 0, sizeof(buff));
strncpy(buff, opt_basedir, sizeof(buff) - 1);
#ifdef __WIN__
diff --git a/client/mysql_upgrade.c b/client/mysql_upgrade.c
index 0dfcd81bdf9..c3240915233 100644
--- a/client/mysql_upgrade.c
+++ b/client/mysql_upgrade.c
@@ -55,6 +55,8 @@ static DYNAMIC_STRING conn_args;
static char *opt_password= 0;
static char *opt_plugin_dir= 0, *opt_default_auth= 0;
+static char *cnf_file_path= 0, defaults_file[FN_REFLEN + 32];
+
static my_bool tty_password= 0;
static char opt_tmpdir[FN_REFLEN] = "";
@@ -111,6 +113,7 @@ static struct my_option my_long_options[]=
&opt_force, &opt_force, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"host", 'h', "Connect to host.", 0,
0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
+#define PASSWORD_OPT 12
{"password", 'p',
"Password to use when connecting to server. If password is not given,"
" it's solicited on the tty.", &opt_password,&opt_password,
@@ -147,6 +150,7 @@ static struct my_option my_long_options[]=
{"upgrade-system-tables", 's', "Only upgrade the system tables in the mysql database. Tables in other databases are not checked or touched.",
&opt_systables_only, &opt_systables_only, 0,
GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
+#define USER_OPT (array_elements(my_long_options) - 6)
{"user", 'u', "User for login if not current user.", &opt_user,
&opt_user, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"verbose", 'v', "Display more output about the process; Using it twice will print connection argument; Using it 3 times will print out all CHECK, RENAME and ALTER TABLE during the check phase.",
@@ -184,6 +188,8 @@ static void free_used_memory(void)
dynstr_free(&ds_args);
dynstr_free(&conn_args);
+ if (cnf_file_path)
+ my_delete(cnf_file_path, MYF(MY_WME));
}
@@ -235,31 +241,32 @@ static void verbose(const char *fmt, ...)
this way we pass the same arguments on to mysql and mysql_check
*/
-static void add_one_option(DYNAMIC_STRING* ds,
- const struct my_option *opt,
- const char* argument)
-
+static void add_one_option_cmd_line(DYNAMIC_STRING *ds,
+ const struct my_option *opt,
+ const char* arg)
{
- const char* eq= NullS;
- const char* arg= NullS;
- if (opt->arg_type != NO_ARG)
+ dynstr_append(ds, "--");
+ dynstr_append(ds, opt->name);
+ if (arg)
{
- eq= "=";
- switch (opt->var_type & GET_TYPE_MASK) {
- case GET_STR:
- arg= argument;
- break;
- case GET_BOOL:
- arg= (*(my_bool *)opt->value) ? "1" : "0";
- break;
- default:
- die("internal error at %s: %d",__FILE__, __LINE__);
- }
+ dynstr_append(ds, "=");
+ dynstr_append_os_quoted(ds, arg, NullS);
}
- dynstr_append_os_quoted(ds, "--", opt->name, eq, arg, NullS);
dynstr_append(ds, " ");
}
+static void add_one_option_cnf_file(DYNAMIC_STRING *ds,
+ const struct my_option *opt,
+ const char* arg)
+{
+ dynstr_append(ds, opt->name);
+ if (arg)
+ {
+ dynstr_append(ds, "=");
+ dynstr_append_os_quoted(ds, arg, NullS);
+ }
+ dynstr_append(ds, "\n");
+}
static my_bool
get_one_option(int optid, const struct my_option *opt,
@@ -290,16 +297,17 @@ get_one_option(int optid, const struct my_option *opt,
case 'p':
if (argument == disabled_my_option)
argument= (char*) ""; /* Don't require password */
- tty_password= 1;
add_option= FALSE;
if (argument)
{
/* Add password to ds_args before overwriting the arg with x's */
- add_one_option(&ds_args, opt, argument);
+ add_one_option_cnf_file(&ds_args, opt, argument);
while (*argument)
*argument++= 'x'; /* Destroy argument */
tty_password= 0;
}
+ else
+ tty_password= 1;
break;
case 't':
@@ -346,18 +354,18 @@ get_one_option(int optid, const struct my_option *opt,
case OPT_SHARED_MEMORY_BASE_NAME: /* --shared-memory-base-name */
case OPT_PLUGIN_DIR: /* --plugin-dir */
case OPT_DEFAULT_AUTH: /* --default-auth */
- add_one_option(&conn_args, opt, argument);
+ add_one_option_cmd_line(&conn_args, opt, argument);
break;
}
if (add_option)
{
/*
- This is an option that is accpted by mysql_upgrade just so
+ This is an option that is accepted by mysql_upgrade just so
it can be passed on to "mysql" and "mysqlcheck"
Save it in the ds_args string
*/
- add_one_option(&ds_args, opt, argument);
+ add_one_option_cnf_file(&ds_args, opt, argument);
}
return 0;
}
@@ -420,11 +428,8 @@ static int run_tool(char *tool_path, DYNAMIC_STRING *ds_res, ...)
while ((arg= va_arg(args, char *)))
{
- /* Options should be os quoted */
- if (strncmp(arg, "--", 2) == 0)
- dynstr_append_os_quoted(&ds_cmdline, arg, NullS);
- else
- dynstr_append(&ds_cmdline, arg);
+ /* Options should already be os quoted */
+ dynstr_append(&ds_cmdline, arg);
dynstr_append(&ds_cmdline, " ");
}
@@ -571,8 +576,7 @@ static int run_query(const char *query, DYNAMIC_STRING *ds_res,
ret= run_tool(mysql_path,
ds_res,
- "--no-defaults",
- ds_args.str,
+ defaults_file,
"--database=mysql",
"--batch", /* Turns off pager etc. */
force ? "--force": "--skip-force",
@@ -764,8 +768,7 @@ static int run_mysqlcheck_upgrade(my_bool mysql_db_only)
print_conn_args("mysqlcheck");
retch= run_tool(mysqlcheck_path,
NULL, /* Send output from mysqlcheck directly to screen */
- "--no-defaults",
- ds_args.str,
+ defaults_file,
"--check-upgrade",
"--auto-repair",
!opt_silent || opt_verbose >= 1 ? "--verbose" : "",
@@ -825,8 +828,7 @@ static int run_mysqlcheck_views(void)
print_conn_args("mysqlcheck");
return run_tool(mysqlcheck_path,
NULL, /* Send output from mysqlcheck directly to screen */
- "--no-defaults",
- ds_args.str,
+ defaults_file,
"--all-databases", "--repair",
upgrade_views,
"--skip-process-tables",
@@ -850,8 +852,7 @@ static int run_mysqlcheck_fixnames(void)
print_conn_args("mysqlcheck");
return run_tool(mysqlcheck_path,
NULL, /* Send output from mysqlcheck directly to screen */
- "--no-defaults",
- ds_args.str,
+ defaults_file,
"--all-databases",
"--fix-db-names",
"--fix-table-names",
@@ -1075,12 +1076,21 @@ int main(int argc, char **argv)
{
opt_password= get_tty_password(NullS);
/* add password to defaults file */
- dynstr_append_os_quoted(&ds_args, "--password=", opt_password, NullS);
- dynstr_append(&ds_args, " ");
+ add_one_option_cnf_file(&ds_args, &my_long_options[PASSWORD_OPT], opt_password);
+ DBUG_ASSERT(strcmp(my_long_options[PASSWORD_OPT].name, "password") == 0);
}
/* add user to defaults file */
- dynstr_append_os_quoted(&ds_args, "--user=", opt_user, NullS);
- dynstr_append(&ds_args, " ");
+ add_one_option_cnf_file(&ds_args, &my_long_options[USER_OPT], opt_user);
+ DBUG_ASSERT(strcmp(my_long_options[USER_OPT].name, "user") == 0);
+
+ cnf_file_path= strmov(defaults_file, "--defaults-file=");
+ {
+ int fd= create_temp_file(cnf_file_path, opt_tmpdir[0] ? opt_tmpdir : NULL,
+ "mysql_upgrade-", O_CREAT | O_WRONLY, MYF(MY_FAE));
+ my_write(fd, USTRING_WITH_LEN( "[client]\n"), MYF(MY_FAE));
+ my_write(fd, (uchar*)ds_args.str, ds_args.length, MYF(MY_FAE));
+ my_close(fd, MYF(0));
+ }
/* Find mysql */
find_tool(mysql_path, IF_WIN("mysql.exe", "mysql"), self_name);
diff --git a/client/mysqlbinlog.cc b/client/mysqlbinlog.cc
index 7a54a693cb4..315fdcd22dc 100644
--- a/client/mysqlbinlog.cc
+++ b/client/mysqlbinlog.cc
@@ -1533,6 +1533,8 @@ static void cleanup()
my_free(host);
my_free(user);
my_free(const_cast<char*>(dirname_for_local_load));
+ my_free(start_datetime_str);
+ my_free(stop_datetime_str);
delete binlog_filter;
delete glob_description_event;
@@ -1719,7 +1721,7 @@ static int parse_args(int *argc, char*** argv)
exit(ho_error);
if (debug_info_flag)
my_end_arg= MY_CHECK_ERROR | MY_GIVE_INFO;
- if (debug_check_flag)
+ else if (debug_check_flag)
my_end_arg= MY_CHECK_ERROR;
return 0;
}
@@ -2044,6 +2046,7 @@ static Exit_status dump_remote_log_entries(PRINT_EVENT_INFO *print_event_info,
if ((rev->ident_len != logname_len) ||
memcmp(rev->new_log_ident, logname, logname_len))
{
+ delete ev;
DBUG_RETURN(OK_CONTINUE);
}
/*
@@ -2052,6 +2055,7 @@ static Exit_status dump_remote_log_entries(PRINT_EVENT_INFO *print_event_info,
log. If we are running with to_last_remote_log, we print it,
because it serves as a useful marker between binlogs then.
*/
+ delete ev;
continue;
}
len= 1; // fake Rotate, so don't increment old_off
@@ -2082,7 +2086,9 @@ static Exit_status dump_remote_log_entries(PRINT_EVENT_INFO *print_event_info,
Exit_status retval;
if ((file= load_processor.prepare_new_file_for_old_format(le,fname)) < 0)
+ {
DBUG_RETURN(ERROR_STOP);
+ }
retval= process_event(print_event_info, ev, old_off, logname);
if (retval != OK_CONTINUE)
@@ -2450,23 +2456,23 @@ int main(int argc, char** argv)
if (load_defaults("my", load_groups, &argc, &argv))
exit(1);
+ defaults_argv= argv;
+
if (!(binlog_filter= new Rpl_filter))
{
error("Failed to create Rpl_filter");
- exit(1);
+ goto err;
}
- defaults_argv= argv;
parse_args(&argc, (char***)&argv);
if (!argc || opt_version)
{
if (!argc)
usage();
- cleanup();
- free_defaults(defaults_argv);
- my_end(my_end_arg);
- exit(!opt_version);
+ if (!opt_version)
+ retval= ERROR_STOP;
+ goto err;
}
if (opt_base64_output_mode == BASE64_OUTPUT_UNSPEC)
@@ -2486,12 +2492,18 @@ int main(int argc, char** argv)
if (!dirname_for_local_load)
{
if (init_tmpdir(&tmpdir, 0))
- exit(1);
+ {
+ retval= ERROR_STOP;
+ goto err;
+ }
dirname_for_local_load= my_strdup(my_tmpdir(&tmpdir), MY_WME);
}
if (load_processor.init())
- exit(1);
+ {
+ retval= ERROR_STOP;
+ goto err;
+ }
if (dirname_for_local_load)
load_processor.init_by_dir_name(dirname_for_local_load);
else
@@ -2561,12 +2573,20 @@ int main(int argc, char** argv)
free_defaults(defaults_argv);
my_free_open_file_info();
load_processor.destroy();
+ mysql_server_end();
/* We cannot free DBUG, it is used in global destructors after exit(). */
my_end(my_end_arg | MY_DONT_FREE_DBUG);
exit(retval == ERROR_STOP ? 1 : 0);
/* Keep compilers happy. */
DBUG_RETURN(retval == ERROR_STOP ? 1 : 0);
+
+err:
+ cleanup();
+ free_defaults(defaults_argv);
+ my_end(my_end_arg);
+ exit(retval == ERROR_STOP ? 1 : 0);
+ DBUG_RETURN(retval == ERROR_STOP ? 1 : 0);
}
diff --git a/client/mysqldump.c b/client/mysqldump.c
index e4683ab79c4..e41305d7c07 100644
--- a/client/mysqldump.c
+++ b/client/mysqldump.c
@@ -1,6 +1,6 @@
/*
Copyright (c) 2000, 2013, Oracle and/or its affiliates.
- Copyright (c) 2010, 2013, Monty Program Ab.
+ Copyright (c) 2010, 2015, Monty Program Ab.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -148,6 +148,12 @@ static int first_error=0;
*/
static uint multi_source= 0;
static DYNAMIC_STRING extended_row;
+static DYNAMIC_STRING dynamic_where;
+static MYSQL_RES *get_table_name_result= NULL;
+static MEM_ROOT glob_root;
+static MYSQL_RES *routine_res, *routine_list_res;
+
+
#include <sslopt-vars.h>
FILE *md_result_file= 0;
FILE *stderror_file=0;
@@ -1138,16 +1144,14 @@ static int fetch_db_collation(const char *db_name,
int db_cl_size)
{
my_bool err_status= FALSE;
- char query[QUERY_LENGTH];
MYSQL_RES *db_cl_res;
MYSQL_ROW db_cl_row;
- char quoted_database_buf[NAME_LEN*2+3];
- char *qdatabase= quote_name(db_name, quoted_database_buf, 1);
-
- my_snprintf(query, sizeof (query), "use %s", qdatabase);
- if (mysql_query_with_error_report(mysql, NULL, query))
- return 1;
+ if (mysql_select_db(mysql, db_name))
+ {
+ DB_error(mysql, "when selecting the database");
+ return 1; /* If --force */
+ }
if (mysql_query_with_error_report(mysql, &db_cl_res,
"select @@collation_database"))
@@ -1585,14 +1589,26 @@ static void free_resources()
{
if (md_result_file && md_result_file != stdout)
my_fclose(md_result_file, MYF(0));
+ if (get_table_name_result)
+ mysql_free_result(get_table_name_result);
+ if (routine_res)
+ mysql_free_result(routine_res);
+ if (routine_list_res)
+ mysql_free_result(routine_list_res);
+ if (mysql)
+ {
+ mysql_close(mysql);
+ mysql= 0;
+ }
+ my_free(order_by);
my_free(opt_password);
my_free(current_host);
+ free_root(&glob_root, MYF(0));
if (my_hash_inited(&ignore_table))
my_hash_free(&ignore_table);
- if (extended_insert)
- dynstr_free(&extended_row);
- if (insert_pat_inited)
- dynstr_free(&insert_pat);
+ dynstr_free(&extended_row);
+ dynstr_free(&dynamic_where);
+ dynstr_free(&insert_pat);
if (defaults_argv)
free_defaults(defaults_argv);
mysql_library_end();
@@ -1609,8 +1625,6 @@ static void maybe_exit(int error)
ignore_errors= 1; /* don't want to recurse, if something fails below */
if (opt_slave_data)
do_start_slave_sql(mysql);
- if (mysql)
- mysql_close(mysql);
free_resources();
exit(error);
}
@@ -1703,6 +1717,7 @@ static void dbDisconnect(char *host)
{
verbose_msg("-- Disconnecting from %s...\n", host ? host : "localhost");
mysql_close(mysql);
+ mysql= 0;
} /* dbDisconnect */
@@ -2324,6 +2339,8 @@ static uint dump_events_for_db(char *db)
(const char *) (query_str != NULL ? query_str : row[3]),
(const char *) delimiter);
+ my_free(query_str);
+
restore_time_zone(sql_file, delimiter);
restore_sql_mode(sql_file, delimiter);
@@ -2408,7 +2425,6 @@ static uint dump_routines_for_db(char *db)
char *routine_name;
int i;
FILE *sql_file= md_result_file;
- MYSQL_RES *routine_res, *routine_list_res;
MYSQL_ROW row, routine_list_row;
char db_cl_name[MY_CS_NAME_SIZE];
@@ -2432,7 +2448,7 @@ static uint dump_routines_for_db(char *db)
/* Get database collation. */
- if (fetch_db_collation(db_name_buff, db_cl_name, sizeof (db_cl_name)))
+ if (fetch_db_collation(db, db_cl_name, sizeof (db_cl_name)))
DBUG_RETURN(1);
if (switch_character_set_results(mysql, "binary"))
@@ -2463,7 +2479,11 @@ static uint dump_routines_for_db(char *db)
routine_type[i], routine_name);
if (mysql_query_with_error_report(mysql, &routine_res, query_buff))
+ {
+ mysql_free_result(routine_list_res);
+ routine_list_res= 0;
DBUG_RETURN(1);
+ }
while ((row= mysql_fetch_row(routine_res)))
{
@@ -2481,7 +2501,8 @@ static uint dump_routines_for_db(char *db)
print_comment(sql_file, 1,
"-- does %s have permissions on mysql.proc?\n\n",
current_user);
- maybe_die(EX_MYSQLERR,"%s has insufficent privileges to %s!", current_user, query_buff);
+ maybe_die(EX_MYSQLERR,"%s has insufficent privileges to %s!",
+ current_user, query_buff);
}
else if (strlen(row[2]))
{
@@ -2501,9 +2522,12 @@ static uint dump_routines_for_db(char *db)
if (mysql_num_fields(routine_res) >= 6)
{
- if (switch_db_collation(sql_file, db_name_buff, ";",
+ if (switch_db_collation(sql_file, db, ";",
db_cl_name, row[5], &db_cl_altered))
{
+ mysql_free_result(routine_res);
+ mysql_free_result(routine_list_res);
+ routine_res= routine_list_res= 0;
DBUG_RETURN(1);
}
@@ -2548,18 +2572,25 @@ static uint dump_routines_for_db(char *db)
if (db_cl_altered)
{
- if (restore_db_collation(sql_file, db_name_buff, ";", db_cl_name))
+ if (restore_db_collation(sql_file, db, ";", db_cl_name))
+ {
+ mysql_free_result(routine_res);
+ mysql_free_result(routine_list_res);
+ routine_res= routine_list_res= 0;
DBUG_RETURN(1);
+ }
}
}
}
} /* end of routine printing */
mysql_free_result(routine_res);
+ routine_res= 0;
} /* end of list of routines */
}
mysql_free_result(routine_list_res);
+ routine_list_res= 0;
} /* end of for i (0 .. 1) */
if (opt_xml)
@@ -2681,13 +2712,20 @@ static uint get_table_structure(char *table, char *db, char *table_type,
if (switch_character_set_results(mysql, "binary") ||
mysql_query_with_error_report(mysql, &result, buff) ||
switch_character_set_results(mysql, default_charset))
+ {
+ my_free(order_by);
+ order_by= 0;
DBUG_RETURN(0);
+ }
if (path)
{
if (!(sql_file= open_sql_file_for_table(table, O_WRONLY)))
+ {
+ my_free(order_by);
+ order_by= 0;
DBUG_RETURN(0);
-
+ }
write_header(sql_file, db);
}
@@ -3257,10 +3295,6 @@ static int dump_trigger(FILE *sql_file, MYSQL_RES *show_create_trigger_rs,
continue;
}
- query_str= cover_definer_clause(row[2], strlen(row[2]),
- C_STRING_WITH_LEN("50017"),
- C_STRING_WITH_LEN("50003"),
- C_STRING_WITH_LEN(" TRIGGER"));
if (switch_db_collation(sql_file, db_name, ";",
db_cl_name, row[5], &db_cl_altered))
DBUG_RETURN(TRUE);
@@ -3272,12 +3306,18 @@ static int dump_trigger(FILE *sql_file, MYSQL_RES *show_create_trigger_rs,
switch_sql_mode(sql_file, ";", row[1]);
+ query_str= cover_definer_clause(row[2], strlen(row[2]),
+ C_STRING_WITH_LEN("50017"),
+ C_STRING_WITH_LEN("50003"),
+ C_STRING_WITH_LEN(" TRIGGER"));
fprintf(sql_file,
"DELIMITER ;;\n"
"/*!50003 %s */;;\n"
"DELIMITER ;\n",
(const char *) (query_str != NULL ? query_str : row[2]));
+ my_free(query_str);
+
restore_sql_mode(sql_file, ";");
restore_cs_variables(sql_file, ";");
@@ -3286,8 +3326,6 @@ static int dump_trigger(FILE *sql_file, MYSQL_RES *show_create_trigger_rs,
if (restore_db_collation(sql_file, db_name, ";", db_cl_name))
DBUG_RETURN(TRUE);
}
-
- my_free(query_str);
}
DBUG_RETURN(FALSE);
@@ -3378,13 +3416,14 @@ static int dump_triggers_for_table(char *table_name, char *db_name)
{
MYSQL_RES *show_create_trigger_rs= mysql_store_result(mysql);
- if (!show_create_trigger_rs ||
- dump_trigger(sql_file, show_create_trigger_rs, db_name, db_cl_name))
- goto done;
-
+ int error= (!show_create_trigger_rs ||
+ dump_trigger(sql_file, show_create_trigger_rs, db_name,
+ db_cl_name));
mysql_free_result(show_create_trigger_rs);
+ if (error)
+ goto done;
}
-
+
}
if (opt_xml)
@@ -3631,12 +3670,14 @@ static void dump_table(char *table, char *db)
{
dynstr_append_checked(&query_string, " ORDER BY ");
dynstr_append_checked(&query_string, order_by);
+ my_free(order_by);
+ order_by= 0;
}
if (mysql_real_query(mysql, query_string.str, query_string.length))
{
- DB_error(mysql, "when executing 'SELECT INTO OUTFILE'");
dynstr_free(&query_string);
+ DB_error(mysql, "when executing 'SELECT INTO OUTFILE'");
DBUG_VOID_RETURN;
}
}
@@ -3662,6 +3703,8 @@ static void dump_table(char *table, char *db)
dynstr_append_checked(&query_string, " ORDER BY ");
dynstr_append_checked(&query_string, order_by);
+ my_free(order_by);
+ order_by= 0;
}
if (!opt_xml && !opt_compact)
@@ -3671,6 +3714,7 @@ static void dump_table(char *table, char *db)
}
if (mysql_query_with_error_report(mysql, 0, query_string.str))
{
+ dynstr_free(&query_string);
DB_error(mysql, "when retrieving data from server");
goto err;
}
@@ -3680,6 +3724,7 @@ static void dump_table(char *table, char *db)
res=mysql_store_result(mysql);
if (!res)
{
+ dynstr_free(&query_string);
DB_error(mysql, "when retrieving data from server");
goto err;
}
@@ -3995,23 +4040,22 @@ err:
static char *getTableName(int reset)
{
- static MYSQL_RES *res= NULL;
- MYSQL_ROW row;
+ MYSQL_ROW row;
- if (!res)
+ if (!get_table_name_result)
{
- if (!(res= mysql_list_tables(mysql,NullS)))
+ if (!(get_table_name_result= mysql_list_tables(mysql,NullS)))
return(NULL);
}
- if ((row= mysql_fetch_row(res)))
+ if ((row= mysql_fetch_row(get_table_name_result)))
return((char*) row[0]);
if (reset)
- mysql_data_seek(res,0); /* We want to read again */
+ mysql_data_seek(get_table_name_result,0); /* We want to read again */
else
{
- mysql_free_result(res);
- res= NULL;
+ mysql_free_result(get_table_name_result);
+ get_table_name_result= NULL;
}
return(NULL);
} /* getTableName */
@@ -4028,46 +4072,44 @@ static int dump_all_tablespaces()
static int dump_tablespaces_for_tables(char *db, char **table_names, int tables)
{
- DYNAMIC_STRING where;
int r;
int i;
char name_buff[NAME_LEN*2+3];
mysql_real_escape_string(mysql, name_buff, db, strlen(db));
- init_dynamic_string_checked(&where, " AND TABLESPACE_NAME IN ("
+ init_dynamic_string_checked(&dynamic_where, " AND TABLESPACE_NAME IN ("
"SELECT DISTINCT TABLESPACE_NAME FROM"
" INFORMATION_SCHEMA.PARTITIONS"
" WHERE"
" TABLE_SCHEMA='", 256, 1024);
- dynstr_append_checked(&where, name_buff);
- dynstr_append_checked(&where, "' AND TABLE_NAME IN (");
+ dynstr_append_checked(&dynamic_where, name_buff);
+ dynstr_append_checked(&dynamic_where, "' AND TABLE_NAME IN (");
for (i=0 ; i<tables ; i++)
{
mysql_real_escape_string(mysql, name_buff,
table_names[i], strlen(table_names[i]));
- dynstr_append_checked(&where, "'");
- dynstr_append_checked(&where, name_buff);
- dynstr_append_checked(&where, "',");
+ dynstr_append_checked(&dynamic_where, "'");
+ dynstr_append_checked(&dynamic_where, name_buff);
+ dynstr_append_checked(&dynamic_where, "',");
}
- dynstr_trunc(&where, 1);
- dynstr_append_checked(&where,"))");
+ dynstr_trunc(&dynamic_where, 1);
+ dynstr_append_checked(&dynamic_where,"))");
- DBUG_PRINT("info",("Dump TS for Tables where: %s",where.str));
- r= dump_tablespaces(where.str);
- dynstr_free(&where);
+ DBUG_PRINT("info",("Dump TS for Tables where: %s",dynamic_where.str));
+ r= dump_tablespaces(dynamic_where.str);
+ dynstr_free(&dynamic_where);
return r;
}
static int dump_tablespaces_for_databases(char** databases)
{
- DYNAMIC_STRING where;
int r;
int i;
- init_dynamic_string_checked(&where, " AND TABLESPACE_NAME IN ("
+ init_dynamic_string_checked(&dynamic_where, " AND TABLESPACE_NAME IN ("
"SELECT DISTINCT TABLESPACE_NAME FROM"
" INFORMATION_SCHEMA.PARTITIONS"
" WHERE"
@@ -4078,16 +4120,16 @@ static int dump_tablespaces_for_databases(char** databases)
char db_name_buff[NAME_LEN*2+3];
mysql_real_escape_string(mysql, db_name_buff,
databases[i], strlen(databases[i]));
- dynstr_append_checked(&where, "'");
- dynstr_append_checked(&where, db_name_buff);
- dynstr_append_checked(&where, "',");
+ dynstr_append_checked(&dynamic_where, "'");
+ dynstr_append_checked(&dynamic_where, db_name_buff);
+ dynstr_append_checked(&dynamic_where, "',");
}
- dynstr_trunc(&where, 1);
- dynstr_append_checked(&where,"))");
+ dynstr_trunc(&dynamic_where, 1);
+ dynstr_append_checked(&dynamic_where,"))");
- DBUG_PRINT("info",("Dump TS for DBs where: %s",where.str));
- r= dump_tablespaces(where.str);
- dynstr_free(&where);
+ DBUG_PRINT("info",("Dump TS for DBs where: %s",dynamic_where.str));
+ r= dump_tablespaces(dynamic_where.str);
+ dynstr_free(&dynamic_where);
return r;
}
@@ -4495,9 +4537,12 @@ static int dump_all_tables_in_db(char *database)
}
}
if (numrows && mysql_real_query(mysql, query.str, query.length-1))
+ {
+ dynstr_free(&query);
DB_error(mysql, "when using LOCK TABLES");
- /* We shall continue here, if --force was given */
- dynstr_free(&query);
+ /* We shall continue here, if --force was given */
+ }
+ dynstr_free(&query); /* Safe to call twice */
}
if (flush_logs)
{
@@ -4511,7 +4556,9 @@ static int dump_all_tables_in_db(char *database)
{
verbose_msg("-- Setting savepoint...\n");
if (mysql_query_with_error_report(mysql, 0, "SAVEPOINT sp"))
+ {
DBUG_RETURN(1);
+ }
}
while ((table= getTableName(0)))
{
@@ -4746,22 +4793,22 @@ static int dump_selected_tables(char *db, char **table_names, int tables)
{
char table_buff[NAME_LEN*2+3];
DYNAMIC_STRING lock_tables_query;
- MEM_ROOT root;
char **dump_tables, **pos, **end;
DBUG_ENTER("dump_selected_tables");
if (init_dumping(db, init_dumping_tables))
DBUG_RETURN(1);
- init_alloc_root(&root, 8192, 0, MYF(0));
- if (!(dump_tables= pos= (char**) alloc_root(&root, tables * sizeof(char *))))
+ init_alloc_root(&glob_root, 8192, 0, MYF(0));
+ if (!(dump_tables= pos= (char**) alloc_root(&glob_root,
+ tables * sizeof(char *))))
die(EX_EOM, "alloc_root failure.");
init_dynamic_string_checked(&lock_tables_query, "LOCK TABLES ", 256, 1024);
for (; tables > 0 ; tables-- , table_names++)
{
/* the table name passed on commandline may be wrong case */
- if ((*pos= get_actual_table_name(*table_names, &root)))
+ if ((*pos= get_actual_table_name(*table_names, &glob_root)))
{
/* Add found table name to lock_tables_query */
if (lock_tables)
@@ -4776,7 +4823,7 @@ static int dump_selected_tables(char *db, char **table_names, int tables)
if (!ignore_errors)
{
dynstr_free(&lock_tables_query);
- free_root(&root, MYF(0));
+ free_root(&glob_root, MYF(0));
}
maybe_die(EX_ILLEGAL_TABLE, "Couldn't find table: \"%s\"", *table_names);
/* We shall countinue here, if --force was given */
@@ -4797,7 +4844,7 @@ static int dump_selected_tables(char *db, char **table_names, int tables)
if (!ignore_errors)
{
dynstr_free(&lock_tables_query);
- free_root(&root, MYF(0));
+ free_root(&glob_root, MYF(0));
}
DB_error(mysql, "when doing LOCK TABLES");
/* We shall countinue here, if --force was given */
@@ -4809,7 +4856,7 @@ static int dump_selected_tables(char *db, char **table_names, int tables)
if (mysql_refresh(mysql, REFRESH_LOG))
{
if (!ignore_errors)
- free_root(&root, MYF(0));
+ free_root(&glob_root, MYF(0));
DB_error(mysql, "when doing refresh");
}
/* We shall countinue here, if --force was given */
@@ -4823,7 +4870,10 @@ static int dump_selected_tables(char *db, char **table_names, int tables)
{
verbose_msg("-- Setting savepoint...\n");
if (mysql_query_with_error_report(mysql, 0, "SAVEPOINT sp"))
+ {
+ free_root(&glob_root, MYF(0));
DBUG_RETURN(1);
+ }
}
/* Dump each selected table */
@@ -4838,6 +4888,8 @@ static int dump_selected_tables(char *db, char **table_names, int tables)
{
if (path)
my_fclose(md_result_file, MYF(MY_WME));
+ if (!ignore_errors)
+ free_root(&glob_root, MYF(0));
maybe_exit(EX_MYSQLERR);
}
}
@@ -4856,7 +4908,11 @@ static int dump_selected_tables(char *db, char **table_names, int tables)
{
verbose_msg("-- Rolling back to savepoint sp...\n");
if (mysql_query_with_error_report(mysql, 0, "ROLLBACK TO SAVEPOINT sp"))
+ {
+ if (!ignore_errors)
+ free_root(&glob_root, MYF(0));
maybe_exit(EX_MYSQLERR);
+ }
}
}
@@ -4864,8 +4920,10 @@ static int dump_selected_tables(char *db, char **table_names, int tables)
{
verbose_msg("-- Releasing savepoint...\n");
if (mysql_query_with_error_report(mysql, 0, "RELEASE SAVEPOINT sp"))
+ {
+ free_root(&glob_root, MYF(0));
DBUG_RETURN(1);
-
+ }
}
/* Dump each selected view */
@@ -4885,9 +4943,7 @@ static int dump_selected_tables(char *db, char **table_names, int tables)
DBUG_PRINT("info", ("Dumping routines for database %s", db));
dump_routines_for_db(db);
}
- free_root(&root, MYF(0));
- my_free(order_by);
- order_by= 0;
+ free_root(&glob_root, MYF(0));
if (opt_xml)
{
fputs("</database>\n", md_result_file);
diff --git a/client/mysqlshow.c b/client/mysqlshow.c
index d1ffb6a4876..fd81f18790a 100644
--- a/client/mysqlshow.c
+++ b/client/mysqlshow.c
@@ -1,6 +1,6 @@
/*
- Copyright (c) 2000, 2012, Oracle and/or its affiliates.
- Copyright (c) 2010, 2012, Monty Program Ab
+ Copyright (c) 2000, 2015, Oracle and/or its affiliates.
+ Copyright (c) 2010, 2015, MariaDB
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -68,10 +68,12 @@ int main(int argc, char **argv)
my_bool first_argument_uses_wildcards=0;
char *wild;
MYSQL mysql;
+ static char **defaults_argv;
MY_INIT(argv[0]);
sf_leaking_memory=1; /* don't report memory leaks on early exits */
if (load_defaults("my",load_default_groups,&argc,&argv))
exit(1);
+ defaults_argv=argv;
get_options(&argc,&argv);
@@ -150,7 +152,8 @@ int main(int argc, char **argv)
0)))
{
fprintf(stderr,"%s: %s\n",my_progname,mysql_error(&mysql));
- exit(1);
+ error= 1;
+ goto error;
}
mysql.reconnect= 1;
@@ -169,11 +172,14 @@ int main(int argc, char **argv)
error=list_fields(&mysql,argv[0],argv[1],wild);
break;
}
+error:
mysql_close(&mysql); /* Close & free connection */
my_free(opt_password);
+ mysql_server_end();
#ifdef HAVE_SMEM
my_free(shared_memory_base_name);
#endif
+ free_defaults(defaults_argv);
my_end(my_end_arg);
exit(error ? 1 : 0);
return 0; /* No compiler warnings */
@@ -376,7 +382,7 @@ list_dbs(MYSQL *mysql,const char *wild)
uint length, counter = 0;
ulong rowcount = 0L;
char tables[NAME_LEN+1], rows[NAME_LEN+1];
- char query[255];
+ char query[NAME_LEN + 100];
MYSQL_FIELD *field;
MYSQL_RES *result;
MYSQL_ROW row= NULL, rrow;
@@ -443,7 +449,8 @@ list_dbs(MYSQL *mysql,const char *wild)
MYSQL_ROW trow;
while ((trow = mysql_fetch_row(tresult)))
{
- sprintf(query,"SELECT COUNT(*) FROM `%s`",trow[0]);
+ my_snprintf(query, sizeof(query),
+ "SELECT COUNT(*) FROM `%s`", trow[0]);
if (!(mysql_query(mysql,query)))
{
MYSQL_RES *rresult;
@@ -499,7 +506,7 @@ list_tables(MYSQL *mysql,const char *db,const char *table)
{
const char *header;
uint head_length, counter = 0;
- char query[255], rows[NAME_LEN], fields[16];
+ char query[NAME_LEN + 100], rows[NAME_LEN], fields[16];
MYSQL_FIELD *field;
MYSQL_RES *result;
MYSQL_ROW row, rrow;
@@ -584,7 +591,8 @@ list_tables(MYSQL *mysql,const char *db,const char *table)
if (opt_verbose > 1)
{
/* Print the count of rows for each table */
- sprintf(query,"SELECT COUNT(*) FROM `%s`",row[0]);
+ my_snprintf(query, sizeof(query), "SELECT COUNT(*) FROM `%s`",
+ row[0]);
if (!(mysql_query(mysql,query)))
{
if ((rresult = mysql_store_result(mysql)))
@@ -644,13 +652,15 @@ list_tables(MYSQL *mysql,const char *db,const char *table)
static int
list_table_status(MYSQL *mysql,const char *db,const char *wild)
{
- char query[1024],*end;
+ char query[NAME_LEN + 100];
+ int len;
MYSQL_RES *result;
MYSQL_ROW row;
- end=strxmov(query,"show table status from `",db,"`",NullS);
- if (wild && wild[0])
- strxmov(end," like '",wild,"'",NullS);
+ len= sizeof(query);
+ len-= my_snprintf(query, len, "show table status from `%s`", db);
+ if (wild && wild[0] && len)
+ strxnmov(query + strlen(query), len, " like '", wild, "'", NullS);
if (mysql_query(mysql,query) || !(result=mysql_store_result(mysql)))
{
fprintf(stderr,"%s: Cannot get status for db: %s, table: %s: %s\n",
@@ -682,7 +692,8 @@ static int
list_fields(MYSQL *mysql,const char *db,const char *table,
const char *wild)
{
- char query[1024],*end;
+ char query[NAME_LEN + 100];
+ int len;
MYSQL_RES *result;
MYSQL_ROW row;
ulong UNINIT_VAR(rows);
@@ -696,7 +707,7 @@ list_fields(MYSQL *mysql,const char *db,const char *table,
if (opt_count)
{
- sprintf(query,"select count(*) from `%s`", table);
+ my_snprintf(query, sizeof(query), "select count(*) from `%s`", table);
if (mysql_query(mysql,query) || !(result=mysql_store_result(mysql)))
{
fprintf(stderr,"%s: Cannot get record count for db: %s, table: %s: %s\n",
@@ -708,9 +719,11 @@ list_fields(MYSQL *mysql,const char *db,const char *table,
mysql_free_result(result);
}
- end=strmov(strmov(strmov(query,"show /*!32332 FULL */ columns from `"),table),"`");
- if (wild && wild[0])
- strxmov(end," like '",wild,"'",NullS);
+ len= sizeof(query);
+ len-= my_snprintf(query, len, "show /*!32332 FULL */ columns from `%s`",
+ table);
+ if (wild && wild[0] && len)
+ strxnmov(query + strlen(query), len, " like '", wild, "'", NullS);
if (mysql_query(mysql,query) || !(result=mysql_store_result(mysql)))
{
fprintf(stderr,"%s: Cannot list columns in db: %s, table: %s: %s\n",
@@ -731,7 +744,7 @@ list_fields(MYSQL *mysql,const char *db,const char *table,
print_res_top(result);
if (opt_show_keys)
{
- end=strmov(strmov(strmov(query,"show keys from `"),table),"`");
+ my_snprintf(query, sizeof(query), "show keys from `%s`", table);
if (mysql_query(mysql,query) || !(result=mysql_store_result(mysql)))
{
fprintf(stderr,"%s: Cannot list keys in db: %s, table: %s: %s\n",
diff --git a/client/mysqlslap.c b/client/mysqlslap.c
index f12ea4c2086..29919f3028d 100644
--- a/client/mysqlslap.c
+++ b/client/mysqlslap.c
@@ -168,6 +168,7 @@ static ulonglong auto_generate_sql_number;
const char *concurrency_str= NULL;
static char *create_string;
uint *concurrency;
+static char mysql_charsets_dir[FN_REFLEN+1];
const char *default_dbug_option="d:t:o,/tmp/mysqlslap.trace";
const char *opt_csv_str;
@@ -372,6 +373,7 @@ int main(int argc, char **argv)
{
fprintf(stderr,"%s: Error when connecting to server: %s\n",
my_progname,mysql_error(&mysql));
+ mysql_close(&mysql);
free_defaults(defaults_argv);
my_end(0);
exit(1);
@@ -417,8 +419,7 @@ int main(int argc, char **argv)
pthread_mutex_destroy(&sleeper_mutex);
pthread_cond_destroy(&sleep_threshhold);
- if (!opt_only_print)
- mysql_close(&mysql); /* Close & free connection */
+ mysql_close(&mysql); /* Close & free connection */
/* now free all the strings we created */
my_free(opt_password);
@@ -585,6 +586,9 @@ static struct my_option my_long_options[] =
"Number of row inserts to perform for each thread (default is 100).",
&auto_generate_sql_number, &auto_generate_sql_number,
0, GET_ULL, REQUIRED_ARG, 100, 0, 0, 0, 0, 0},
+ {"character-sets-dir", OPT_CHARSETS_DIR,
+ "Directory for character set files.", &charsets_dir,
+ &charsets_dir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"commit", OPT_SLAP_COMMIT, "Commit records every X number of statements.",
&commit_rate, &commit_rate, 0, GET_UINT, REQUIRED_ARG,
0, 0, 0, 0, 0, 0},
@@ -782,6 +786,10 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
DBUG_PUSH(argument ? argument : default_dbug_option);
debug_check_flag= 1;
break;
+ case OPT_CHARSETS_DIR:
+ strmake_buf(mysql_charsets_dir, argument);
+ charsets_dir = mysql_charsets_dir;
+ break;
case OPT_SLAP_CSV:
if (!argument)
argument= (char *)"-"; /* use stdout */
@@ -1863,21 +1871,21 @@ pthread_handler_t run_task(void *p)
}
pthread_mutex_unlock(&sleeper_mutex);
- if (!(mysql= mysql_init(NULL)))
+ if (mysql_thread_init())
{
- fprintf(stderr,"%s: mysql_init() failed ERROR : %s\n",
- my_progname, mysql_error(mysql));
+ fprintf(stderr,"%s: mysql_thread_init() failed\n", my_progname);
exit(0);
}
- set_mysql_connect_options(mysql);
- if (mysql_thread_init())
+ if (!(mysql= mysql_init(NULL)))
{
- fprintf(stderr,"%s: mysql_thread_init() failed ERROR : %s\n",
- my_progname, mysql_error(mysql));
+ fprintf(stderr,"%s: mysql_init() failed\n", my_progname);
+ mysql_thread_end();
exit(0);
}
+ set_mysql_connect_options(mysql);
+
DBUG_PRINT("info", ("trying to connect to host %s as user %s", host, user));
if (!opt_only_print)
@@ -1995,8 +2003,7 @@ end:
if (commit_rate)
run_query(mysql, "COMMIT", strlen("COMMIT"));
- if (!opt_only_print)
- mysql_close(mysql);
+ mysql_close(mysql);
mysql_thread_end();
diff --git a/client/mysqltest.cc b/client/mysqltest.cc
index e28d56e9187..c601fb57f2f 100644
--- a/client/mysqltest.cc
+++ b/client/mysqltest.cc
@@ -5246,7 +5246,7 @@ static st_error global_error_names[] =
#include <my_base.h>
static st_error handler_error_names[] =
{
- { "<No error>", -1U, "" },
+ { "<No error>", UINT_MAX, "" },
#include <handler_ername.h>
{ 0, 0, 0 }
};