diff options
Diffstat (limited to 'client')
-rwxr-xr-x | client/CMakeLists.txt | 17 | ||||
-rw-r--r-- | client/Makefile.am | 36 | ||||
-rw-r--r-- | client/client_priv.h | 5 | ||||
-rw-r--r-- | client/completion_hash.cc | 3 | ||||
-rw-r--r-- | client/completion_hash.h | 6 | ||||
-rw-r--r-- | client/get_password.c | 3 | ||||
-rw-r--r-- | client/my_readline.h | 3 | ||||
-rw-r--r-- | client/mysql.cc | 32 | ||||
-rw-r--r-- | client/mysql_upgrade.c | 129 | ||||
-rw-r--r-- | client/mysqladmin.cc | 9 | ||||
-rw-r--r-- | client/mysqlbinlog.cc | 60 | ||||
-rw-r--r-- | client/mysqlcheck.c | 3 | ||||
-rw-r--r-- | client/mysqldump.c | 7 | ||||
-rw-r--r-- | client/mysqlimport.c | 7 | ||||
-rw-r--r-- | client/mysqlmanager-pwgen.c | 3 | ||||
-rw-r--r-- | client/mysqlmanagerc.c | 3 | ||||
-rw-r--r-- | client/mysqlshow.c | 7 | ||||
-rw-r--r-- | client/mysqltest.c | 157 | ||||
-rw-r--r-- | client/readline.cc | 6 | ||||
-rw-r--r-- | client/sql_string.cc | 3 | ||||
-rw-r--r-- | client/sql_string.h | 3 |
21 files changed, 351 insertions, 151 deletions
diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index 09a6a3f1e2a..2edb1489f81 100755 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -1,3 +1,18 @@ +# Copyright (C) 2006 MySQL 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 +# the Free Software Foundation; version 2 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DSAFEMALLOC -DSAFE_MUTEX") SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DSAFEMALLOC -DSAFE_MUTEX") @@ -66,7 +81,7 @@ TARGET_LINK_LIBRARIES(mysqldump mysqlclient mysys dbug yassl taocrypt zlib wsock ADD_EXECUTABLE(mysqlimport mysqlimport.c) TARGET_LINK_LIBRARIES(mysqlimport mysqlclient mysys dbug yassl taocrypt zlib wsock32) -ADD_EXECUTABLE(mysql_upgrade mysql_upgrade.c) +ADD_EXECUTABLE(mysql_upgrade mysql_upgrade.c ../mysys/my_getpagesize.c) TARGET_LINK_LIBRARIES(mysql_upgrade mysqlclient mysys dbug yassl taocrypt zlib wsock32) ADD_EXECUTABLE(mysqlshow mysqlshow.c) diff --git a/client/Makefile.am b/client/Makefile.am index 29624f2017f..2cb7dce64f9 100644 --- a/client/Makefile.am +++ b/client/Makefile.am @@ -1,9 +1,8 @@ -# Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB +# Copyright (C) 2000-2006 MySQL 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 -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. +# the Free Software Foundation; version 2 of the License. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -16,11 +15,6 @@ # This file is public domain and comes with NO WARRANTY of any kind -if HAVE_YASSL - yassl_dummy_link_fix= $(top_srcdir)/extra/yassl/src/dummy.cpp -else - yassl_dummy_link_fix= -endif #AUTOMAKE_OPTIONS = nostdinc INCLUDES = -I$(top_builddir)/include \ -I$(top_srcdir)/include \ @@ -40,27 +34,29 @@ mysqladmin_SOURCES = mysqladmin.cc mysql_LDADD = @readline_link@ @TERMCAP_LIB@ $(LDADD) $(CXXLDFLAGS) mysqltest_SOURCES= mysqltest.c \ $(top_srcdir)/mysys/my_getsystime.c \ - $(top_srcdir)/mysys/my_copy.c \ - $(yassl_dummy_link_fix) + $(top_srcdir)/mysys/my_copy.c + mysqltest_LDADD = $(top_builddir)/regex/libregex.a $(LDADD) -mysqlbinlog_SOURCES = mysqlbinlog.cc $(top_srcdir)/mysys/mf_tempdir.c $(top_srcdir)/mysys/my_new.cc +mysqlbinlog_SOURCES = mysqlbinlog.cc \ + $(top_srcdir)/mysys/mf_tempdir.c \ + $(top_srcdir)/mysys/my_new.cc mysqlbinlog_LDADD = $(LDADD) $(CXXLDFLAGS) -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) +mysqltestmanager_pwgen_SOURCES = mysqlmanager-pwgen.c +mysqltestmanagerc_SOURCES= mysqlmanagerc.c +mysqlcheck_SOURCES= mysqlcheck.c +mysqlshow_SOURCES= mysqlshow.c 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) + $(top_srcdir)/mysys/mf_getdate.c +mysqlimport_SOURCES= mysqlimport.c +mysql_upgrade_SOURCES= mysql_upgrade.c \ + $(top_srcdir)/mysys/my_getpagesize.c sql_src=log_event.h mysql_priv.h log_event.cc my_decimal.h my_decimal.cc strings_src=decimal.c # Fix for mit-threads DEFS = -DUNDEF_THREADS_HACK \ -DDEFAULT_MYSQL_HOME="\"$(prefix)\"" \ - -DDATADIR="\"$(localstatedir)\"" + -DDATADIR="\"$(localstatedir)\"" EXTRA_DIST = get_password.c CMakeLists.txt diff --git a/client/client_priv.h b/client/client_priv.h index 7ebbade4ef6..7748dc612d6 100644 --- a/client/client_priv.h +++ b/client/client_priv.h @@ -1,9 +1,8 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB +/* Copyright (C) 2001-2006 MySQL 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 - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. + the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of diff --git a/client/completion_hash.cc b/client/completion_hash.cc index 7a3b363c93c..4c777f8a704 100644 --- a/client/completion_hash.cc +++ b/client/completion_hash.cc @@ -2,8 +2,7 @@ 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 - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. + the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of diff --git a/client/completion_hash.h b/client/completion_hash.h index 2595a445c9d..b91d6e4d187 100644 --- a/client/completion_hash.h +++ b/client/completion_hash.h @@ -1,9 +1,9 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB +/* Copyright (C) 2000-2002 MySQL AB This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. + License as published by the Free Software Foundation; version 2 + of the License. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of diff --git a/client/get_password.c b/client/get_password.c index 1b7b4e65a9f..e7e6c850469 100644 --- a/client/get_password.c +++ b/client/get_password.c @@ -2,8 +2,7 @@ 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 - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. + the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of diff --git a/client/my_readline.h b/client/my_readline.h index 6052d462ab9..47be7fa9294 100644 --- a/client/my_readline.h +++ b/client/my_readline.h @@ -2,8 +2,7 @@ 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 - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. + the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of diff --git a/client/mysql.cc b/client/mysql.cc index d0965588b80..4e479f3ff70 100644 --- a/client/mysql.cc +++ b/client/mysql.cc @@ -2,8 +2,7 @@ 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 - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. + the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -819,10 +818,23 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), default_charset_used= 1; break; case OPT_DELIMITER: - if (argument == disabled_my_option) + if (argument == disabled_my_option) + { strmov(delimiter, DEFAULT_DELIMITER); - else - strmake(delimiter, argument, sizeof(delimiter) - 1); + } + else + { + /* Check that delimiter does not contain a backslash */ + if (!strstr(argument, "\\")) + { + strmake(delimiter, argument, sizeof(delimiter) - 1); + } + else + { + put_info("DELIMITER cannot contain a backslash character", INFO_ERROR); + return 0; + } + } delimiter_length= (uint)strlen(delimiter); delimiter_str= delimiter; break; @@ -2397,7 +2409,6 @@ print_table_data(MYSQL_RES *result) const char *buffer; uint data_length; uint field_max_length; - bool right_justified; uint visible_length; uint extra_padding; @@ -3041,6 +3052,14 @@ com_delimiter(String *buffer __attribute__((unused)), char *line) INFO_ERROR); return 0; } + else + { + if (strstr(tmp, "\\")) + { + put_info("DELIMITER cannot contain a backslash character", INFO_ERROR); + return 0; + } + } strmake(delimiter, tmp, sizeof(delimiter) - 1); delimiter_length= (int)strlen(delimiter); delimiter_str= delimiter; @@ -3446,7 +3465,6 @@ server_version_string(MYSQL *mysql) { char *bufp = buf; MYSQL_RES *result; - MYSQL_ROW cur; bufp = strnmov(buf, mysql_get_server_info(mysql), sizeof buf); diff --git a/client/mysql_upgrade.c b/client/mysql_upgrade.c index 520d87b5ed7..8eb72af6b9d 100644 --- a/client/mysql_upgrade.c +++ b/client/mysql_upgrade.c @@ -2,8 +2,7 @@ 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 - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. + the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -31,10 +30,12 @@ const char *mysqlcheck_name= "mysqlcheck.exe"; const char *mysql_name= "mysql.exe"; const char *mysqld_name= "mysqld.exe"; +#define EXTRA_CLIENT_PATHS "client/release", "client/debug" #else const char *mysqlcheck_name= "mysqlcheck"; const char *mysql_name= "mysql"; const char *mysqld_name= "mysqld"; +#define EXTRA_CLIENT_PATHS "client" #endif /*__WIN__*/ extern TYPELIB sql_protocol_typelib; @@ -142,6 +143,7 @@ void set_extra_default(int id, const struct my_option *opt) case 'f': /* --force is ours */ case 'u': /* --user passed on cmdline */ case 'T': /* --debug-info is not accepted by mysqlcheck */ + case 'p': /* --password may change yet */ /* so, do nothing */ break; default: @@ -173,7 +175,7 @@ void set_extra_default(int id, const struct my_option *opt) d->id= id; d->name= opt->name; d->n_len= strlen(opt->name); - if (opt->arg_type != NO_ARG) + if (opt->arg_type != NO_ARG && opt->value) switch (opt->var_type & GET_TYPE_MASK) { case GET_BOOL: if (*((int *)opt->value)) @@ -319,6 +321,15 @@ static int create_defaults_file(const char *path, const char *forced_path) } dynstr_set(&buf, "\n[client]"); + if (opt_password) + { + if (dynstr_append(&buf, "\npassword=") + || dynstr_append(&buf, opt_password)) + { + ret = 1; + goto error; + } + } while (extra_defaults) { int len; @@ -459,7 +470,12 @@ int main(int argc, char **argv) load_defaults("my", load_default_groups, &argc, &argv); - if (handle_options(&argc, &argv, my_long_options, get_one_option)) + /* + Must init_dynamic_string before handle_options because string is freed + at error label. + */ + if (init_dynamic_string(&cmdline, NULL, 2 * FN_REFLEN + 128, FN_REFLEN) || + handle_options(&argc, &argv, my_long_options, get_one_option)) { ret= 1; goto error; @@ -467,11 +483,6 @@ int main(int argc, char **argv) if (tty_password) opt_password= get_tty_password(NullS); - if (init_dynamic_string(&cmdline, NULL, 2 * FN_REFLEN + 128, FN_REFLEN)) - { - ret= 1; - goto error; - } if (!basedir) { my_getwd(path, sizeof(path), MYF(0)); @@ -499,8 +510,9 @@ int main(int argc, char **argv) "mysql", NullS)) { ret= 1; - puts("Can't find data directory. Please restart with" - " --datadir=path-to-writable-data-dir"); + fprintf(stderr, + "Can't find data directory. Please restart with" + " --datadir=path-to-writable-data-dir"); goto error; } @@ -543,25 +555,44 @@ int main(int argc, char **argv) } if (find_file(mysqlcheck_name, basedir, MYF(0), path, sizeof(path), - "bin", NullS)) + "bin", EXTRA_CLIENT_PATHS, NullS)) { ret= 1; - printf("Can't find program '%s'\n", mysqlcheck_name); - puts("Please restart with --basedir=mysql-install-directory"); + fprintf(stderr, + "Can't find program '%s'\n" + "Please restart with --basedir=mysql-install-directory", + mysqlcheck_name); goto error; } else - dynstr_set(&cmdline, path); + { +#ifdef __WIN__ + /* Windows requires an extra pair of quotes around the entire string. */ + dynstr_set(&cmdline, "\""); +#else + dynstr_set(&cmdline, ""); +#endif /* __WIN__ */ + dynstr_append_os_quoted(&cmdline, path, NullS); + } if (defaults_to_use) { - dynstr_append(&cmdline, " --defaults-extra-file="); - dynstr_append(&cmdline, defaults_to_use); + dynstr_append(&cmdline, " "); + dynstr_append_os_quoted(&cmdline, "--defaults-extra-file=", + defaults_to_use, NullS); } - - dynstr_append(&cmdline, " --check-upgrade --all-databases" - " --auto-repair --user="); - dynstr_append(&cmdline, user); + + dynstr_append(&cmdline, " "); + dynstr_append_os_quoted(&cmdline, "--check-upgrade", NullS); + dynstr_append(&cmdline, " "); + dynstr_append_os_quoted(&cmdline, "--all-databases", NullS); + dynstr_append(&cmdline, " "); + dynstr_append_os_quoted(&cmdline, "--auto-repair", NullS); + dynstr_append(&cmdline, " "); + dynstr_append_os_quoted(&cmdline, "--user=", user, NullS); +#ifdef __WIN__ + dynstr_append(&cmdline, "\""); +#endif /* __WIN__ */ if (opt_verbose) printf("Running %s\n", cmdline.str); @@ -569,7 +600,7 @@ int main(int argc, char **argv) ret= system(cmdline.str); if (ret) { - printf("Error executing '%s'\n", cmdline.str); + fprintf(stderr, "Error executing '%s'\n", cmdline.str); goto error; } @@ -580,29 +611,39 @@ int main(int argc, char **argv) fix_priv_tables: if (find_file(mysql_name, basedir, MYF(0), path, sizeof(path), - "bin", NullS)) + "bin", EXTRA_CLIENT_PATHS, NullS)) { ret= 1; - puts("Could not find MySQL command-line client (mysql).\n" - "Please use --basedir to specify the directory" - " where MySQL is installed."); + fprintf(stderr, + "Could not find MySQL command-line client (mysql).\n" + "Please use --basedir to specify the directory" + " where MySQL is installed."); goto error; } else - dynstr_set(&cmdline, path); + { +#ifdef __WIN__ + /* Windows requires an extra pair of quotes around the entire string. */ + dynstr_set(&cmdline, "\""); +#else + dynstr_set(&cmdline, ""); +#endif /* __WIN__ */ + dynstr_append_os_quoted(&cmdline, path, NullS); + } if (find_file(MYSQL_FIX_PRIV_TABLES_NAME, basedir, MYF(0), path, sizeof(path), - "support_files", "share/mysql", "scripts", + "support_files", "share", "share/mysql", "scripts", NullS) && find_file(MYSQL_FIX_PRIV_TABLES_NAME, "/usr/local/mysql", MYF(0), path, sizeof(path), "share/mysql", NullS)) { ret= 1; - puts("Could not find file " MYSQL_FIX_PRIV_TABLES_NAME "\n" - "Please use --basedir to specify the directory" - " where MySQL is installed"); + fprintf(stderr, + "Could not find file " MYSQL_FIX_PRIV_TABLES_NAME "\n" + "Please use --basedir to specify the directory" + " where MySQL is installed"); goto error; } else @@ -610,20 +651,32 @@ fix_priv_tables: if (defaults_to_use) { - dynstr_append(&cmdline, " --defaults-extra-file="); - dynstr_append(&cmdline, defaults_to_use); + dynstr_append(&cmdline, " "); + dynstr_append_os_quoted(&cmdline, "--defaults-extra-file=", + defaults_to_use, NullS); } - dynstr_append(&cmdline, " --force --no-auto-rehash --batch --user="); - dynstr_append(&cmdline, user); - dynstr_append(&cmdline, " mysql < "); - dynstr_append(&cmdline, script_line); + dynstr_append(&cmdline, " "); + dynstr_append_os_quoted(&cmdline, "--force", NullS); + dynstr_append(&cmdline, " "); + dynstr_append_os_quoted(&cmdline, "--no-auto-rehash", NullS); + dynstr_append(&cmdline, " "); + dynstr_append_os_quoted(&cmdline, "--batch", NullS); + dynstr_append(&cmdline, " "); + dynstr_append_os_quoted(&cmdline, "--user=", user, NullS); + dynstr_append(&cmdline, " "); + dynstr_append_os_quoted(&cmdline, "--database=mysql", NullS); + dynstr_append(&cmdline, " < "); + dynstr_append_os_quoted(&cmdline, script_line, NullS); +#ifdef __WIN__ + dynstr_append(&cmdline, "\""); +#endif /* __WIN__ */ if (opt_verbose) printf("Running %s\n", cmdline.str); ret= system(cmdline.str); if (ret) - printf("Error executing '%s'\n", cmdline.str); + fprintf(stderr, "Error executing '%s'\n", cmdline.str); error: dynstr_free(&cmdline); diff --git a/client/mysqladmin.cc b/client/mysqladmin.cc index 57ab4e071fb..c7033f6914f 100644 --- a/client/mysqladmin.cc +++ b/client/mysqladmin.cc @@ -1,9 +1,8 @@ -/* Copyright (C) 2000-2004 MySQL AB +/* Copyright (C) 2000-2006 MySQL 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 - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. + the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -614,7 +613,7 @@ static int execute_commands(MYSQL *mysql,int argc, char **argv) case ADMIN_VER: new_line=1; print_version(); - puts("Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB"); + puts("Copyright (C) 2000-2006 MySQL AB"); puts("This software comes with ABSOLUTELY NO WARRANTY. This is free software,\nand you are welcome to modify and redistribute it under the GPL license\n"); printf("Server version\t\t%s\n", mysql_get_server_info(mysql)); printf("Protocol version\t%d\n", mysql_get_proto_info(mysql)); @@ -1003,7 +1002,7 @@ static void print_version(void) static void usage(void) { print_version(); - puts("Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB"); + puts("Copyright (C) 2000-2006 MySQL AB"); puts("This software comes with ABSOLUTELY NO WARRANTY. This is free software,\nand you are welcome to modify and redistribute it under the GPL license\n"); puts("Administration program for the mysqld daemon."); printf("Usage: %s [OPTIONS] command command....\n", my_progname); diff --git a/client/mysqlbinlog.cc b/client/mysqlbinlog.cc index ff4e0b5a5cf..7489cdb334c 100644 --- a/client/mysqlbinlog.cc +++ b/client/mysqlbinlog.cc @@ -2,8 +2,7 @@ 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 - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. + the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -94,8 +93,10 @@ static bool stop_passed= 0; */ Format_description_log_event* description_event; -static int dump_local_log_entries(const char* logname); -static int dump_remote_log_entries(const char* logname); +static int dump_local_log_entries(PRINT_EVENT_INFO *print_event_info, + const char* logname); +static int dump_remote_log_entries(PRINT_EVENT_INFO *print_event_info, + const char* logname); static int dump_log_entries(const char* logname); static int dump_remote_file(NET* net, const char* fname); static void die(const char* fmt, ...); @@ -950,8 +951,22 @@ static MYSQL* safe_connect() static int dump_log_entries(const char* logname) { - return (remote_opt ? dump_remote_log_entries(logname) : - dump_local_log_entries(logname)); + int rc; + PRINT_EVENT_INFO print_event_info; + /* + Set safe delimiter, to dump things + like CREATE PROCEDURE safely + */ + fprintf(result_file, "DELIMITER /*!*/;\n"); + strcpy(print_event_info.delimiter, "/*!*/;"); + + rc= (remote_opt ? dump_remote_log_entries(&print_event_info, logname) : + dump_local_log_entries(&print_event_info, logname)); + + /* Set delimiter back to semicolon */ + fprintf(result_file, "DELIMITER ;\n"); + strcpy(print_event_info.delimiter, ";"); + return rc; } @@ -1016,11 +1031,11 @@ static int check_master_version(MYSQL* mysql, } -static int dump_remote_log_entries(const char* logname) +static int dump_remote_log_entries(PRINT_EVENT_INFO *print_event_info, + const char* logname) { char buf[128]; - PRINT_EVENT_INFO print_event_info; ulong len; uint logname_len; NET* net; @@ -1143,7 +1158,7 @@ could be out of memory"); len= 1; // fake Rotate, so don't increment old_off } } - if ((error= process_event(&print_event_info, ev, old_off))) + if ((error= process_event(print_event_info, ev, old_off))) { error= ((error < 0) ? 0 : 1); goto err; @@ -1162,7 +1177,7 @@ could be out of memory"); goto err; } - if ((error= process_event(&print_event_info, ev, old_off))) + if ((error= process_event(print_event_info, ev, old_off))) { my_close(file,MYF(MY_WME)); error= ((error < 0) ? 0 : 1); @@ -1288,11 +1303,11 @@ at offset %lu ; this could be a log format error or read error", } -static int dump_local_log_entries(const char* logname) +static int dump_local_log_entries(PRINT_EVENT_INFO *print_event_info, + const char* logname) { File fd = -1; IO_CACHE cache,*file= &cache; - PRINT_EVENT_INFO print_event_info; byte tmp_buff[BIN_LOG_HEADER_SIZE]; int error= 0; @@ -1310,6 +1325,25 @@ static int dump_local_log_entries(const char* logname) } else // reading from stdin; { + /* + Bug fix: #23735 + Author: Chuck Bell + Description: + Windows opens stdin in text mode by default. Certain characters + such as CTRL-Z are interpeted as events and the read() method + will stop. CTRL-Z is the EOF marker in Windows. to get past this + you have to open stdin in binary mode. Setmode() is used to set + stdin in binary mode. Errors on setting this mode result in + halting the function and printing an error message to stderr. + */ +#if defined (__WIN__) || (_WIN64) + if (_setmode(fileno(stdin), O_BINARY) == -1) + { + fprintf(stderr, "Could not set binary mode on stdin.\n"); + return 1; + } +#endif + if (init_io_cache(file, fileno(stdin), 0, READ_CACHE, (my_off_t) 0, 0, MYF(MY_WME | MY_NABP | MY_DONT_CHECK_FILESIZE))) return 1; @@ -1364,7 +1398,7 @@ static int dump_local_log_entries(const char* logname) // file->error == 0 means EOF, that's OK, we break in this case break; } - if ((error= process_event(&print_event_info, ev, old_off))) + if ((error= process_event(print_event_info, ev, old_off))) { if (error < 0) error= 0; diff --git a/client/mysqlcheck.c b/client/mysqlcheck.c index 5d87a4fd23c..b69e9201a28 100644 --- a/client/mysqlcheck.c +++ b/client/mysqlcheck.c @@ -2,8 +2,7 @@ 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 - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. + the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of diff --git a/client/mysqldump.c b/client/mysqldump.c index 2be60b2df9a..0dfc7ee8e3c 100644 --- a/client/mysqldump.c +++ b/client/mysqldump.c @@ -2,8 +2,7 @@ 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 - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. + the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -1419,7 +1418,7 @@ static uint dump_routines_for_db(char *db) routine body of other routines that are not the creator of! */ DBUG_PRINT("info",("length of body for %s row[2] '%s' is %d", - routine_name, row[2], strlen(row[2]))); + routine_name, row[2], (int) strlen(row[2]))); if (strlen(row[2])) { char *query_str= NULL; @@ -2001,7 +2000,7 @@ continue_xml: write_footer(sql_file); my_fclose(sql_file, MYF(MY_WME)); } - DBUG_RETURN(num_fields); + DBUG_RETURN((uint) num_fields); } /* get_table_structure */ diff --git a/client/mysqlimport.c b/client/mysqlimport.c index 67659684c9c..e7bf1cfd889 100644 --- a/client/mysqlimport.c +++ b/client/mysqlimport.c @@ -1,9 +1,8 @@ -/* Copyright (C) 2000 MySQL AB +/* Copyright (C) 2000-2006 MySQL 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 - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. + the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -165,7 +164,7 @@ static void print_version(void) static void usage(void) { print_version(); - puts("Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB"); + puts("Copyright (C) 2000-2006 MySQL AB"); puts("This software comes with ABSOLUTELY NO WARRANTY. This is free software,\nand you are welcome to modify and redistribute it under the GPL license\n"); printf("\ Loads tables from text files in various formats. The base name of the\n\ diff --git a/client/mysqlmanager-pwgen.c b/client/mysqlmanager-pwgen.c index 1d942e207ad..716a1e4bf4e 100644 --- a/client/mysqlmanager-pwgen.c +++ b/client/mysqlmanager-pwgen.c @@ -2,8 +2,7 @@ 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 - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. + the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of diff --git a/client/mysqlmanagerc.c b/client/mysqlmanagerc.c index 0001a0266e6..1fdedab97fb 100644 --- a/client/mysqlmanagerc.c +++ b/client/mysqlmanagerc.c @@ -2,8 +2,7 @@ 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 - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. + the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of diff --git a/client/mysqlshow.c b/client/mysqlshow.c index 40405c53565..5be01cc5a52 100644 --- a/client/mysqlshow.c +++ b/client/mysqlshow.c @@ -1,9 +1,8 @@ -/* Copyright (C) 2000 MySQL AB +/* Copyright (C) 2000-2006 MySQL 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 - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. + the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -236,7 +235,7 @@ static void print_version(void) static void usage(void) { print_version(); - puts("Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB"); + puts("Copyright (C) 2000-2006 MySQL AB"); puts("This software comes with ABSOLUTELY NO WARRANTY. This is free software,\nand you are welcome to modify and redistribute it under the GPL license\n"); puts("Shows the structure of a mysql database (databases,tables and columns)\n"); printf("Usage: %s [OPTIONS] [database [table [column]]]\n",my_progname); diff --git a/client/mysqltest.c b/client/mysqltest.c index 2063d31251d..e2d2f0f45a6 100644 --- a/client/mysqltest.c +++ b/client/mysqltest.c @@ -2,8 +2,7 @@ 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 - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. + the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -32,7 +31,7 @@ Holyfoot */ -#define MTEST_VERSION "3.0" +#define MTEST_VERSION "3.1" #include <my_global.h> #include <mysql_embed.h> @@ -103,6 +102,7 @@ static my_bool disable_query_log= 0, disable_result_log= 0; static my_bool disable_warnings= 0, disable_ps_warnings= 0; static my_bool disable_info= 1; static my_bool abort_on_error= 1; +static my_bool server_initialized= 0; static char **default_argv; static const char *load_default_groups[]= { "mysqltest", "client", 0 }; @@ -222,11 +222,13 @@ struct st_connection char *name; MYSQL_STMT* stmt; +#ifdef EMBEDDED_LIBRARY const char *cur_query; int cur_query_len; pthread_mutex_t mutex; pthread_cond_t cond; int query_done; +#endif /*EMBEDDED_LIBRARY*/ }; struct st_connection connections[128]; struct st_connection* cur_con, *next_con, *connections_end; @@ -271,6 +273,7 @@ enum enum_commands { Q_DISABLE_PARSING, Q_ENABLE_PARSING, Q_REPLACE_REGEX, Q_REMOVE_FILE, Q_FILE_EXIST, Q_WRITE_FILE, Q_COPY_FILE, Q_PERL, Q_DIE, Q_EXIT, + Q_CHMOD_FILE, Q_UNKNOWN, /* Unknown command. */ Q_COMMENT, /* Comments, ignored. */ @@ -351,8 +354,10 @@ const char *command_names[]= "copy_file", "perl", "die", + /* Don't execute any more commands, compare result */ "exit", + "chmod", 0 }; @@ -719,6 +724,20 @@ void close_connections() } +void close_statements() +{ + struct st_connection *con; + DBUG_ENTER("close_statements"); + for (con= connections; con < next_con; con++) + { + if (con->stmt) + mysql_stmt_close(con->stmt); + con->stmt= 0; + } + DBUG_VOID_RETURN; +} + + void close_files() { DBUG_ENTER("close_files"); @@ -765,13 +784,18 @@ void free_used_memory() free_all_replace(); my_free(pass,MYF(MY_ALLOW_ZERO_PTR)); free_defaults(default_argv); - mysql_server_end(); free_re(); #ifdef __WIN__ free_tmp_sh_file(); free_win_path_patterns(); #endif - DBUG_VOID_RETURN; + + /* Only call mysql_server_end if mysql_server_init has been called */ + if (server_initialized) + mysql_server_end(); + + /* Don't use DBUG after mysql_server_end() */ + return; } @@ -946,8 +970,8 @@ int dyn_string_cmp(DYNAMIC_STRING* ds, const char *fname) die(NullS); if (!eval_result && (uint) stat_info.st_size != ds->length) { - DBUG_PRINT("info",("Size differs: result size: %u file size: %llu", - ds->length, stat_info.st_size)); + DBUG_PRINT("info",("Size differs: result size: %u file size: %lu", + ds->length, (ulong) stat_info.st_size)); DBUG_PRINT("info",("result: '%s'", ds->str)); DBUG_RETURN(RESULT_LENGTH_MISMATCH); } @@ -1235,7 +1259,9 @@ void var_set(const char *var_name, const char *var_name_end, v->int_dirty= 0; v->str_val_len= strlen(v->str_val); } - strxmov(buf, v->name, "=", v->str_val, NullS); + my_snprintf(buf, sizeof(buf), "%.*s=%.*s", + v->name_len, v->name, + v->str_val_len, v->str_val); if (!(v->env_s= my_strdup(buf, MYF(MY_WME)))) die("Out of memory"); putenv(v->env_s); @@ -1809,6 +1835,46 @@ void do_copy_file(struct st_command *command) /* SYNOPSIS + do_chmod_file + command command handle + + DESCRIPTION + chmod <octal> <file> + Change file permission of <file> + +*/ + +void do_chmod_file(struct st_command *command) +{ + ulong mode= 0; + static DYNAMIC_STRING ds_mode; + static DYNAMIC_STRING ds_file; + const struct command_arg chmod_file_args[] = { + "mode", ARG_STRING, TRUE, &ds_mode, "Mode of file", + "file", ARG_STRING, TRUE, &ds_file, "Filename of file to modify" + }; + DBUG_ENTER("do_chmod_file"); + + check_command_args(command, command->first_argument, + chmod_file_args, + sizeof(chmod_file_args)/sizeof(struct command_arg), + ' '); + + /* Parse what mode to set */ + if (ds_mode.length != 4 || + str2int(ds_mode.str, 8, 0, INT_MAX, &mode) == NullS) + die("You must write a 4 digit octal number for mode"); + + DBUG_PRINT("info", ("chmod %o %s", (uint)mode, ds_file.str)); + handle_command_error(command, chmod(ds_file.str, mode)); + dynstr_free(&ds_mode); + dynstr_free(&ds_file); + DBUG_VOID_RETURN; +} + + +/* + SYNOPSIS do_file_exists command called command @@ -2855,6 +2921,10 @@ void do_close_connection(struct st_command *command) } } #endif + if (next_con->stmt) + mysql_stmt_close(next_con->stmt); + next_con->stmt= 0; + mysql_close(&con->mysql); if (con->util_mysql) mysql_close(con->util_mysql); @@ -2916,12 +2986,19 @@ void safe_connect(MYSQL* mysql, const char *name, const char *host, Connect failed Only allow retry if this was an error indicating the server - could not be contacted + could not be contacted. Error code differs depending + on protocol/connection type */ - if (mysql_errno(mysql) == CR_CONNECTION_ERROR && + if ((mysql_errno(mysql) == CR_CONN_HOST_ERROR || + mysql_errno(mysql) == CR_CONNECTION_ERROR) && failed_attempts < opt_max_connect_retries) + { + verbose_msg("Connect attempt %d/%d failed: %d: %s", failed_attempts, + opt_max_connect_retries, mysql_errno(mysql), + mysql_error(mysql)); my_sleep(connection_retry_sleep); + } else { if (failed_attempts > 0) @@ -3130,14 +3207,15 @@ void do_connect(struct st_command *command) else if (!strncmp(con_options, "COMPRESS", 8)) con_compress= 1; else - die("Illegal option to connect: %.*s", end - con_options, con_options); + die("Illegal option to connect: %.*s", + (int) (end - con_options), con_options); /* Process next option */ con_options= end; } if (next_con == connections_end) die("Connection limit exhausted, you can have max %d connections", - (sizeof(connections)/sizeof(struct st_connection))); + (int) (sizeof(connections)/sizeof(struct st_connection))); if (find_connection_by_name(ds_connection_name.str)) die("Connection %s already exists", ds_connection_name.str); @@ -3458,10 +3536,10 @@ int read_line(char *buf, int size) DBUG_RETURN(0); } else if ((c == '{' && - (!my_strnncoll_simple(charset_info, "while", 5, - buf, min(5, p - buf), 0) || - !my_strnncoll_simple(charset_info, "if", 2, - buf, min(2, p - buf), 0)))) + (!my_strnncoll_simple(charset_info, (const uchar*) "while", 5, + (uchar*) buf, min(5, p - buf), 0) || + !my_strnncoll_simple(charset_info, (const uchar*) "if", 2, + (uchar*) buf, min(2, p - buf), 0)))) { /* Only if and while commands can be terminated by { */ *p++= c; @@ -4193,8 +4271,9 @@ void init_win_path_patterns() /* List of string patterns to match in order to find paths */ const char* paths[] = { "$MYSQL_TEST_DIR", "$MYSQL_TMP_DIR", - "./test/", 0 }; - int num_paths= 3; + "$MYSQLTEST_VARDIR", + "./test/" }; + int num_paths= sizeof(paths)/sizeof(char*); int i; char* p; @@ -4214,6 +4293,13 @@ void init_win_path_patterns() else p= my_strdup(paths[i], MYF(MY_FAE)); + /* Don't insert zero length strings in patterns array */ + if (strlen(p) == 0) + { + my_free(p, MYF(0)); + continue; + } + if (insert_dynamic(&patterns, (gptr) &p)) die(NullS); @@ -4263,7 +4349,7 @@ void fix_win_paths(const char *val, int len) { const char** pattern= dynamic_element(&patterns, i, const char**); DBUG_PRINT("info", ("pattern: %s", *pattern)); - if (strlen(*pattern) == 0) continue; + /* Search for the path in string */ while ((p= strstr(val, *pattern))) { @@ -4623,10 +4709,9 @@ void run_query_normal(struct st_connection *cn, struct st_command *command, } /* - Store the result. If res is NULL, use mysql_field_count to - determine if that was expected + Store the result of the query if it will return any fields */ - if (!(res= mysql_store_result(mysql)) && mysql_field_count(mysql)) + if (mysql_field_count(mysql) && ((res= mysql_store_result(mysql)) == 0)) { handle_error(command, mysql_errno(mysql), mysql_error(mysql), mysql_sqlstate(mysql), ds); @@ -4678,7 +4763,10 @@ void run_query_normal(struct st_connection *cn, struct st_command *command, } if (res) + { mysql_free_result(res); + res= 0; + } counter++; } while (!(err= mysql_next_result(mysql))); if (err > 0) @@ -4745,7 +4833,7 @@ void handle_error(struct st_command *command, err_errno, err_error); /* Abort the run of this test, pass the failed query as reason */ - abort_not_supported_test("Query '%s' failed, required functionality" \ + abort_not_supported_test("Query '%s' failed, required functionality " \ "not supported", command->query); } @@ -5035,6 +5123,14 @@ end: dynstr_free(&ds_execute_warnings); } + + /* Close the statement if - no reconnect, need new prepare */ + if (mysql->reconnect) + { + mysql_stmt_close(stmt); + cur_con->stmt= NULL; + } + /* We save the return code (mysql_stmt_errno(stmt)) from the last call sent to the server into the mysqltest builtin variable $mysql_errno. This @@ -5042,10 +5138,7 @@ end: */ var_set_errno(mysql_stmt_errno(stmt)); -#ifndef BUG15518_FIXED - mysql_stmt_close(stmt); - cur_con->stmt= NULL; -#endif + DBUG_VOID_RETURN; } @@ -5565,6 +5658,7 @@ int main(int argc, char **argv) embedded_server_args, (char**) embedded_server_groups)) die("Can't initialize MySQL server"); + server_initialized= 1; if (cur_file == file_stack && cur_file->file == 0) { cur_file->file= stdin; @@ -5684,6 +5778,7 @@ int main(int argc, char **argv) case Q_FILE_EXIST: do_file_exist(command); break; case Q_WRITE_FILE: do_write_file(command); break; case Q_COPY_FILE: do_copy_file(command); break; + case Q_CHMOD_FILE: do_chmod_file(command); break; case Q_PERL: do_perl(command); break; case Q_DELIMITER: do_delimiter(command); @@ -5830,6 +5925,8 @@ int main(int argc, char **argv) break; case Q_DISABLE_PS_PROTOCOL: ps_protocol_enabled= 0; + /* Close any open statements */ + close_statements(); break; case Q_ENABLE_PS_PROTOCOL: ps_protocol_enabled= ps_protocol; @@ -5839,6 +5936,8 @@ int main(int argc, char **argv) break; case Q_ENABLE_RECONNECT: set_reconnect(&cur_con->mysql, 1); + /* Close any open statements - no reconnect, need new prepare */ + close_statements(); break; case Q_DISABLE_PARSING: if (parsing_disabled == 0) @@ -6516,7 +6615,7 @@ int reg_replace(char** buf_p, int* buf_len_p, char *pattern, { my_regex_t r; my_regmatch_t *subs; - char *buf_end, *replace_end; + char *replace_end; char *buf= *buf_p; int len; int buf_len, need_buf_len; @@ -6536,8 +6635,6 @@ int reg_replace(char** buf_p, int* buf_len_p, char *pattern, SECURE_REG_BUF - buf_end= buf + buf_len; - if (icase) cflags|= REG_ICASE; diff --git a/client/readline.cc b/client/readline.cc index 3d524633d69..ad42ed2ee10 100644 --- a/client/readline.cc +++ b/client/readline.cc @@ -2,8 +2,7 @@ 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 - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. + the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -51,7 +50,8 @@ char *batch_readline(LINE_BUFFER *line_buff) if (!(pos=intern_read_line(line_buff,&out_length))) return 0; if (out_length && pos[out_length-1] == '\n') - out_length--; /* Remove '\n' */ + if (--out_length && pos[out_length-1] == '\r') /* Remove '\n' */ + out_length--; /* Remove '\r' */ line_buff->read_length=out_length; pos[out_length]=0; return pos; diff --git a/client/sql_string.cc b/client/sql_string.cc index 51f802e7465..7d7d5d70754 100644 --- a/client/sql_string.cc +++ b/client/sql_string.cc @@ -2,8 +2,7 @@ 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 - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. + the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of diff --git a/client/sql_string.h b/client/sql_string.h index e284301b214..0e0d2452297 100644 --- a/client/sql_string.h +++ b/client/sql_string.h @@ -2,8 +2,7 @@ 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 - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. + the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of |