mirror of
https://github.com/MariaDB/server.git
synced 2026-04-21 07:45:32 +02:00
Merge branch '10.0' into 10.1
This commit is contained in:
commit
a2bcee626d
3462 changed files with 635147 additions and 221404 deletions
|
|
@ -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__
|
||||
|
|
|
|||
|
|
@ -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, " ");
|
||||
}
|
||||
|
||||
|
|
@ -580,8 +585,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",
|
||||
|
|
@ -773,8 +777,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" : "",
|
||||
|
|
@ -834,8 +837,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",
|
||||
|
|
@ -859,8 +861,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",
|
||||
|
|
@ -1084,12 +1085,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);
|
||||
|
|
|
|||
|
|
@ -1536,6 +1536,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;
|
||||
|
|
@ -1722,7 +1724,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;
|
||||
if (start_position > UINT_MAX32 && remote_opt)
|
||||
{
|
||||
|
|
@ -2056,6 +2058,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);
|
||||
}
|
||||
/*
|
||||
|
|
@ -2064,6 +2067,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
|
||||
|
|
@ -2094,7 +2098,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)
|
||||
|
|
@ -2462,23 +2468,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)
|
||||
|
|
@ -2498,12 +2504,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
|
||||
|
|
@ -2573,12 +2585,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);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ static my_bool opt_alldbs = 0, opt_check_only_changed = 0, opt_extended = 0,
|
|||
opt_silent = 0, opt_auto_repair = 0, ignore_errors = 0,
|
||||
tty_password= 0, opt_frm= 0, debug_info_flag= 0, debug_check_flag= 0,
|
||||
opt_fix_table_names= 0, opt_fix_db_names= 0, opt_upgrade= 0,
|
||||
opt_do_tables= 1;
|
||||
opt_persistent_all= 0, opt_do_tables= 1;
|
||||
static my_bool opt_write_binlog= 1, opt_flush_tables= 0;
|
||||
static uint verbose = 0, opt_mysql_port=0;
|
||||
static int my_end_arg;
|
||||
|
|
@ -160,6 +160,10 @@ static struct my_option my_long_options[] =
|
|||
{"password", 'p',
|
||||
"Password to use when connecting to server. If password is not given, it's solicited on the tty.",
|
||||
0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
|
||||
{"persistent", 'Z',
|
||||
"When using ANALYZE TABLE use the PERSISTENT FOR ALL option.",
|
||||
&opt_persistent_all, &opt_persistent_all, 0, GET_BOOL, NO_ARG,
|
||||
0, 0, 0, 0, 0, 0},
|
||||
#ifdef __WIN__
|
||||
{"pipe", 'W', "Use named pipes to connect to server.", 0, 0, 0, GET_NO_ARG,
|
||||
NO_ARG, 0, 0, 0, 0, 0, 0},
|
||||
|
|
@ -910,6 +914,7 @@ static int handle_request_for_tables(char *tables, size_t length, my_bool view)
|
|||
case DO_ANALYZE:
|
||||
DBUG_ASSERT(!view);
|
||||
op= (opt_write_binlog) ? "ANALYZE" : "ANALYZE NO_WRITE_TO_BINLOG";
|
||||
if (opt_persistent_all) end = strmov(end, " PERSISTENT FOR ALL");
|
||||
break;
|
||||
case DO_OPTIMIZE:
|
||||
DBUG_ASSERT(!view);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
@ -1144,16 +1150,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"))
|
||||
|
|
@ -1591,14 +1595,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();
|
||||
|
|
@ -1615,8 +1631,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);
|
||||
}
|
||||
|
|
@ -1709,6 +1723,7 @@ static void dbDisconnect(char *host)
|
|||
{
|
||||
verbose_msg("-- Disconnecting from %s...\n", host ? host : "localhost");
|
||||
mysql_close(mysql);
|
||||
mysql= 0;
|
||||
} /* dbDisconnect */
|
||||
|
||||
|
||||
|
|
@ -2350,6 +2365,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);
|
||||
|
||||
|
|
@ -2434,7 +2451,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];
|
||||
|
|
@ -2458,7 +2474,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"))
|
||||
|
|
@ -2489,7 +2505,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)))
|
||||
{
|
||||
|
|
@ -2507,7 +2527,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]))
|
||||
{
|
||||
|
|
@ -2527,9 +2548,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);
|
||||
}
|
||||
|
||||
|
|
@ -2574,18 +2598,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)
|
||||
|
|
@ -2708,13 +2739,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);
|
||||
}
|
||||
|
||||
|
|
@ -3286,10 +3324,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);
|
||||
|
|
@ -3301,12 +3335,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, ";");
|
||||
|
||||
|
|
@ -3315,8 +3355,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);
|
||||
|
|
@ -3409,13 +3447,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)
|
||||
|
|
@ -3662,12 +3701,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;
|
||||
}
|
||||
}
|
||||
|
|
@ -3693,6 +3734,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)
|
||||
|
|
@ -3702,6 +3745,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;
|
||||
}
|
||||
|
|
@ -3711,6 +3755,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;
|
||||
}
|
||||
|
|
@ -4026,23 +4071,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 */
|
||||
|
|
@ -4059,46 +4103,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"
|
||||
|
|
@ -4109,16 +4151,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;
|
||||
}
|
||||
|
||||
|
|
@ -4526,9 +4568,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)
|
||||
{
|
||||
|
|
@ -4542,7 +4587,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)))
|
||||
{
|
||||
|
|
@ -4839,7 +4886,6 @@ 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;
|
||||
int lower_case_table_names;
|
||||
DBUG_ENTER("dump_selected_tables");
|
||||
|
|
@ -4847,8 +4893,9 @@ static int dump_selected_tables(char *db, char **table_names, int 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.");
|
||||
|
||||
/* Figure out how to compare table names. */
|
||||
|
|
@ -4859,7 +4906,7 @@ static int dump_selected_tables(char *db, char **table_names, int tables)
|
|||
{
|
||||
/* the table name passed on commandline may be wrong case */
|
||||
if ((*pos= get_actual_table_name(*table_names, lower_case_table_names,
|
||||
&root)))
|
||||
&glob_root)))
|
||||
{
|
||||
/* Add found table name to lock_tables_query */
|
||||
if (lock_tables)
|
||||
|
|
@ -4874,7 +4921,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 */
|
||||
|
|
@ -4895,7 +4942,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 */
|
||||
|
|
@ -4907,7 +4954,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 */
|
||||
|
|
@ -4921,7 +4968,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 */
|
||||
|
|
@ -4936,6 +4986,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);
|
||||
}
|
||||
}
|
||||
|
|
@ -4954,7 +5006,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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -4962,8 +5018,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 */
|
||||
|
|
@ -4983,9 +5041,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);
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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)))
|
||||
{
|
||||
fprintf(stderr,"%s: mysql_init() failed ERROR : %s\n",
|
||||
my_progname, mysql_error(mysql));
|
||||
exit(0);
|
||||
}
|
||||
set_mysql_connect_options(mysql);
|
||||
|
||||
if (mysql_thread_init())
|
||||
{
|
||||
fprintf(stderr,"%s: mysql_thread_init() failed ERROR : %s\n",
|
||||
my_progname, mysql_error(mysql));
|
||||
fprintf(stderr,"%s: mysql_thread_init() failed\n", my_progname);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
if (!(mysql= mysql_init(NULL)))
|
||||
{
|
||||
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();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue