summaryrefslogtreecommitdiff
path: root/client/mysqltest.c
diff options
context:
space:
mode:
Diffstat (limited to 'client/mysqltest.c')
-rw-r--r--client/mysqltest.c181
1 files changed, 115 insertions, 66 deletions
diff --git a/client/mysqltest.c b/client/mysqltest.c
index fe99dda1ac3..f3037fcc173 100644
--- a/client/mysqltest.c
+++ b/client/mysqltest.c
@@ -166,7 +166,8 @@ typedef struct
VAR var_reg[10];
/*Perl/shell-like variable registers */
HASH var_hash;
-int disable_query_log=0, disable_result_log=0;
+my_bool disable_query_log=0, disable_result_log=0, disable_warnings=0;
+my_bool disable_info= 1; /* By default off */
struct connection cons[MAX_CONS];
struct connection* cur_con, *next_con, *cons_end;
@@ -195,6 +196,8 @@ Q_ENABLE_RESULT_LOG, Q_DISABLE_RESULT_LOG,
Q_SERVER_START, Q_SERVER_STOP,Q_REQUIRE_MANAGER,
Q_WAIT_FOR_SLAVE_TO_STOP,
Q_REQUIRE_VERSION,
+Q_ENABLE_WARNINGS, Q_DISABLE_WARNINGS,
+Q_ENABLE_INFO, Q_DISABLE_INFO,
Q_UNKNOWN, /* Unknown command. */
Q_COMMENT, /* Comments, ignored. */
Q_COMMENT_WITH_COMMAND
@@ -253,6 +256,10 @@ const char *command_names[]=
"require_manager",
"wait_for_slave_to_stop",
"require_version",
+ "enable_warnings",
+ "disable_warnings",
+ "enable_info",
+ "diable_info",
0
};
@@ -311,7 +318,7 @@ static int eval_result = 0;
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; }
-int mysql_rpl_probe(MYSQL *mysql __attribute__((unused))) { return 1; }
+my_bool mysql_rpl_probe(MYSQL *mysql __attribute__((unused))) { return 1; }
#endif
#define MAX_SERVER_ARGS 20
@@ -482,9 +489,9 @@ void init_parser()
int hex_val(int c)
{
- if (isdigit(c))
+ if (my_isdigit(system_charset_info,c))
return c - '0';
- else if ((c = tolower(c)) >= 'a' && c <= 'f')
+ else if ((c = my_tolower(system_charset_info,c)) >= 'a' && c <= 'f')
return c - 'a' + 10;
else
return -1;
@@ -594,7 +601,7 @@ VAR* var_get(const char* var_name, const char** var_name_end, my_bool raw,
{
const char* save_var_name = var_name, *end;
end = (var_name_end) ? *var_name_end : 0;
- while (isvar(*var_name) && var_name != end)
+ while (my_isvar(system_charset_info,*var_name) && var_name != end)
++var_name;
if (var_name == save_var_name)
{
@@ -757,7 +764,7 @@ int do_server_op(struct st_query* q,const char* op)
com_p=strmov(com_p,"_exec ");
if (!*p)
die("Missing server name in server_%s\n",op);
- while (*p && !isspace(*p))
+ while (*p && !my_isspace(system_charset_info,*p))
{
*com_p++=*p++;
}
@@ -790,7 +797,7 @@ int do_require_version(struct st_query* q)
if (!*p)
die("Missing version argument in require_version\n");
ver_arg = p;
- while (*p && !isspace(*p))
+ while (*p && !my_isspace(system_charset_info,*p))
p++;
*p = 0;
ver_arg_len = p - ver_arg;
@@ -820,7 +827,7 @@ int do_source(struct st_query* q)
if (!*p)
die("Missing file name in source\n");
name = p;
- while (*p && !isspace(*p))
+ while (*p && !my_isspace(system_charset_info,*p))
p++;
*p = 0;
@@ -1057,11 +1064,11 @@ int do_let(struct st_query* q)
if (!*p)
die("Missing variable name in let\n");
var_name = p;
- while (*p && (*p != '=' || isspace(*p)))
+ while (*p && (*p != '=' || my_isspace(system_charset_info,*p)))
p++;
var_name_end = p;
if (*p == '=') p++;
- while (*p && isspace(*p))
+ while (*p && my_isspace(system_charset_info,*p))
p++;
var_val_start = p;
return var_set(var_name, var_name_end, var_val_start, q->end);
@@ -1090,8 +1097,8 @@ int do_disable_rpl_parse(struct st_query* q __attribute__((unused)))
int do_sleep(struct st_query* q, my_bool real_sleep)
{
- char* p=q->first_argument;
- while (*p && isspace(*p))
+ char *p=q->first_argument;
+ while (*p && my_isspace(system_charset_info,*p))
p++;
if (!*p)
die("Missing argument in sleep\n");
@@ -1107,7 +1114,7 @@ static void get_file_name(char *filename, struct st_query* q)
char* p=q->first_argument;
strnmov(filename, p, FN_REFLEN);
/* Remove end space */
- while (p > filename && isspace(p[-1]))
+ while (p > filename && my_isspace(system_charset_info,p[-1]))
p--;
p[0]=0;
}
@@ -1193,7 +1200,7 @@ static char *get_string(char **to_ptr, char **from_ptr,
if (*from != ' ' && *from)
die("Wrong string argument in %s\n", q->query);
- while (isspace(*from)) /* Point to next string */
+ while (my_isspace(system_charset_info,*from)) /* Point to next string */
from++;
*to =0; /* End of string marker */
@@ -1250,8 +1257,8 @@ static void get_replace(struct st_query *q)
insert_pointer_name(&to_array,to);
}
for (i=1,pos=word_end_chars ; i < 256 ; i++)
- if (isspace(i))
- *pos++=i;
+ if (my_isspace(system_charset_info,i))
+ *pos++= i;
*pos=0; /* End pointer */
if (!(glob_replace=init_replace((char**) from_array.typelib.type_names,
(char**) to_array.typelib.type_names,
@@ -1287,7 +1294,7 @@ int select_connection(char *p)
if (!*p)
die("Missing connection name in connect\n");
name = p;
- while (*p && !isspace(*p))
+ while (*p && !my_isspace(system_charset_info,*p))
p++;
*p = 0;
@@ -1313,7 +1320,7 @@ int close_connection(struct st_query* q)
if (!*p)
die("Missing connection name in connect\n");
name = p;
- while (*p && !isspace(*p))
+ while (*p && !my_isspace(system_charset_info,*p))
p++;
*p = 0;
@@ -1349,11 +1356,13 @@ int close_connection(struct st_query* q)
char* safe_get_param(char* str, char** arg, const char* msg)
{
DBUG_ENTER("safe_get_param");
- while (*str && isspace(*str)) str++;
+ while (*str && my_isspace(system_charset_info,*str))
+ str++;
*arg = str;
for (; *str && *str != ',' && *str != ')' ; str++)
{
- if (isspace(*str)) *str = 0;
+ if (my_isspace(system_charset_info,*str))
+ *str = 0;
}
if (!*str)
die(msg);
@@ -1635,7 +1644,7 @@ int read_line(char* buf, int size)
{
state = R_COMMENT;
}
- else if (isspace(c))
+ else if (my_isspace(system_charset_info,c))
{
if (c == '\n')
start_lineno= ++*lineno; /* Query hasn't started yet */
@@ -1761,7 +1770,7 @@ int read_query(struct st_query** q_ptr)
{
expected_errno = 0;
p++;
- for (;isdigit(*p);p++)
+ for (;my_isdigit(system_charset_info,*p);p++)
expected_errno = expected_errno * 10 + *p - '0';
q->expected_errno[0] = expected_errno;
q->expected_errno[1] = 0;
@@ -1769,25 +1778,28 @@ int read_query(struct st_query** q_ptr)
}
}
- while (*p && isspace(*p)) p++ ;
+ while (*p && my_isspace(system_charset_info,*p))
+ p++ ;
if (*p == '@')
{
p++;
p1 = q->record_file;
- while (!isspace(*p) &&
+ while (!my_isspace(system_charset_info,*p) &&
p1 < q->record_file + sizeof(q->record_file) - 1)
*p1++ = *p++;
*p1 = 0;
}
}
- while (*p && isspace(*p)) p++;
+ while (*p && my_isspace(system_charset_info,*p))
+ p++;
if (!(q->query_buf=q->query=my_strdup(p,MYF(MY_WME))))
die(NullS);
/* Calculate first word and first argument */
- for (p=q->query; *p && !isspace(*p) ; p++) ;
+ for (p=q->query; *p && !my_isspace(system_charset_info,*p) ; p++) ;
q->first_word_len = (uint) (p - q->query);
- while (*p && isspace(*p)) p++;
+ while (*p && my_isspace(system_charset_info,*p))
+ p++;
q->first_argument=p;
q->end = strend(q->query);
parser.read_lines++;
@@ -2036,6 +2048,36 @@ static void replace_dynstr_append_mem(DYNAMIC_STRING *ds, const char *val,
dynstr_append_mem(ds, val, len);
}
+/*
+ Append all results to the dynamic string separated with '\t'
+*/
+
+static void append_result(DYNAMIC_STRING *ds, MYSQL_RES *res)
+{
+ MYSQL_ROW row;
+ int num_fields= mysql_num_fields(res);
+ unsigned long *lengths;
+ while ((row = mysql_fetch_row(res)))
+ {
+ int i;
+ lengths = mysql_fetch_lengths(res);
+ for (i = 0; i < num_fields; i++)
+ {
+ const char *val= row[i];
+ ulonglong len= lengths[i];
+ if (!val)
+ {
+ val = "NULL";
+ len = 4;
+ }
+ if (i)
+ dynstr_append_mem(ds, "\t", 1);
+ replace_dynstr_append_mem(ds, val, len);
+ }
+ dynstr_append_mem(ds, "\n", 1);
+ }
+}
+
/*
* flags control the phased/stages of query execution to be performed
@@ -2046,12 +2088,7 @@ static void replace_dynstr_append_mem(DYNAMIC_STRING *ds, const char *val,
int run_query(MYSQL* mysql, struct st_query* q, int flags)
{
MYSQL_RES* res = 0;
- MYSQL_FIELD* fields;
- MYSQL_ROW row;
- int num_fields,i, error = 0;
- unsigned long* lengths;
- char* val;
- int len;
+ int i, error = 0;
DYNAMIC_STRING *ds;
DYNAMIC_STRING ds_tmp;
DYNAMIC_STRING eval_query;
@@ -2139,17 +2176,17 @@ int run_query(MYSQL* mysql, struct st_query* q, int flags)
verbose_msg("query '%s' failed: %d: %s", q->query, mysql_errno(mysql),
mysql_error(mysql));
/*
- if we do not abort on error, failure to run the query does
- not fail the whole test case
+ if we do not abort on error, failure to run the query does
+ not fail the whole test case
*/
goto end;
}
/*{
verbose_msg("failed in mysql_store_result for query '%s' (%d)", query,
- mysql_errno(mysql));
+ mysql_errno(mysql));
error = 1;
goto end;
- }*/
+ }*/
}
if (q->expected_errno[0])
@@ -2160,45 +2197,52 @@ int run_query(MYSQL* mysql, struct st_query* q, int flags)
goto end;
}
- if (!res)
- goto end;
-
if (!disable_result_log)
{
- fields = mysql_fetch_fields(res);
- num_fields = mysql_num_fields(res);
- for (i = 0; i < num_fields; i++)
+ if (res)
{
- if (i)
- dynstr_append_mem(ds, "\t", 1);
- dynstr_append(ds, fields[i].name);
- }
-
- dynstr_append_mem(ds, "\n", 1);
-
- while ((row = mysql_fetch_row(res)))
- {
- lengths = mysql_fetch_lengths(res);
+ int num_fields= mysql_num_fields(res);
+ MYSQL_FIELD *fields= mysql_fetch_fields(res);
for (i = 0; i < num_fields; i++)
{
- val = (char*)row[i];
- len = lengths[i];
-
- if (!val)
- {
- val = (char*)"NULL";
- len = 4;
- }
-
if (i)
dynstr_append_mem(ds, "\t", 1);
- replace_dynstr_append_mem(ds, val, len);
+ dynstr_append(ds, fields[i].name);
}
dynstr_append_mem(ds, "\n", 1);
+ append_result(ds, res);
+ }
+
+ /* Add all warnings to the result */
+ if (!disable_warnings && mysql_warning_count(mysql))
+ {
+ MYSQL_RES *warn_res=0;
+ uint count= mysql_warning_count(mysql);
+ if (!mysql_real_query(mysql, "SHOW WARNINGS", 13))
+ {
+ warn_res=mysql_store_result(mysql);
+ }
+ if (!warn_res)
+ verbose_msg("Warning count is %u but didn't get any warnings\n",
+ count);
+ else
+ {
+ dynstr_append_mem(ds, "Warnings:\n", 10);
+ append_result(ds, warn_res);
+ mysql_free_result(warn_res);
+ }
+ }
+ if (!disable_info && mysql_info(mysql))
+ {
+ dynstr_append(ds, "info: ");
+ dynstr_append(ds, mysql_info(mysql));
+ dynstr_append_mem(ds, "\n", 1);
}
- if (glob_replace)
- free_replace();
}
+
+ if (glob_replace)
+ free_replace();
+
if (record)
{
if (!q->record_file[0] && !result_file)
@@ -2310,7 +2354,8 @@ static void init_var_hash()
{
VAR* v;
DBUG_ENTER("init_var_hash");
- if (hash_init(&var_hash, 1024, 0, 0, get_var_key, var_free, MYF(0)))
+ if (hash_init(&var_hash, system_charset_info,
+ 1024, 0, 0, get_var_key, var_free, MYF(0)))
die("Variable hash initialization failed");
var_from_env("MASTER_MYPORT", "9306");
var_from_env("SLAVE_MYPORT", "9307");
@@ -2403,6 +2448,10 @@ int main(int argc, char** argv)
case Q_DISABLE_QUERY_LOG: disable_query_log=1; break;
case Q_ENABLE_RESULT_LOG: disable_result_log=0; break;
case Q_DISABLE_RESULT_LOG: disable_result_log=1; break;
+ case Q_ENABLE_WARNINGS: disable_warnings=0; break;
+ case Q_DISABLE_WARNINGS: disable_warnings=1; break;
+ case Q_ENABLE_INFO: disable_info=0; break;
+ case Q_DISABLE_INFO: disable_info=1; break;
case Q_SOURCE: do_source(q); break;
case Q_SLEEP: do_sleep(q, 0); break;
case Q_REAL_SLEEP: do_sleep(q, 1); break;