summaryrefslogtreecommitdiff
path: root/client/mysqltest.cc
diff options
context:
space:
mode:
Diffstat (limited to 'client/mysqltest.cc')
-rw-r--r--client/mysqltest.cc129
1 files changed, 99 insertions, 30 deletions
diff --git a/client/mysqltest.cc b/client/mysqltest.cc
index 6a8d119a7c4..f4fe149f5b5 100644
--- a/client/mysqltest.cc
+++ b/client/mysqltest.cc
@@ -188,6 +188,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"
@@ -608,8 +610,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;
}
@@ -1081,8 +1086,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)
@@ -1352,14 +1358,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)
{
@@ -1383,6 +1389,7 @@ void cat_file(DYNAMIC_STRING* ds, const char* filename)
dynstr_append_mem(ds, start, p-start);
}
my_close(fd, MYF(0));
+ return 0;
}
@@ -2376,6 +2383,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)
@@ -2722,8 +2732,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 &&
@@ -2869,6 +2880,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
@@ -2943,6 +2989,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;
@@ -2962,6 +3012,7 @@ void do_remove_files_wildcard(struct st_command *command)
if (error)
break;
}
+ set_wild_chars(0);
my_dirend(dir_info);
end:
@@ -3203,6 +3254,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;
@@ -3216,6 +3268,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);
}
@@ -3498,6 +3551,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" }
@@ -3512,8 +3566,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;
}
@@ -3776,8 +3830,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));
}
@@ -4920,7 +4975,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)
{
/*
@@ -5161,11 +5216,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)
{
@@ -5337,8 +5394,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;
@@ -5882,6 +5951,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
@@ -6018,7 +6089,7 @@ void read_embedded_server_arguments(const char *name)
static my_bool
-get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
+get_one_option(int optid, const struct my_option *opt,
char *argument)
{
switch(optid) {
@@ -6107,6 +6178,10 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
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);
@@ -7571,9 +7646,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;
}
@@ -7860,6 +7932,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);
+
#ifdef HAVE_OPENSSL
if (opt_use_ssl)
@@ -7918,6 +7993,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;
/*
@@ -8292,16 +8371,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
{