summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
Diffstat (limited to 'client')
-rw-r--r--client/mysqlimport.c3
-rw-r--r--client/mysqltest.c135
2 files changed, 94 insertions, 44 deletions
diff --git a/client/mysqlimport.c b/client/mysqlimport.c
index 019e3080023..ca4acd82db6 100644
--- a/client/mysqlimport.c
+++ b/client/mysqlimport.c
@@ -37,8 +37,9 @@ static char *add_load_option(char *ptr,const char *object,
const char *statement);
static my_bool verbose=0,lock_tables=0,ignore_errors=0,opt_delete=0,
- replace=0,silent=0,ignore=0,opt_compress=0,opt_local_file=0,
+ replace=0,silent=0,ignore=0,opt_compress=0,
opt_low_priority= 0, tty_password= 0;
+static uint opt_local_file=0;
static MYSQL mysql_connection;
static char *opt_password=0, *current_user=0,
*current_host=0, *current_db=0, *fields_terminated=0,
diff --git a/client/mysqltest.c b/client/mysqltest.c
index 33702e9d1d2..f5facccee3a 100644
--- a/client/mysqltest.c
+++ b/client/mysqltest.c
@@ -97,6 +97,10 @@
#define DEFAULT_DELIMITER ";"
#define MAX_DELIMITER 16
+#define RESULT_OK 0
+#define RESULT_CONTENT_MISMATCH 1
+#define RESULT_LENGTH_MISMATCH 2
+
enum {OPT_MANAGER_USER=256,OPT_MANAGER_HOST,OPT_MANAGER_PASSWD,
OPT_MANAGER_PORT,OPT_MANAGER_WAIT_TIMEOUT, OPT_SKIP_SAFEMALLOC,
OPT_SSL_SSL, OPT_SSL_KEY, OPT_SSL_CERT, OPT_SSL_CA, OPT_SSL_CAPATH,
@@ -456,6 +460,7 @@ my_bool mysql_rpl_probe(MYSQL *mysql __attribute__((unused))) { return 1; }
#endif
static void replace_dynstr_append_mem(DYNAMIC_STRING *ds, const char *val,
int len);
+static int handle_no_error(struct st_query *q);
static void do_eval(DYNAMIC_STRING* query_eval, const char *query)
{
@@ -649,7 +654,7 @@ int dyn_string_cmp(DYNAMIC_STRING* ds, const char *fname)
{
DBUG_PRINT("info",("Size differs: result size: %u file size: %u",
ds->length, stat_info.st_size));
- DBUG_RETURN(2);
+ DBUG_RETURN(RESULT_LENGTH_MISMATCH);
}
if (!(tmp = (char*) my_malloc(stat_info.st_size + 1, MYF(MY_WME))))
die(NullS);
@@ -666,7 +671,7 @@ int dyn_string_cmp(DYNAMIC_STRING* ds, const char *fname)
res_ptr = res_ds.str;
if ((res_len = res_ds.length) != ds->length)
{
- res = 2;
+ res= RESULT_LENGTH_MISMATCH;
goto err;
}
}
@@ -676,7 +681,8 @@ int dyn_string_cmp(DYNAMIC_STRING* ds, const char *fname)
res_len = stat_info.st_size;
}
- res = (memcmp(res_ptr, ds->str, res_len)) ? 1 : 0;
+ res= (memcmp(res_ptr, ds->str, res_len)) ?
+ RESULT_CONTENT_MISMATCH : RESULT_OK;
err:
if (res && eval_result)
@@ -693,21 +699,21 @@ err:
static int check_result(DYNAMIC_STRING* ds, const char *fname,
my_bool require_option)
{
- int error = 0;
- int res=dyn_string_cmp(ds, fname);
+ int error= RESULT_OK;
+ int res= dyn_string_cmp(ds, fname);
if (res && require_option)
abort_not_supported_test();
switch (res) {
- case 0:
+ case RESULT_OK:
break; /* ok */
- case 2:
+ case RESULT_LENGTH_MISMATCH:
verbose_msg("Result length mismatch");
- error = 1;
+ error= RESULT_LENGTH_MISMATCH;
break;
- case 1:
+ case RESULT_CONTENT_MISMATCH:
verbose_msg("Result content mismatch");
- error = 1;
+ error= RESULT_CONTENT_MISMATCH;
break;
default: /* impossible */
die("Unknown error code from dyn_string_cmp()");
@@ -812,9 +818,9 @@ int var_set(const char *var_name, const char *var_name_end,
int open_file(const char *name)
{
+ char buff[FN_REFLEN];
DBUG_ENTER("open_file");
DBUG_PRINT("enter", ("name: %s", name));
- char buff[FN_REFLEN];
if (!test_if_hard_path(name))
{
strxmov(buff, opt_basedir, name, NullS);
@@ -843,9 +849,9 @@ int open_file(const char *name)
int check_eol_junk(const char *eol)
{
+ const char *p= eol;
DBUG_ENTER("check_eol_junk");
DBUG_PRINT("enter", ("eol: %s", eol));
- const char *p= eol;
/* Remove all spacing chars except new line */
while (*p && my_isspace(charset_info, *p) && (*p != '\n'))
p++;
@@ -2170,7 +2176,10 @@ int read_line(char *buf, int size)
{
found_eof:
if (cur_file->file != stdin)
+ {
my_fclose(cur_file->file, MYF(0));
+ cur_file->file= 0;
+ }
my_free((gptr)cur_file->file_name, MYF(MY_ALLOW_ZERO_PTR));
cur_file->file_name= 0;
lineno--;
@@ -2556,10 +2565,11 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
argument= buff;
}
fn_format(buff, argument, "", "", 4);
- DBUG_ASSERT(cur_file->file == 0);
+ DBUG_ASSERT(cur_file == file_stack && cur_file->file == 0);
if (!(cur_file->file=
my_fopen(buff, O_RDONLY | FILE_BINARY, MYF(MY_WME))))
- die("Could not open %s: errno = %d", argument, errno);
+ die("Could not open %s: errno = %d", buff, errno);
+ cur_file->file_name= my_strdup(buff, MYF(MY_FAE));
break;
}
case 'm':
@@ -2904,22 +2914,9 @@ static int run_query_normal(MYSQL* mysql, struct st_query* q, int flags)
}
- if (q->expected_errno[0].type == ERR_ERRNO &&
- q->expected_errno[0].code.errnum != 0)
- {
- /* Error code we wanted was != 0, i.e. not an expected success */
- verbose_msg("query '%s' succeeded - should have failed with errno %d...",
- q->query, q->expected_errno[0].code.errnum);
- error = 1;
- goto end;
- }
- else if (q->expected_errno[0].type == ERR_SQLSTATE &&
- strcmp(q->expected_errno[0].code.sqlstate,"00000") != 0)
+ if (handle_no_error(q))
{
- /* SQLSTATE we wanted was != "00000", i.e. not an expected success */
- verbose_msg("query '%s' succeeded - should have failed with sqlstate %s...",
- q->query, q->expected_errno[0].code.sqlstate);
- error = 1;
+ error= 1;
goto end;
}
@@ -3099,10 +3096,8 @@ static int run_query_stmt(MYSQL *mysql, struct st_query *q, int flags)
{
if (q->abort_on_error)
{
- die("unable to prepare statement '%s': "
- "%s (mysql_stmt_errno=%d returned=%d)",
- query,
- mysql_stmt_error(stmt), mysql_stmt_errno(stmt), err);
+ die("query '%s' failed: %d: %s", query,
+ mysql_stmt_errno(stmt), mysql_stmt_error(stmt));
}
else
{
@@ -3183,12 +3178,8 @@ static int run_query_stmt(MYSQL *mysql, struct st_query *q, int flags)
}
/* If we got here the statement was both executed and read succeesfully */
-
- if (q->expected_errno[0].type == ERR_ERRNO &&
- q->expected_errno[0].code.errnum != 0)
+ if (handle_no_error(q))
{
- verbose_msg("query '%s' succeeded - should have failed with errno %d...",
- q->query, q->expected_errno[0].code.errnum);
error= 1;
goto end;
}
@@ -3515,8 +3506,14 @@ static int run_query_stmt_handle_error(char *query, struct st_query *q,
dynstr_append_mem(ds,"\n",1);
if (i)
{
- verbose_msg("query '%s' failed with wrong errno %d instead of %d...",
- q->query, mysql_stmt_errno(stmt), q->expected_errno[0]);
+ if (q->expected_errno[0].type == ERR_ERRNO)
+ verbose_msg("query '%s' failed with wrong errno %d instead of %d...",
+ q->query, mysql_stmt_errno(stmt),
+ q->expected_errno[0].code.errnum);
+ else
+ verbose_msg("query '%s' failed with wrong sqlstate %s instead of %s...",
+ q->query, mysql_stmt_sqlstate(stmt),
+ q->expected_errno[0].code.sqlstate);
return 1; /* Error */
}
verbose_msg("query '%s' failed: %d: %s", q->query, mysql_stmt_errno(stmt),
@@ -3531,6 +3528,43 @@ static int run_query_stmt_handle_error(char *query, struct st_query *q,
return 0;
}
+
+/*
+ Handle absence of errors after execution
+
+ SYNOPSIS
+ handle_no_error()
+ q - context of query
+
+ RETURN VALUE
+ 0 - OK
+ 1 - Some error was expected from this query.
+*/
+
+static int handle_no_error(struct st_query *q)
+{
+ DBUG_ENTER("handle_no_error");
+
+ if (q->expected_errno[0].type == ERR_ERRNO &&
+ q->expected_errno[0].code.errnum != 0)
+ {
+ /* Error code we wanted was != 0, i.e. not an expected success */
+ verbose_msg("query '%s' succeeded - should have failed with errno %d...",
+ q->query, q->expected_errno[0].code.errnum);
+ DBUG_RETURN(1);
+ }
+ else if (q->expected_errno[0].type == ERR_SQLSTATE &&
+ strcmp(q->expected_errno[0].code.sqlstate,"00000") != 0)
+ {
+ /* SQLSTATE we wanted was != "00000", i.e. not an expected success */
+ verbose_msg("query '%s' succeeded - should have failed with sqlstate %s...",
+ q->query, q->expected_errno[0].code.sqlstate);
+ DBUG_RETURN(1);
+ }
+
+ DBUG_RETURN(0);
+}
+
/****************************************************************************\
* Functions to match SQL statements that can be prepared
\****************************************************************************/
@@ -3709,8 +3743,9 @@ int main(int argc, char **argv)
{
int error = 0;
struct st_query *q;
- my_bool require_file=0, q_send_flag=0;
+ my_bool require_file=0, q_send_flag=0, query_executed= 0;
char save_file[FN_REFLEN];
+ MY_STAT res_info;
MY_INIT(argv[0]);
{
DBUG_ENTER("main");
@@ -3746,9 +3781,8 @@ int main(int argc, char **argv)
embedded_server_args,
(char**) embedded_server_groups))
die("Can't initialize MySQL server");
- if (cur_file == file_stack)
+ if (cur_file == file_stack && cur_file->file == 0)
{
- DBUG_ASSERT(cur_file->file == 0);
cur_file->file= stdin;
cur_file->file_name= my_strdup("<stdin>", MYF(MY_WME));
}
@@ -3904,6 +3938,7 @@ int main(int argc, char **argv)
save_file[0]=0;
}
error |= run_query(&cur_con->mysql, q, flags);
+ query_executed= 1;
q->last_argument= q->end;
break;
}
@@ -3924,6 +3959,7 @@ int main(int argc, char **argv)
is given on this connection.
*/
error |= run_query(&cur_con->mysql, q, QUERY_SEND);
+ query_executed= 1;
q->last_argument= q->end;
break;
case Q_RESULT:
@@ -3964,6 +4000,7 @@ int main(int argc, char **argv)
break;
case Q_EXEC:
do_exec(q);
+ query_executed= 1;
break;
case Q_START_TIMER:
/* Overwrite possible earlier start of timer */
@@ -4020,6 +4057,18 @@ int main(int argc, char **argv)
parser.current_line += current_line_inc;
}
+ if (!query_executed && result_file && my_stat(result_file, &res_info, 0))
+ {
+ /*
+ my_stat() successful on result file. Check if we have not run a
+ single query, but we do have a result file that contains data.
+ Note that we don't care, if my_stat() fails. For example for
+ non-existing or non-readable file we assume it's fine to have
+ no query output from the test file, e.g. regarded as no error.
+ */
+ if (res_info.st_size)
+ error|= (RESULT_CONTENT_MISMATCH | RESULT_LENGTH_MISMATCH);
+ }
if (result_file && ds_res.length && !error)
{
if (!record)