diff options
author | Georgi Kodinov <Georgi.Kodinov@Oracle.com> | 2010-08-16 18:16:07 +0300 |
---|---|---|
committer | Georgi Kodinov <Georgi.Kodinov@Oracle.com> | 2010-08-16 18:16:07 +0300 |
commit | 5564e0837f8d6811acd6f8dc0369ec96dcab3c54 (patch) | |
tree | 94f7517b9264a7af5ea2dd14b146c7e10860363b /client | |
parent | 37da201f2fde90fc952b22a75eb34274ac2c3494 (diff) | |
parent | 32edab6bfe4fada3adbf8688375600c8f911c82c (diff) | |
download | mariadb-git-5564e0837f8d6811acd6f8dc0369ec96dcab3c54.tar.gz |
merged mysql-5.5 into WL1054-5.5
Diffstat (limited to 'client')
-rw-r--r-- | client/CMakeLists.txt | 4 | ||||
-rw-r--r-- | client/mysql_upgrade.c | 3 | ||||
-rw-r--r-- | client/mysqltest.cc | 129 |
3 files changed, 104 insertions, 32 deletions
diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index 5be39396edf..e36659d74bf 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (C) 2006 MySQL AB +# Copyright (c) 2006, 2010, 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 @@ -11,7 +11,7 @@ # # 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 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA INCLUDE_DIRECTORIES( ${CMAKE_SOURCE_DIR}/include diff --git a/client/mysql_upgrade.c b/client/mysql_upgrade.c index eeab3611913..882350f813b 100644 --- a/client/mysql_upgrade.c +++ b/client/mysql_upgrade.c @@ -209,6 +209,9 @@ static void add_one_option(DYNAMIC_STRING* ds, 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__); } diff --git a/client/mysqltest.cc b/client/mysqltest.cc index fabe0e1ea3e..8416432ffe1 100644 --- a/client/mysqltest.cc +++ b/client/mysqltest.cc @@ -202,6 +202,8 @@ static void init_re(void); static int match_re(my_regex_t *, char *); static void free_re(void); +static uint opt_protocol=0; + DYNAMIC_ARRAY q_lines; #include "sslopt-vars.h" @@ -618,8 +620,11 @@ public: if ((bytes= fread(buf, 1, sizeof(buf), m_file)) <= 0) { - fprintf(stderr, "Failed to read from '%s', errno: %d\n", - m_file_name, errno); + // ferror=0 will happen here if no queries executed yet + if (ferror(m_file)) + fprintf(stderr, + "Failed to read from '%s', errno: %d, feof:%d, ferror:%d\n", + m_file_name, errno, feof(m_file), ferror(m_file)); DBUG_VOID_RETURN; } @@ -1083,8 +1088,9 @@ void handle_command_error(struct st_command *command, uint error) command->first_word_len, command->query, error)); DBUG_VOID_RETURN; } - die("command \"%.*s\" failed with wrong error: %d", - command->first_word_len, command->query, error); + if (command->expected_errors.count > 0) + die("command \"%.*s\" failed with wrong error: %d", + command->first_word_len, command->query, error); } else if (command->expected_errors.err[0].type == ERR_ERRNO && command->expected_errors.err[0].code.errnum != 0) @@ -1353,14 +1359,14 @@ void log_msg(const char *fmt, ...) */ -void cat_file(DYNAMIC_STRING* ds, const char* filename) +int cat_file(DYNAMIC_STRING* ds, const char* filename) { int fd; size_t len; char buff[512]; if ((fd= my_open(filename, O_RDONLY, MYF(0))) < 0) - die("Failed to open file '%s'", filename); + return 1; while((len= my_read(fd, (uchar*)&buff, sizeof(buff), MYF(0))) > 0) { @@ -1384,6 +1390,7 @@ void cat_file(DYNAMIC_STRING* ds, const char* filename) dynstr_append_mem(ds, start, p-start); } my_close(fd, MYF(0)); + return 0; } @@ -2436,6 +2443,9 @@ void eval_expr(VAR *v, const char *p, const char **p_end) if ((vp= var_get(p, p_end, 0, 0))) var_copy(v, vp); + /* Apparently it is not safe to assume null-terminated string */ + v->str_val[v->str_val_len]= 0; + /* Make sure there was just a $variable and nothing else */ const char* end= *p_end + 1; if (end < expected_end) @@ -2782,8 +2792,9 @@ void do_exec(struct st_command *command) else { dynstr_free(&ds_cmd); - die("command \"%s\" failed with wrong error: %d", - command->first_argument, status); + if (command->expected_errors.count > 0) + die("command \"%s\" failed with wrong error: %d", + command->first_argument, status); } } else if (command->expected_errors.err[0].type == ERR_ERRNO && @@ -2929,6 +2940,41 @@ void do_system(struct st_command *command) /* SYNOPSIS + set_wild_chars + set true to set * etc. as wild char, false to reset + + DESCRIPTION + Auxiliary function to set "our" wild chars before calling wild_compare + This is needed because the default values are changed to SQL syntax + in mysqltest_embedded. +*/ + +void set_wild_chars (my_bool set) +{ + static char old_many= 0, old_one, old_prefix; + + if (set) + { + if (wild_many == '*') return; // No need + old_many= wild_many; + old_one= wild_one; + old_prefix= wild_prefix; + wild_many= '*'; + wild_one= '?'; + wild_prefix= 0; + } + else + { + if (! old_many) return; // Was not set + wild_many= old_many; + wild_one= old_one; + wild_prefix= old_prefix; + } +} + + +/* + SYNOPSIS do_remove_file command called command @@ -3003,6 +3049,10 @@ void do_remove_files_wildcard(struct st_command *command) dir_separator[0]= FN_LIBCHAR; dir_separator[1]= 0; dynstr_append(&ds_file_to_remove, dir_separator); + + /* Set default wild chars for wild_compare, is changed in embedded mode */ + set_wild_chars(1); + for (i= 0; i < (uint) dir_info->number_off_files; i++) { file= dir_info->dir_entry + i; @@ -3022,6 +3072,7 @@ void do_remove_files_wildcard(struct st_command *command) if (error) break; } + set_wild_chars(0); my_dirend(dir_info); end: @@ -3267,6 +3318,7 @@ static int get_list_files(DYNAMIC_STRING *ds, const DYNAMIC_STRING *ds_dirname, /* Note that my_dir sorts the list if not given any flags */ if (!(dir_info= my_dir(ds_dirname->str, MYF(0)))) DBUG_RETURN(1); + set_wild_chars(1); for (i= 0; i < (uint) dir_info->number_off_files; i++) { file= dir_info->dir_entry + i; @@ -3280,6 +3332,7 @@ static int get_list_files(DYNAMIC_STRING *ds, const DYNAMIC_STRING *ds_dirname, dynstr_append(ds, file->name); dynstr_append(ds, "\n"); } + set_wild_chars(0); my_dirend(dir_info); DBUG_RETURN(0); } @@ -3562,6 +3615,7 @@ void do_append_file(struct st_command *command) void do_cat_file(struct st_command *command) { + int error; static DYNAMIC_STRING ds_filename; const struct command_arg cat_file_args[] = { { "filename", ARG_STRING, TRUE, &ds_filename, "File to read from" } @@ -3576,8 +3630,8 @@ void do_cat_file(struct st_command *command) DBUG_PRINT("info", ("Reading from, file: %s", ds_filename.str)); - cat_file(&ds_res, ds_filename.str); - + error= cat_file(&ds_res, ds_filename.str); + handle_command_error(command, error); dynstr_free(&ds_filename); DBUG_VOID_RETURN; } @@ -3841,8 +3895,9 @@ void do_perl(struct st_command *command) } error= pclose(res_file); - /* Remove the temporary file */ - my_delete(temp_file_path, MYF(0)); + /* Remove the temporary file, but keep it if perl failed */ + if (!error) + my_delete(temp_file_path, MYF(0)); handle_command_error(command, WEXITSTATUS(error)); } @@ -4955,7 +5010,7 @@ int connect_n_handle_errors(struct st_command *command, ds= &ds_res; /* Only log if an error is expected */ - if (!command->abort_on_error && + if (command->expected_errors.count > 0 && !disable_query_log) { /* @@ -5203,11 +5258,13 @@ void do_connect(struct st_command *command) #ifdef __WIN__ if (con_pipe) { - uint protocol= MYSQL_PROTOCOL_PIPE; - mysql_options(&con_slot->mysql, MYSQL_OPT_PROTOCOL, &protocol); + opt_protocol= MYSQL_PROTOCOL_PIPE; } #endif + if (opt_protocol) + mysql_options(&con_slot->mysql, MYSQL_OPT_PROTOCOL, (char*) &opt_protocol); + #ifdef HAVE_SMEM if (con_shm) { @@ -5385,8 +5442,20 @@ void do_block(enum block_cmd cmd, struct st_command* command) /* Define inner block */ cur_block++; cur_block->cmd= cmd; - cur_block->ok= (v.int_val ? TRUE : FALSE); + if (v.int_val) + { + cur_block->ok= TRUE; + } else + /* Any non-empty string which does not begin with 0 is also TRUE */ + { + p= v.str_val; + /* First skip any leading white space or unary -+ */ + while (*p && ((my_isspace(charset_info, *p) || *p == '-' || *p == '+'))) + p++; + cur_block->ok= (*p && *p != '0') ? TRUE : FALSE; + } + if (not_expr) cur_block->ok = !cur_block->ok; @@ -5947,6 +6016,8 @@ static struct my_option my_long_options[] = GET_INT, REQUIRED_ARG, 128, 8, 5120, 0, 0, 0}, {"password", 'p', "Password to use when connecting to server.", 0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0}, + {"protocol", OPT_MYSQL_PROTOCOL, "The protocol of connection (tcp,socket,pipe,memory).", + 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, {"port", 'P', "Port number to use for connection or 0 for default to, in " "order of preference, my.cnf, $MYSQL_TCP_PORT, " #if MYSQL_PORT_DEFAULT == 0 @@ -6086,7 +6157,7 @@ void read_embedded_server_arguments(const char *name) static my_bool -get_one_option(int optid, const struct my_option *, char *argument) +get_one_option(int optid, const struct my_option *opt, char *argument) { switch(optid) { case '#': @@ -6172,6 +6243,10 @@ get_one_option(int optid, const struct my_option *, char *argument) case 'V': print_version(); exit(0); + case OPT_MYSQL_PROTOCOL: + opt_protocol= find_type_or_exit(argument, &sql_protocol_typelib, + opt->name); + break; case '?': usage(); exit(0); @@ -7633,9 +7708,6 @@ void get_command_type(struct st_command* command) sizeof(saved_expected_errors)); DBUG_PRINT("info", ("There are %d expected errors", command->expected_errors.count)); - command->abort_on_error= (command->expected_errors.count == 0 && - abort_on_error); - DBUG_VOID_RETURN; } @@ -7926,6 +7998,9 @@ int main(int argc, char **argv) mysql_options(&con->mysql, MYSQL_SET_CHARSET_DIR, opt_charsets_dir); + if (opt_protocol) + mysql_options(&con->mysql,MYSQL_OPT_PROTOCOL,(char*)&opt_protocol); + #if defined(HAVE_OPENSSL) && !defined(EMBEDDED_LIBRARY) if (opt_use_ssl) @@ -7984,6 +8059,10 @@ int main(int argc, char **argv) command->type= Q_COMMENT; } + /* (Re-)set abort_on_error for this command */ + command->abort_on_error= (command->expected_errors.count == 0 && + abort_on_error); + /* delimiter needs to be executed so we can continue to parse */ my_bool ok_to_do= cur_block->ok || command->type == Q_DELIMITER; /* @@ -8385,16 +8464,6 @@ int main(int argc, char **argv) check_result(); } } - else - { - /* - No result_file_name specified, the result - has been printed to stdout, exit with error - unless script has called "exit" to indicate success - */ - if (abort_flag == 0) - die("Exit with failure! Call 'exit' in script to return with sucess"); - } } else { |