summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
authorAlexander Nozdrin <alik@sun.com>2009-12-11 12:39:38 +0300
committerAlexander Nozdrin <alik@sun.com>2009-12-11 12:39:38 +0300
commit567671368723c704d60902b4d0ccff951b414552 (patch)
tree965519a5b0af3f33624c7e16fd61b58d15f42372 /client
parentefee0608316e4cc034a3e62d05980eef8530843d (diff)
parentceefe7bb50b17b72e88851e3b98642e89a4cddae (diff)
downloadmariadb-git-567671368723c704d60902b4d0ccff951b414552.tar.gz
Manual merge from mysql-trunk.
Conflicts: - client/mysqltest.cc - mysql-test/collections/default.experimental - mysql-test/suite/rpl/t/disabled.def - sql/mysqld.cc - sql/opt_range.cc - sql/sp.cc - sql/sql_acl.cc - sql/sql_partition.cc - sql/sql_table.cc
Diffstat (limited to 'client')
-rwxr-xr-xclient/CMakeLists.txt27
-rw-r--r--client/client_priv.h1
-rw-r--r--client/my_readline.h5
-rw-r--r--client/mysql.cc27
-rw-r--r--client/mysql_upgrade.c22
-rw-r--r--client/mysqladmin.cc5
-rw-r--r--client/mysqlbinlog.cc6
-rw-r--r--client/mysqlcheck.c14
-rw-r--r--client/mysqldump.c206
-rw-r--r--client/mysqlimport.c8
-rw-r--r--client/mysqlshow.c2
-rw-r--r--client/mysqlslap.c2
-rw-r--r--client/mysqltest.cc153
-rw-r--r--client/readline.cc2
-rw-r--r--client/sql_string.h5
15 files changed, 217 insertions, 268 deletions
diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt
index e96437d40d0..28e4c354a69 100755
--- a/client/CMakeLists.txt
+++ b/client/CMakeLists.txt
@@ -14,13 +14,6 @@
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
INCLUDE("${PROJECT_SOURCE_DIR}/win/mysql_manifest.cmake")
-# We use the "mysqlclient_notls" library here just as safety, in case
-# any of the clients here would go beyond the client API and access the
-# Thread Local Storage directly.
-
-SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DSAFEMALLOC -DSAFE_MUTEX")
-SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DSAFEMALLOC -DSAFE_MUTEX")
-
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include
${CMAKE_SOURCE_DIR}/zlib
${CMAKE_SOURCE_DIR}/extra/yassl/include
@@ -30,27 +23,27 @@ INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include
${CMAKE_SOURCE_DIR}/strings)
ADD_EXECUTABLE(mysql completion_hash.cc mysql.cc readline.cc sql_string.cc ../mysys/my_conio.c)
-TARGET_LINK_LIBRARIES(mysql mysqlclient_notls wsock32)
+TARGET_LINK_LIBRARIES(mysql mysqlclient)
ADD_EXECUTABLE(mysqltest mysqltest.cc)
SET_SOURCE_FILES_PROPERTIES(mysqltest.cc PROPERTIES COMPILE_FLAGS "-DTHREADS")
-TARGET_LINK_LIBRARIES(mysqltest mysqlclient mysys regex wsock32 dbug)
+TARGET_LINK_LIBRARIES(mysqltest mysqlclient mysys regex dbug)
ADD_EXECUTABLE(mysqlcheck mysqlcheck.c)
-TARGET_LINK_LIBRARIES(mysqlcheck mysqlclient_notls wsock32)
+TARGET_LINK_LIBRARIES(mysqlcheck mysqlclient)
ADD_EXECUTABLE(mysqldump mysqldump.c ../sql-common/my_user.c ../mysys/mf_getdate.c)
-TARGET_LINK_LIBRARIES(mysqldump mysqlclient_notls wsock32)
+TARGET_LINK_LIBRARIES(mysqldump mysqlclient)
ADD_EXECUTABLE(mysqlimport mysqlimport.c)
-TARGET_LINK_LIBRARIES(mysqlimport mysqlclient_notls wsock32)
+TARGET_LINK_LIBRARIES(mysqlimport mysqlclient)
ADD_EXECUTABLE(mysql_upgrade mysql_upgrade.c ../mysys/my_getpagesize.c)
-TARGET_LINK_LIBRARIES(mysql_upgrade mysqlclient_notls wsock32)
+TARGET_LINK_LIBRARIES(mysql_upgrade mysqlclient)
ADD_DEPENDENCIES(mysql_upgrade GenFixPrivs)
ADD_EXECUTABLE(mysqlshow mysqlshow.c)
-TARGET_LINK_LIBRARIES(mysqlshow mysqlclient_notls wsock32)
+TARGET_LINK_LIBRARIES(mysqlshow mysqlclient)
ADD_EXECUTABLE(mysqlbinlog mysqlbinlog.cc
../mysys/mf_tempdir.c
@@ -59,14 +52,14 @@ ADD_EXECUTABLE(mysqlbinlog mysqlbinlog.cc
../mysys/my_bitmap.c
../mysys/my_vle.c
../mysys/base64.c)
-TARGET_LINK_LIBRARIES(mysqlbinlog mysqlclient_notls wsock32)
+TARGET_LINK_LIBRARIES(mysqlbinlog mysqlclient)
ADD_EXECUTABLE(mysqladmin mysqladmin.cc)
-TARGET_LINK_LIBRARIES(mysqladmin mysqlclient_notls wsock32)
+TARGET_LINK_LIBRARIES(mysqladmin mysqlclient)
ADD_EXECUTABLE(mysqlslap mysqlslap.c)
SET_SOURCE_FILES_PROPERTIES(mysqlslap.c PROPERTIES COMPILE_FLAGS "-DTHREADS")
-TARGET_LINK_LIBRARIES(mysqlslap mysqlclient mysys zlib wsock32 dbug)
+TARGET_LINK_LIBRARIES(mysqlslap mysqlclient mysys zlib dbug)
ADD_EXECUTABLE(echo echo.c)
diff --git a/client/client_priv.h b/client/client_priv.h
index 06145232995..e99d34ffa97 100644
--- a/client/client_priv.h
+++ b/client/client_priv.h
@@ -80,5 +80,6 @@ enum options_client
OPT_FIX_TABLE_NAMES, OPT_FIX_DB_NAMES, OPT_SSL_VERIFY_SERVER_CERT,
OPT_DEBUG_INFO, OPT_DEBUG_CHECK, OPT_COLUMN_TYPES, OPT_ERROR_LOG_FILE,
OPT_WRITE_BINLOG, OPT_DUMP_DATE,
+ OPT_INIT_COMMAND,
OPT_MAX_CLIENT_OPTION
};
diff --git a/client/my_readline.h b/client/my_readline.h
index 62ad19bece9..08cff565819 100644
--- a/client/my_readline.h
+++ b/client/my_readline.h
@@ -1,3 +1,6 @@
+#ifndef CLIENT_MY_READLINE_INCLUDED
+#define CLIENT_MY_READLINE_INCLUDED
+
/* Copyright (C) 2000 MySQL AB
This program is free software; you can redistribute it and/or modify
@@ -31,3 +34,5 @@ extern LINE_BUFFER *batch_readline_init(ulong max_size,FILE *file);
extern LINE_BUFFER *batch_readline_command(LINE_BUFFER *buffer, char * str);
extern char *batch_readline(LINE_BUFFER *buffer, bool *truncated);
extern void batch_readline_end(LINE_BUFFER *buffer);
+
+#endif /* CLIENT_MY_READLINE_INCLUDED */
diff --git a/client/mysql.cc b/client/mysql.cc
index 9d078153a33..548feb5a1c7 100644
--- a/client/mysql.cc
+++ b/client/mysql.cc
@@ -141,7 +141,7 @@ static my_bool ignore_errors=0,wait_flag=0,quick=0,
vertical=0, line_numbers=1, column_names=1,opt_html=0,
opt_xml=0,opt_nopager=1, opt_outfile=0, named_cmds= 0,
tty_password= 0, opt_nobeep=0, opt_reconnect=1,
- default_charset_used= 0, opt_secure_auth= 0,
+ opt_secure_auth= 0,
default_pager_set= 0, opt_sigint_ignore= 0,
show_warnings= 0, executing_query= 0, interrupted_query= 0,
ignore_spaces= 0;
@@ -155,7 +155,8 @@ static char * opt_mysql_unix_port=0;
static int connect_flag=CLIENT_INTERACTIVE;
static char *current_host,*current_db,*current_user=0,*opt_password=0,
*current_prompt=0, *delimiter_str= 0,
- *default_charset= (char*) MYSQL_DEFAULT_CHARSET_NAME;
+ *default_charset= (char*) MYSQL_AUTODETECT_CHARSET_NAME,
+ *opt_init_command= 0;
static char *histfile;
static char *histfile_tmp;
static String glob_buffer,old_buffer;
@@ -1398,6 +1399,10 @@ static struct my_option my_long_options[] =
{"ignore-spaces", 'i', "Ignore space after function names.",
(uchar**) &ignore_spaces, (uchar**) &ignore_spaces, 0, GET_BOOL, NO_ARG, 0, 0,
0, 0, 0, 0},
+ {"init-command", OPT_INIT_COMMAND,
+ "SQL Command to execute when connecting to MySQL server. Will automatically be re-executed when reconnecting.",
+ (uchar**) &opt_init_command, (uchar**) &opt_init_command, 0,
+ GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"local-infile", OPT_LOCAL_INFILE, "Enable/disable LOAD DATA LOCAL INFILE.",
(uchar**) &opt_local_infile,
(uchar**) &opt_local_infile, 0, GET_BOOL, OPT_ARG, 0, 0, 0, 0, 0, 0},
@@ -1590,9 +1595,6 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
strmake(mysql_charsets_dir, argument, sizeof(mysql_charsets_dir) - 1);
charsets_dir = mysql_charsets_dir;
break;
- case OPT_DEFAULT_CHARSET:
- default_charset_used= 1;
- break;
case OPT_DELIMITER:
if (argument == disabled_my_option)
{
@@ -1797,10 +1799,6 @@ static int get_options(int argc, char **argv)
connect_flag= 0; /* Not in interactive mode */
}
- if (strcmp(default_charset, charset_info->csname) &&
- !(charset_info= get_charset_by_csname(default_charset,
- MY_CS_PRIMARY, MYF(MY_WME))))
- exit(1);
if (argc > 1)
{
usage(0);
@@ -2928,7 +2926,6 @@ com_charset(String *buffer __attribute__((unused)), char *line)
charset_info= new_cs;
mysql_set_character_set(&mysql, charset_info->csname);
default_charset= (char *)charset_info->csname;
- default_charset_used= 1;
put_info("Charset changed", INFO_INFO);
}
else put_info("Charset is not found", INFO_INFO);
@@ -4217,6 +4214,8 @@ sql_real_connect(char *host,char *database,char *user,char *password,
mysql_close(&mysql);
}
mysql_init(&mysql);
+ if (opt_init_command)
+ mysql_options(&mysql, MYSQL_INIT_COMMAND, opt_init_command);
if (opt_connect_timeout)
{
uint timeout=opt_connect_timeout;
@@ -4250,8 +4249,9 @@ sql_real_connect(char *host,char *database,char *user,char *password,
select_limit,max_join_size);
mysql_options(&mysql, MYSQL_INIT_COMMAND, init_command);
}
- if (default_charset_used)
- mysql_options(&mysql, MYSQL_SET_CHARSET_NAME, default_charset);
+
+ mysql_options(&mysql, MYSQL_SET_CHARSET_NAME, default_charset);
+
if (!mysql_real_connect(&mysql, host, user, password,
database, opt_mysql_port, opt_mysql_unix_port,
connect_flag | CLIENT_MULTI_STATEMENTS))
@@ -4266,6 +4266,9 @@ sql_real_connect(char *host,char *database,char *user,char *password,
}
return -1; // Retryable
}
+
+ charset_info= mysql.charset;
+
connected=1;
#ifndef EMBEDDED_LIBRARY
mysql.reconnect= debug_info_flag; // We want to know if this happens
diff --git a/client/mysql_upgrade.c b/client/mysql_upgrade.c
index 52c3636219d..05eb80e5455 100644
--- a/client/mysql_upgrade.c
+++ b/client/mysql_upgrade.c
@@ -34,7 +34,8 @@
static char mysql_path[FN_REFLEN];
static char mysqlcheck_path[FN_REFLEN];
-static my_bool opt_force, opt_verbose, debug_info_flag, debug_check_flag;
+static my_bool opt_force, opt_verbose, debug_info_flag, debug_check_flag,
+ opt_systables_only;
static uint my_end_arg= 0;
static char *opt_user= (char*)"root";
@@ -121,6 +122,10 @@ static struct my_option my_long_options[]=
#include <sslopt-longopts.h>
{"tmpdir", 't', "Directory for temporary files",
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
+ {"upgrade-system-tables", 's', "Only upgrade the system tables "
+ "do not try to upgrade the data.",
+ (uchar**)&opt_systables_only, (uchar**)&opt_systables_only, 0,
+ GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"user", 'u', "User for login if not current user.", (uchar**) &opt_user,
(uchar**) &opt_user, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"verbose", 'v', "Display more output about the process",
@@ -838,8 +843,15 @@ int main(int argc, char **argv)
/* Find mysql */
find_tool(mysql_path, IF_WIN("mysql.exe", "mysql"), self_name);
- /* Find mysqlcheck */
- find_tool(mysqlcheck_path, IF_WIN("mysqlcheck.exe", "mysqlcheck"), self_name);
+ if (!opt_systables_only)
+ {
+ /* Find mysqlcheck */
+ find_tool(mysqlcheck_path, IF_WIN("mysqlcheck.exe", "mysqlcheck"), self_name);
+ }
+ else
+ {
+ printf("The --upgrade-system-tables option was used, databases won't be touched.\n");
+ }
/*
Read the mysql_upgrade_info file to check if mysql_upgrade
@@ -856,8 +868,8 @@ int main(int argc, char **argv)
/*
Run "mysqlcheck" and "mysql_fix_privilege_tables.sql"
*/
- if (run_mysqlcheck_fixnames() ||
- run_mysqlcheck_upgrade() ||
+ if ((!opt_systables_only &&
+ (run_mysqlcheck_fixnames() || run_mysqlcheck_upgrade())) ||
run_sql_fix_privilege_tables())
{
/*
diff --git a/client/mysqladmin.cc b/client/mysqladmin.cc
index 2b93c149523..a3eee14e0d1 100644
--- a/client/mysqladmin.cc
+++ b/client/mysqladmin.cc
@@ -30,7 +30,7 @@
#define MAX_TRUNC_LENGTH 3
char *host= NULL, *user= 0, *opt_password= 0,
- *default_charset= NULL;
+ *default_charset= (char*) MYSQL_AUTODETECT_CHARSET_NAME;
char truncated_var_names[MAX_MYSQL_VAR][MAX_TRUNC_LENGTH];
char ex_var_names[MAX_MYSQL_VAR][FN_REFLEN];
ulonglong last_values[MAX_MYSQL_VAR];
@@ -348,8 +348,7 @@ int main(int argc,char *argv[])
if (shared_memory_base_name)
mysql_options(&mysql,MYSQL_SHARED_MEMORY_BASE_NAME,shared_memory_base_name);
#endif
- if (default_charset)
- mysql_options(&mysql, MYSQL_SET_CHARSET_NAME, default_charset);
+ mysql_options(&mysql, MYSQL_SET_CHARSET_NAME, default_charset);
error_flags= (myf)(opt_nobeep ? 0 : ME_BELL);
if (sql_connect(&mysql, option_wait))
diff --git a/client/mysqlbinlog.cc b/client/mysqlbinlog.cc
index f55dc75df5d..f87f5b92f10 100644
--- a/client/mysqlbinlog.cc
+++ b/client/mysqlbinlog.cc
@@ -1358,7 +1358,6 @@ static int parse_args(int *argc, char*** argv)
int ho_error;
result_file = stdout;
- load_defaults("my",load_default_groups,argc,argv);
if ((ho_error=handle_options(argc, argv, my_long_options, get_one_option)))
exit(ho_error);
if (debug_info_flag)
@@ -1926,7 +1925,7 @@ static Exit_status dump_local_log_entries(PRINT_EVENT_INFO *print_event_info,
return ERROR_STOP;
}
#endif
- if (init_io_cache(file, fileno(stdin), 0, READ_CACHE, (my_off_t) 0,
+ if (init_io_cache(file, my_fileno(stdin), 0, READ_CACHE, (my_off_t) 0,
0, MYF(MY_WME | MY_NABP | MY_DONT_CHECK_FILESIZE)))
{
error("Failed to init IO cache.");
@@ -2015,8 +2014,9 @@ int main(int argc, char** argv)
my_init_time(); // for time functions
+ load_defaults("my", load_default_groups, &argc, &argv);
+ defaults_argv= argv;
parse_args(&argc, (char***)&argv);
- defaults_argv=argv;
if (!argc)
{
diff --git a/client/mysqlcheck.c b/client/mysqlcheck.c
index 1533e602639..1affea1d189 100644
--- a/client/mysqlcheck.c
+++ b/client/mysqlcheck.c
@@ -369,12 +369,15 @@ static int get_options(int *argc, char ***argv)
If there's no --default-character-set option given with
--fix-table-name or --fix-db-name set the default character set to "utf8".
*/
- if (!default_charset && (opt_fix_db_names || opt_fix_table_names))
+ if (!default_charset)
{
- default_charset= (char*) "utf8";
+ if (opt_fix_db_names || opt_fix_table_names)
+ default_charset= (char*) "utf8";
+ else
+ default_charset= (char*) MYSQL_AUTODETECT_CHARSET_NAME;
}
- if (default_charset && !get_charset_by_csname(default_charset, MY_CS_PRIMARY,
- MYF(MY_WME)))
+ if (strcmp(default_charset, MYSQL_AUTODETECT_CHARSET_NAME) &&
+ !get_charset_by_csname(default_charset, MY_CS_PRIMARY, MYF(MY_WME)))
{
printf("Unsupported character set: %s\n", default_charset);
return 1;
@@ -798,8 +801,7 @@ static int dbConnect(char *host, char *user, char *passwd)
if (shared_memory_base_name)
mysql_options(&mysql_connection,MYSQL_SHARED_MEMORY_BASE_NAME,shared_memory_base_name);
#endif
- if (default_charset)
- mysql_options(&mysql_connection, MYSQL_SET_CHARSET_NAME, default_charset);
+ mysql_options(&mysql_connection, MYSQL_SET_CHARSET_NAME, default_charset);
if (!(sock = mysql_real_connect(&mysql_connection, host, user, passwd,
NULL, opt_mysql_port, opt_mysql_unix_port, 0)))
{
diff --git a/client/mysqldump.c b/client/mysqldump.c
index e9e3124b9cb..aa81a0e98bf 100644
--- a/client/mysqldump.c
+++ b/client/mysqldump.c
@@ -861,9 +861,9 @@ static int get_options(int *argc, char ***argv)
load_defaults("my",load_default_groups,argc,argv);
defaults_argv= *argv;
- if (hash_init(&ignore_table, charset_info, 16, 0, 0,
- (hash_get_key) get_table_key,
- (hash_free_key) free_table_ent, 0))
+ if (my_hash_init(&ignore_table, charset_info, 16, 0, 0,
+ (my_hash_get_key) get_table_key,
+ (my_hash_free_key) free_table_ent, 0))
return(EX_EOM);
/* Don't copy internal log tables */
if (my_hash_insert(&ignore_table,
@@ -1273,120 +1273,68 @@ static int switch_character_set_results(MYSQL *mysql, const char *cs_name)
}
/**
- Rewrite CREATE TRIGGER statement, enclosing DEFINER clause in
- version-specific comment.
+ Rewrite statement, enclosing DEFINER clause in version-specific comment.
- This function parses the CREATE TRIGGER statement and encloses
- DEFINER-clause in version-specific comment:
- input query: CREATE DEFINER=a@b TRIGGER ...
- rewritten query: CREATE * / / *!50017 DEFINER=a@b * / / *!50003 TRIGGER ...
-
- @note This function will go away when WL#3995 is implemented.
-
- @param[in] trigger_def_str CREATE TRIGGER statement string.
- @param[in] trigger_def_length length of the trigger_def_str.
-
- @return pointer to the new allocated query string.
-*/
-
-static char *cover_definer_clause_in_trigger(const char *trigger_def_str,
- uint trigger_def_length)
-{
- char *query_str= NULL;
- char *definer_begin= my_case_str(trigger_def_str, trigger_def_length,
- C_STRING_WITH_LEN(" DEFINER"));
- char *definer_end;
-
- if (!definer_begin)
- return NULL;
-
- definer_end= my_case_str(definer_begin, strlen(definer_begin),
- C_STRING_WITH_LEN(" TRIGGER"));
-
- if (definer_end)
- {
- char *query_str_tail;
-
- /*
- Allocate memory for new query string: original string
- from SHOW statement and version-specific comments.
- */
- query_str= alloc_query_str(trigger_def_length + 23);
-
- query_str_tail= strnmov(query_str,
- trigger_def_str,
- definer_begin - trigger_def_str);
-
- query_str_tail= strmov(query_str_tail,
- "*/ /*!50017");
-
- query_str_tail= strnmov(query_str_tail,
- definer_begin,
- definer_end - definer_begin);
-
- query_str_tail= strxmov(query_str_tail,
- "*/ /*!50003",
- definer_end,
- NullS);
- }
-
- return query_str;
-}
-
-/**
- Rewrite CREATE FUNCTION or CREATE PROCEDURE statement, enclosing DEFINER
- clause in version-specific comment.
-
- This function parses the CREATE FUNCTION | PROCEDURE statement and
- encloses DEFINER-clause in version-specific comment:
+ This function parses any CREATE statement and encloses DEFINER-clause in
+ version-specific comment:
input query: CREATE DEFINER=a@b FUNCTION ...
rewritten query: CREATE * / / *!50020 DEFINER=a@b * / / *!50003 FUNCTION ...
@note This function will go away when WL#3995 is implemented.
- @param[in] def_str CREATE FUNCTION|PROCEDURE statement string.
- @param[in] def_str_length length of the def_str.
+ @param[in] stmt_str CREATE statement string.
+ @param[in] stmt_length Length of the stmt_str.
+ @param[in] definer_version_str Minimal MySQL version number when
+ DEFINER clause is supported in the
+ given statement.
+ @param[in] definer_version_length Length of definer_version_str.
+ @param[in] stmt_version_str Minimal MySQL version number when the
+ given statement is supported.
+ @param[in] stmt_version_length Length of stmt_version_str.
+ @param[in] keyword_str Keyword to look for after CREATE.
+ @param[in] keyword_length Length of keyword_str.
@return pointer to the new allocated query string.
*/
-static char *cover_definer_clause_in_sp(const char *def_str,
- uint def_str_length)
+static char *cover_definer_clause(const char *stmt_str,
+ uint stmt_length,
+ const char *definer_version_str,
+ uint definer_version_length,
+ const char *stmt_version_str,
+ uint stmt_version_length,
+ const char *keyword_str,
+ uint keyword_length)
{
- char *query_str= NULL;
- char *definer_begin= my_case_str(def_str, def_str_length,
+ char *definer_begin= my_case_str(stmt_str, stmt_length,
C_STRING_WITH_LEN(" DEFINER"));
- char *definer_end;
+ char *definer_end= NULL;
+
+ char *query_str= NULL;
+ char *query_ptr;
if (!definer_begin)
return NULL;
definer_end= my_case_str(definer_begin, strlen(definer_begin),
- C_STRING_WITH_LEN(" PROCEDURE"));
+ keyword_str, keyword_length);
if (!definer_end)
- {
- definer_end= my_case_str(definer_begin, strlen(definer_begin),
- C_STRING_WITH_LEN(" FUNCTION"));
- }
+ return NULL;
- if (definer_end)
- {
- char *query_str_tail;
+ /*
+ Allocate memory for new query string: original string
+ from SHOW statement and version-specific comments.
+ */
+ query_str= alloc_query_str(stmt_length + 23);
- /*
- Allocate memory for new query string: original string
- from SHOW statement and version-specific comments.
- */
- query_str= alloc_query_str(def_str_length + 23);
-
- query_str_tail= strnmov(query_str, def_str, definer_begin - def_str);
- query_str_tail= strmov(query_str_tail, "*/ /*!50020");
- query_str_tail= strnmov(query_str_tail, definer_begin,
- definer_end - definer_begin);
- query_str_tail= strxmov(query_str_tail, "*/ /*!50003",
- definer_end, NullS);
- }
+ query_ptr= strnmov(query_str, stmt_str, definer_begin - stmt_str);
+ query_ptr= strnmov(query_ptr, C_STRING_WITH_LEN("*/ /*!"));
+ query_ptr= strnmov(query_ptr, definer_version_str, definer_version_length);
+ query_ptr= strnmov(query_ptr, definer_begin, definer_end - definer_begin);
+ query_ptr= strnmov(query_ptr, C_STRING_WITH_LEN("*/ /*!"));
+ query_ptr= strnmov(query_ptr, stmt_version_str, stmt_version_length);
+ query_ptr= strxmov(query_ptr, definer_end, NullS);
return query_str;
}
@@ -1419,8 +1367,8 @@ static void free_resources()
if (md_result_file && md_result_file != stdout)
my_fclose(md_result_file, MYF(0));
my_free(opt_password, MYF(MY_ALLOW_ZERO_PTR));
- if (hash_inited(&ignore_table))
- hash_free(&ignore_table);
+ if (my_hash_inited(&ignore_table))
+ my_hash_free(&ignore_table);
if (extended_insert)
dynstr_free(&extended_row);
if (insert_pat_inited)
@@ -1922,6 +1870,8 @@ static uint dump_events_for_db(char *db)
*/
if (strlen(row[3]) != 0)
{
+ char *query_str;
+
if (opt_drop)
fprintf(sql_file, "/*!50106 DROP EVENT IF EXISTS %s */%s\n",
event_name, delimiter);
@@ -1948,31 +1898,36 @@ static uint dump_events_for_db(char *db)
row[4], /* character_set_results */
row[5]); /* collation_connection */
}
- else
- {
- /*
- mysqldump is being run against the server, that does not
- provide character set information in SHOW CREATE
- statements.
+ else
+ {
+ /*
+ mysqldump is being run against the server, that does not
+ provide character set information in SHOW CREATE
+ statements.
- NOTE: the dump may be incorrect, since character set
- information is required in order to restore event properly.
- */
+ NOTE: the dump may be incorrect, since character set
+ information is required in order to restore event properly.
+ */
- fprintf(sql_file,
- "--\n"
- "-- WARNING: old server version. "
- "The following dump may be incomplete.\n"
- "--\n");
- }
+ fprintf(sql_file,
+ "--\n"
+ "-- WARNING: old server version. "
+ "The following dump may be incomplete.\n"
+ "--\n");
+ }
switch_sql_mode(sql_file, delimiter, row[1]);
switch_time_zone(sql_file, delimiter, row[2]);
+ query_str= cover_definer_clause(row[3], strlen(row[3]),
+ C_STRING_WITH_LEN("50117"),
+ C_STRING_WITH_LEN("50106"),
+ C_STRING_WITH_LEN(" EVENT"));
+
fprintf(sql_file,
"/*!50106 %s */ %s\n",
- (const char *) row[3],
+ (const char *) (query_str != NULL ? query_str : row[3]),
(const char *) delimiter);
restore_time_zone(sql_file, delimiter);
@@ -2127,7 +2082,16 @@ static uint dump_routines_for_db(char *db)
fprintf(sql_file, "/*!50003 DROP %s IF EXISTS %s */;\n",
routine_type[i], routine_name);
- query_str= cover_definer_clause_in_sp(row[2], strlen(row[2]));
+ query_str= cover_definer_clause(row[2], strlen(row[2]),
+ C_STRING_WITH_LEN("50020"),
+ C_STRING_WITH_LEN("50003"),
+ C_STRING_WITH_LEN(" FUNCTION"));
+
+ if (!query_str)
+ query_str= cover_definer_clause(row[2], strlen(row[2]),
+ C_STRING_WITH_LEN("50020"),
+ C_STRING_WITH_LEN("50003"),
+ C_STRING_WITH_LEN(" PROCEDURE"));
if (mysql_num_fields(routine_res) >= 6)
{
@@ -2806,8 +2770,10 @@ static int dump_trigger(FILE *sql_file, MYSQL_RES *show_create_trigger_rs,
while ((row= mysql_fetch_row(show_create_trigger_rs)))
{
- char *query_str= cover_definer_clause_in_trigger(row[2], strlen(row[2]));
-
+ char *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))
@@ -3316,7 +3282,7 @@ static void dump_table(char *table, char *db)
{
if (length)
{
- if (!IS_NUM_FIELD(field))
+ if (!(field->flags & NUM_FLAG))
{
/*
"length * 2 + 2" is OK for both HEX and non-HEX modes:
@@ -3384,7 +3350,7 @@ static void dump_table(char *table, char *db)
}
if (row[i])
{
- if (!IS_NUM_FIELD(field))
+ if (!(field->flags & NUM_FLAG))
{
if (opt_xml)
{
@@ -3992,7 +3958,7 @@ static int init_dumping(char *database, int init_func(char*))
my_bool include_table(const uchar *hash_key, size_t len)
{
- return !hash_search(&ignore_table, hash_key, len);
+ return ! my_hash_search(&ignore_table, hash_key, len);
}
diff --git a/client/mysqlimport.c b/client/mysqlimport.c
index ef38d760e5d..5b8ec95c06d 100644
--- a/client/mysqlimport.c
+++ b/client/mysqlimport.c
@@ -55,11 +55,10 @@ static char *opt_password=0, *current_user=0,
*current_host=0, *current_db=0, *fields_terminated=0,
*lines_terminated=0, *enclosed=0, *opt_enclosed=0,
*escaped=0, *opt_columns=0,
- *default_charset= (char*) MYSQL_DEFAULT_CHARSET_NAME;
+ *default_charset= (char*) MYSQL_AUTODETECT_CHARSET_NAME;
static uint opt_mysql_port= 0, opt_protocol= 0;
static char * opt_mysql_unix_port=0;
static longlong opt_ignore_lines= -1;
-static CHARSET_INFO *charset_info= &my_charset_latin1;
#include <sslopt-vars.h>
#ifdef HAVE_SMEM
@@ -282,10 +281,6 @@ static int get_options(int *argc, char ***argv)
fprintf(stderr, "You can't use --ignore (-i) and --replace (-r) at the same time.\n");
return(1);
}
- if (strcmp(default_charset, charset_info->csname) &&
- !(charset_info= get_charset_by_csname(default_charset,
- MY_CS_PRIMARY, MYF(MY_WME))))
- exit(1);
if (*argc < 2)
{
usage();
@@ -440,6 +435,7 @@ static MYSQL *db_connect(char *host, char *database,
if (shared_memory_base_name)
mysql_options(mysql,MYSQL_SHARED_MEMORY_BASE_NAME,shared_memory_base_name);
#endif
+ mysql_options(mysql, MYSQL_SET_CHARSET_NAME, default_charset);
if (!(mysql_real_connect(mysql,host,user,passwd,
database,opt_mysql_port,opt_mysql_unix_port,
0)))
diff --git a/client/mysqlshow.c b/client/mysqlshow.c
index 15f791ca8fb..206b86d07cf 100644
--- a/client/mysqlshow.c
+++ b/client/mysqlshow.c
@@ -32,7 +32,7 @@ static my_bool tty_password= 0, opt_table_type= 0;
static my_bool debug_info_flag= 0, debug_check_flag= 0;
static uint my_end_arg= 0;
static uint opt_verbose=0;
-static char *default_charset= (char*) MYSQL_DEFAULT_CHARSET_NAME;
+static char *default_charset= (char*) MYSQL_AUTODETECT_CHARSET_NAME;
#ifdef HAVE_SMEM
static char *shared_memory_base_name=0;
diff --git a/client/mysqlslap.c b/client/mysqlslap.c
index 5983b911866..f13b5099766 100644
--- a/client/mysqlslap.c
+++ b/client/mysqlslap.c
@@ -1204,7 +1204,7 @@ get_options(int *argc,char ***argv)
if (opt_csv_str[0] == '-')
{
- csv_file= fileno(stdout);
+ csv_file= my_fileno(stdout);
}
else
{
diff --git a/client/mysqltest.cc b/client/mysqltest.cc
index e0cdec42a60..04a3526139e 100644
--- a/client/mysqltest.cc
+++ b/client/mysqltest.cc
@@ -115,6 +115,8 @@ static uint my_end_arg= 0;
/* Number of lines of the result to include in failure report */
static uint opt_tail_lines= 0;
+static uint opt_connect_timeout= 0;
+
static char delimiter[MAX_DELIMITER_LENGTH]= ";";
static uint delimiter_length= 1;
@@ -260,8 +262,7 @@ enum enum_commands {
Q_SEND, Q_REAP,
Q_DIRTY_CLOSE, Q_REPLACE, Q_REPLACE_COLUMN,
Q_PING, Q_EVAL,
- Q_RPL_PROBE, Q_ENABLE_RPL_PARSE,
- Q_DISABLE_RPL_PARSE, Q_EVAL_RESULT,
+ Q_EVAL_RESULT,
Q_ENABLE_QUERY_LOG, Q_DISABLE_QUERY_LOG,
Q_ENABLE_RESULT_LOG, Q_DISABLE_RESULT_LOG,
Q_WAIT_FOR_SLAVE_TO_STOP,
@@ -283,7 +284,7 @@ enum enum_commands {
Q_SEND_QUIT, Q_CHANGE_USER, Q_MKDIR, Q_RMDIR,
Q_LIST_FILES, Q_LIST_FILES_WRITE_FILE, Q_LIST_FILES_APPEND_FILE,
Q_SEND_SHUTDOWN, Q_SHUTDOWN_SERVER,
- Q_MOVE_FILE,
+ Q_MOVE_FILE, Q_SEND_EVAL,
Q_UNKNOWN, /* Unknown command. */
Q_COMMENT, /* Comments, ignored. */
@@ -320,9 +321,6 @@ const char *command_names[]=
"replace_column",
"ping",
"eval",
- "rpl_probe",
- "enable_rpl_parse",
- "disable_rpl_parse",
"eval_result",
/* Enable/disable that the _query_ is logged to result file */
"enable_query_log",
@@ -381,6 +379,7 @@ const char *command_names[]=
"send_shutdown",
"shutdown_server",
"move_file",
+ "send_eval",
0
};
@@ -662,14 +661,6 @@ public:
LogFile log_file;
LogFile progress_file;
-
-/* Disable functions that only exist in MySQL 4.0 */
-#if MYSQL_VERSION_ID < 40000
-void mysql_enable_rpl_parse(MYSQL* mysql __attribute__((unused))) {}
-void mysql_disable_rpl_parse(MYSQL* mysql __attribute__((unused))) {}
-int mysql_rpl_parse_enabled(MYSQL* mysql __attribute__((unused))) { return 1; }
-my_bool mysql_rpl_probe(MYSQL *mysql __attribute__((unused))) { return 1; }
-#endif
void replace_dynstr_append_mem(DYNAMIC_STRING *ds, const char *val,
int len);
void replace_dynstr_append(DYNAMIC_STRING *ds, const char *val);
@@ -1138,7 +1129,7 @@ void free_used_memory()
close_connections();
close_files();
- hash_free(&var_hash);
+ my_hash_free(&var_hash);
for (i= 0 ; i < q_lines.elements ; i++)
{
@@ -1171,7 +1162,6 @@ void free_used_memory()
mysql_server_end();
/* Don't use DBUG after mysql_server_end() */
- DBUG_VIOLATION_HELPER_LEAVE;
return;
}
@@ -2001,8 +1991,8 @@ VAR* var_get(const char *var_name, const char **var_name_end, my_bool raw,
if (length >= MAX_VAR_NAME_LENGTH)
die("Too long variable name: %s", save_var_name);
- if (!(v = (VAR*) hash_search(&var_hash, (const uchar*) save_var_name,
- length)))
+ if (!(v = (VAR*) my_hash_search(&var_hash, (const uchar*) save_var_name,
+ length)))
{
char buff[MAX_VAR_NAME_LENGTH+1];
strmake(buff, save_var_name, length);
@@ -2033,7 +2023,7 @@ err:
VAR *var_obtain(const char *name, int len)
{
VAR* v;
- if ((v = (VAR*)hash_search(&var_hash, (const uchar *) name, len)))
+ if ((v = (VAR*)my_hash_search(&var_hash, (const uchar *) name, len)))
return v;
v = var_init(0, name, len, "", 0);
my_hash_insert(&var_hash, (uchar*)v);
@@ -2967,6 +2957,7 @@ void do_move_file(struct st_command *command)
void do_chmod_file(struct st_command *command)
{
long mode= 0;
+ int err_code;
static DYNAMIC_STRING ds_mode;
static DYNAMIC_STRING ds_file;
const struct command_arg chmod_file_args[] = {
@@ -2986,7 +2977,10 @@ void do_chmod_file(struct st_command *command)
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));
+ err_code= chmod(ds_file.str, mode);
+ if (err_code < 0)
+ err_code= 1;
+ handle_command_error(command, err_code);
dynstr_free(&ds_mode);
dynstr_free(&ds_file);
DBUG_VOID_RETURN;
@@ -3847,12 +3841,8 @@ int do_save_master_pos()
MYSQL_ROW row;
MYSQL *mysql = &cur_con->mysql;
const char *query;
- int rpl_parse;
DBUG_ENTER("do_save_master_pos");
- rpl_parse = mysql_rpl_parse_enabled(mysql);
- mysql_disable_rpl_parse(mysql);
-
#ifdef HAVE_NDB_BINLOG
/*
Wait for ndb binlog to be up-to-date with all changes
@@ -4002,10 +3992,6 @@ int do_save_master_pos()
strnmov(master_pos.file, row[0], sizeof(master_pos.file)-1);
master_pos.pos = strtoul(row[1], (char**) 0, 10);
mysql_free_result(res);
-
- if (rpl_parse)
- mysql_enable_rpl_parse(mysql);
-
DBUG_RETURN(0);
}
@@ -4068,29 +4054,6 @@ void do_let(struct st_command *command)
}
-int do_rpl_probe(struct st_command *command __attribute__((unused)))
-{
- DBUG_ENTER("do_rpl_probe");
- if (mysql_rpl_probe(&cur_con->mysql))
- die("Failed in mysql_rpl_probe(): '%s'", mysql_error(&cur_con->mysql));
- DBUG_RETURN(0);
-}
-
-
-int do_enable_rpl_parse(struct st_command *command __attribute__((unused)))
-{
- mysql_enable_rpl_parse(&cur_con->mysql);
- return 0;
-}
-
-
-int do_disable_rpl_parse(struct st_command *command __attribute__((unused)))
-{
- mysql_disable_rpl_parse(&cur_con->mysql);
- return 0;
-}
-
-
/*
Sleep the number of specified seconds
@@ -5021,6 +4984,11 @@ void do_connect(struct st_command *command)
#endif
if (!mysql_init(&con_slot->mysql))
die("Failed on mysql_init()");
+
+ if (opt_connect_timeout)
+ mysql_options(&con_slot->mysql, MYSQL_OPT_CONNECT_TIMEOUT,
+ (void *) &opt_connect_timeout);
+
if (opt_compress || con_compress)
mysql_options(&con_slot->mysql, MYSQL_OPT_COMPRESS, NullS);
mysql_options(&con_slot->mysql, MYSQL_OPT_LOCAL_INFILE, 0);
@@ -5810,6 +5778,11 @@ static struct my_option my_long_options[] =
{"view-protocol", OPT_VIEW_PROTOCOL, "Use views for select",
(uchar**) &view_protocol, (uchar**) &view_protocol, 0,
GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
+ {"connect_timeout", OPT_CONNECT_TIMEOUT,
+ "Number of seconds before connection timeout.",
+ (uchar**) &opt_connect_timeout,
+ (uchar**) &opt_connect_timeout, 0, GET_UINT, REQUIRED_ARG,
+ 120, 0, 3600 * 12, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
};
@@ -6548,8 +6521,6 @@ void run_query_normal(struct st_connection *cn, struct st_command *command,
if (!disable_result_log)
{
- ulonglong UNINIT_VAR(affected_rows); /* Ok to be undef if 'disable_info' is set */
-
if (res)
{
MYSQL_FIELD *fields= mysql_fetch_fields(res);
@@ -6566,10 +6537,10 @@ void run_query_normal(struct st_connection *cn, struct st_command *command,
/*
Need to call mysql_affected_rows() before the "new"
- query to find the warnings
+ query to find the warnings.
*/
if (!disable_info)
- affected_rows= mysql_affected_rows(mysql);
+ append_info(ds, mysql_affected_rows(mysql), mysql_info(mysql));
/*
Add all warnings to the result. We can't do this if we are in
@@ -6584,9 +6555,6 @@ void run_query_normal(struct st_connection *cn, struct st_command *command,
dynstr_append_mem(ds, ds_warnings->str, ds_warnings->length);
}
}
-
- if (!disable_info)
- append_info(ds, affected_rows, mysql_info(mysql));
}
if (res)
@@ -6960,40 +6928,34 @@ void run_query_stmt(MYSQL *mysql, struct st_command *command,
}
/*
- Need to grab affected rows information before getting
- warnings here
+ Fetch info before fetching warnings, since it will be reset
+ otherwise.
*/
- {
- ulonglong UNINIT_VAR(affected_rows);
- if (!disable_info)
- affected_rows= mysql_affected_rows(mysql);
+ if (!disable_info)
+ append_info(ds, mysql_stmt_affected_rows(stmt), mysql_info(mysql));
- if (!disable_warnings)
- {
- /* Get the warnings from execute */
+ if (!disable_warnings)
+ {
+ /* Get the warnings from execute */
- /* Append warnings to ds - if there are any */
- if (append_warnings(&ds_execute_warnings, mysql) ||
- ds_execute_warnings.length ||
- ds_prepare_warnings.length ||
- ds_warnings->length)
- {
- dynstr_append_mem(ds, "Warnings:\n", 10);
- if (ds_warnings->length)
- dynstr_append_mem(ds, ds_warnings->str,
- ds_warnings->length);
- if (ds_prepare_warnings.length)
- dynstr_append_mem(ds, ds_prepare_warnings.str,
- ds_prepare_warnings.length);
- if (ds_execute_warnings.length)
- dynstr_append_mem(ds, ds_execute_warnings.str,
- ds_execute_warnings.length);
- }
+ /* Append warnings to ds - if there are any */
+ if (append_warnings(&ds_execute_warnings, mysql) ||
+ ds_execute_warnings.length ||
+ ds_prepare_warnings.length ||
+ ds_warnings->length)
+ {
+ dynstr_append_mem(ds, "Warnings:\n", 10);
+ if (ds_warnings->length)
+ dynstr_append_mem(ds, ds_warnings->str,
+ ds_warnings->length);
+ if (ds_prepare_warnings.length)
+ dynstr_append_mem(ds, ds_prepare_warnings.str,
+ ds_prepare_warnings.length);
+ if (ds_execute_warnings.length)
+ dynstr_append_mem(ds, ds_execute_warnings.str,
+ ds_execute_warnings.length);
}
-
- if (!disable_info)
- append_info(ds, affected_rows, mysql_info(mysql));
}
}
@@ -7043,6 +7005,10 @@ int util_query(MYSQL* org_mysql, const char* query){
if (!(mysql= mysql_init(mysql)))
die("Failed in mysql_init()");
+ if (opt_connect_timeout)
+ mysql_options(mysql, MYSQL_OPT_CONNECT_TIMEOUT,
+ (void *) &opt_connect_timeout);
+
/* enable local infile, in non-binary builds often disabled by default */
mysql_options(mysql, MYSQL_OPT_LOCAL_INFILE, 0);
safe_connect(mysql, "util", org_mysql->host, org_mysql->user,
@@ -7091,7 +7057,7 @@ void run_query(struct st_connection *cn, struct st_command *command, int flags)
/*
Evaluate query if this is an eval command
*/
- if (command->type == Q_EVAL)
+ if (command->type == Q_EVAL || command->type == Q_SEND_EVAL)
{
init_dynamic_string(&eval_query, "", command->query_len+256, 1024);
do_eval(&eval_query, command->query, command->end, FALSE);
@@ -7638,8 +7604,8 @@ int main(int argc, char **argv)
my_init_dynamic_array(&q_lines, sizeof(struct st_command*), 1024, 1024);
- if (hash_init(&var_hash, charset_info,
- 1024, 0, 0, get_var_key, var_free, MYF(0)))
+ if (my_hash_init(&var_hash, charset_info,
+ 1024, 0, 0, get_var_key, var_free, MYF(0)))
die("Variable hash initialization failed");
var_set_string("$MYSQL_SERVER_VERSION", MYSQL_SERVER_VERSION);
@@ -7702,6 +7668,9 @@ int main(int argc, char **argv)
st_connection *con= connections;
if (!( mysql_init(&con->mysql)))
die("Failed in mysql_init()");
+ if (opt_connect_timeout)
+ mysql_options(&con->mysql, MYSQL_OPT_CONNECT_TIMEOUT,
+ (void *) &opt_connect_timeout);
if (opt_compress)
mysql_options(&con->mysql,MYSQL_OPT_COMPRESS,NullS);
mysql_options(&con->mysql, MYSQL_OPT_LOCAL_INFILE, 0);
@@ -7806,9 +7775,6 @@ int main(int argc, char **argv)
case Q_DISCONNECT:
case Q_DIRTY_CLOSE:
do_close_connection(command); break;
- case Q_RPL_PROBE: do_rpl_probe(command); break;
- case Q_ENABLE_RPL_PARSE: do_enable_rpl_parse(command); break;
- case Q_DISABLE_RPL_PARSE: do_disable_rpl_parse(command); break;
case Q_ENABLE_QUERY_LOG: disable_query_log=0; break;
case Q_DISABLE_QUERY_LOG: disable_query_log=1; break;
case Q_ENABLE_ABORT_ON_ERROR: abort_on_error=1; break;
@@ -7915,6 +7881,7 @@ int main(int argc, char **argv)
break;
}
case Q_SEND:
+ case Q_SEND_EVAL:
if (!*command->first_argument)
{
/*
diff --git a/client/readline.cc b/client/readline.cc
index b32cb71b0de..73ce7c3b8c7 100644
--- a/client/readline.cc
+++ b/client/readline.cc
@@ -33,7 +33,7 @@ LINE_BUFFER *batch_readline_init(ulong max_size,FILE *file)
if (!(line_buff=(LINE_BUFFER*)
my_malloc(sizeof(*line_buff),MYF(MY_WME | MY_ZEROFILL))))
return 0;
- if (init_line_buffer(line_buff,fileno(file),IO_SIZE,max_size))
+ if (init_line_buffer(line_buff,my_fileno(file),IO_SIZE,max_size))
{
my_free(line_buff,MYF(0));
return 0;
diff --git a/client/sql_string.h b/client/sql_string.h
index da19c1ccfe5..0e6d6da4476 100644
--- a/client/sql_string.h
+++ b/client/sql_string.h
@@ -1,3 +1,6 @@
+#ifndef CLIENT_SQL_STRING_INCLUDED
+#define CLIENT_SQL_STRING_INCLUDED
+
/* Copyright (C) 2000 MySQL AB
This program is free software; you can redistribute it and/or modify
@@ -353,3 +356,5 @@ public:
return (s->alloced && Ptr >= s->Ptr && Ptr < s->Ptr + s->str_length);
}
};
+
+#endif /* CLIENT_SQL_STRING_INCLUDED */