mirror of
https://github.com/MariaDB/server.git
synced 2025-01-29 18:20:07 +01:00
Added support for multi statement tests. Use mysqltest internal
command delimiter to change the default delimiter (;) to something else, a string upto 16 characters is allowed. Separate the sub queries with ';' and end the whole statement with your own delimiter.
This commit is contained in:
parent
caf4fd96f2
commit
3467862b32
3 changed files with 277 additions and 199 deletions
|
@ -42,7 +42,7 @@
|
|||
|
||||
**********************************************************************/
|
||||
|
||||
#define MTEST_VERSION "2.0"
|
||||
#define MTEST_VERSION "2.1"
|
||||
|
||||
#include <my_global.h>
|
||||
#include <mysql_embed.h>
|
||||
|
@ -86,7 +86,8 @@
|
|||
#define MAX_CON_TRIES 5
|
||||
|
||||
#define SLAVE_POLL_INTERVAL 300000 /* 0.3 of a sec */
|
||||
|
||||
#define DEFAULT_DELIMITER ";"
|
||||
#define MAX_DELIMITER 16
|
||||
|
||||
enum {OPT_MANAGER_USER=256,OPT_MANAGER_HOST,OPT_MANAGER_PASSWD,
|
||||
OPT_MANAGER_PORT,OPT_MANAGER_WAIT_TIMEOUT, OPT_SKIP_SAFEMALLOC,
|
||||
|
@ -114,6 +115,8 @@ static FILE** cur_file;
|
|||
static FILE** file_stack_end;
|
||||
static uint lineno_stack[MAX_INCLUDE_DEPTH];
|
||||
static char TMPDIR[FN_REFLEN];
|
||||
static char delimiter[MAX_DELIMITER]= DEFAULT_DELIMITER;
|
||||
static uint delimiter_length= 1;
|
||||
|
||||
static int *cur_block, *block_stack_end;
|
||||
static int block_stack[BLOCK_STACK_DEPTH];
|
||||
|
@ -209,7 +212,8 @@ Q_WAIT_FOR_SLAVE_TO_STOP,
|
|||
Q_REQUIRE_VERSION,
|
||||
Q_ENABLE_WARNINGS, Q_DISABLE_WARNINGS,
|
||||
Q_ENABLE_INFO, Q_DISABLE_INFO,
|
||||
Q_EXEC,
|
||||
Q_EXEC, Q_DELIMITER,
|
||||
|
||||
Q_UNKNOWN, /* Unknown command. */
|
||||
Q_COMMENT, /* Comments, ignored. */
|
||||
Q_COMMENT_WITH_COMMAND
|
||||
|
@ -281,6 +285,7 @@ const char *command_names[]=
|
|||
"enable_info",
|
||||
"disable_info",
|
||||
"exec",
|
||||
"delimiter",
|
||||
0
|
||||
};
|
||||
|
||||
|
@ -1472,7 +1477,8 @@ int safe_connect(MYSQL* con, const char* host, const char* user,
|
|||
int i;
|
||||
for (i = 0; i < MAX_CON_TRIES; ++i)
|
||||
{
|
||||
if (mysql_real_connect(con, host,user, pass, db, port, sock, 0))
|
||||
if (mysql_real_connect(con, host,user, pass, db, port, sock,
|
||||
CLIENT_MULTI_STATEMENTS))
|
||||
{
|
||||
con_error = 0;
|
||||
break;
|
||||
|
@ -1622,6 +1628,28 @@ int do_while(struct st_query* q)
|
|||
}
|
||||
|
||||
|
||||
my_bool end_of_query(int c, char* p)
|
||||
{
|
||||
uint i= 0, j;
|
||||
int tmp[MAX_DELIMITER]= {0};
|
||||
|
||||
for (i= 0; c == *(delimiter + i) && i < delimiter_length;
|
||||
i++, c= fgetc(*cur_file))
|
||||
tmp[i]= c;
|
||||
tmp[i]= c;
|
||||
|
||||
for (j= i; j > 0 && i != delimiter_length; j--)
|
||||
ungetc(tmp[j], *cur_file);
|
||||
if (i == delimiter_length)
|
||||
{
|
||||
ungetc(tmp[j], *cur_file);
|
||||
*p= 0;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int read_line(char* buf, int size)
|
||||
{
|
||||
int c;
|
||||
|
@ -1650,11 +1678,8 @@ int read_line(char* buf, int size)
|
|||
switch(state) {
|
||||
case R_NORMAL:
|
||||
/* Only accept '{' in the beginning of a line */
|
||||
if (c == ';')
|
||||
{
|
||||
*p = 0;
|
||||
if (end_of_query(c, p))
|
||||
return 0;
|
||||
}
|
||||
else if (c == '\'')
|
||||
state = R_Q1;
|
||||
else if (c == '"')
|
||||
|
@ -1690,7 +1715,7 @@ int read_line(char* buf, int size)
|
|||
*buf= 0;
|
||||
return 0;
|
||||
}
|
||||
else if (c == ';' || c == '{')
|
||||
else if (end_of_query(c, p) || c == '{')
|
||||
{
|
||||
*p= 0;
|
||||
return 0;
|
||||
|
@ -1710,11 +1735,8 @@ int read_line(char* buf, int size)
|
|||
state= R_ESC_SLASH_Q1;
|
||||
break;
|
||||
case R_ESC_Q_Q1:
|
||||
if (c == ';')
|
||||
{
|
||||
*p = 0;
|
||||
if (end_of_query(c, p))
|
||||
return 0;
|
||||
}
|
||||
if (c != '\'')
|
||||
state= R_NORMAL;
|
||||
else
|
||||
|
@ -1731,11 +1753,8 @@ int read_line(char* buf, int size)
|
|||
state= R_ESC_SLASH_Q2;
|
||||
break;
|
||||
case R_ESC_Q_Q2:
|
||||
if (c == ';')
|
||||
{
|
||||
*p = 0;
|
||||
if (end_of_query(c, p))
|
||||
return 0;
|
||||
}
|
||||
if (c != '"')
|
||||
state= R_NORMAL;
|
||||
else
|
||||
|
@ -2130,11 +2149,11 @@ static void append_result(DYNAMIC_STRING *ds, MYSQL_RES *res)
|
|||
int run_query(MYSQL* mysql, struct st_query* q, int flags)
|
||||
{
|
||||
MYSQL_RES* res= 0;
|
||||
int i, error = 0;
|
||||
int i, error= 0, err= 0, counter= 0;
|
||||
DYNAMIC_STRING *ds;
|
||||
DYNAMIC_STRING ds_tmp;
|
||||
DYNAMIC_STRING eval_query;
|
||||
char* query;
|
||||
char* query, buff[MAX_DELIMITER + 1]= {0};
|
||||
int query_len;
|
||||
DBUG_ENTER("run_query");
|
||||
|
||||
|
@ -2162,17 +2181,20 @@ int run_query(MYSQL* mysql, struct st_query* q, int flags)
|
|||
|
||||
if ((flags & QUERY_SEND) && mysql_send_query(mysql, query, query_len))
|
||||
die("At line %u: unable to send query '%s'(mysql_errno=%d,errno=%d)",
|
||||
start_lineno, query,
|
||||
mysql_errno(mysql), errno);
|
||||
if ((flags & QUERY_SEND) && !disable_query_log)
|
||||
start_lineno, query, mysql_errno(mysql), errno);
|
||||
|
||||
do
|
||||
{
|
||||
if ((flags & QUERY_SEND) && !disable_query_log && !counter)
|
||||
{
|
||||
replace_dynstr_append_mem(ds,query, query_len);
|
||||
dynstr_append_mem(ds,";\n",2);
|
||||
sprintf(buff, "%s\n", delimiter);
|
||||
dynstr_append_mem(ds, buff, strlen(delimiter) + 1);
|
||||
}
|
||||
if (!(flags & QUERY_REAP))
|
||||
DBUG_RETURN(0);
|
||||
|
||||
if ((*mysql->methods->read_query_result)(mysql) ||
|
||||
if ((!counter && (*mysql->methods->read_query_result)(mysql)) ||
|
||||
(!(last_result= res= mysql_store_result(mysql)) &&
|
||||
mysql_field_count(mysql)))
|
||||
{
|
||||
|
@ -2251,6 +2273,7 @@ int run_query(MYSQL* mysql, struct st_query* q, int flags)
|
|||
{
|
||||
int num_fields= mysql_num_fields(res);
|
||||
MYSQL_FIELD *fields= mysql_fetch_fields(res);
|
||||
|
||||
for (i = 0; i < num_fields; i++)
|
||||
{
|
||||
if (i)
|
||||
|
@ -2302,11 +2325,16 @@ int run_query(MYSQL* mysql, struct st_query* q, int flags)
|
|||
{
|
||||
error = check_result(ds, q->record_file, q->require_file);
|
||||
}
|
||||
|
||||
end:
|
||||
if (res)
|
||||
mysql_free_result(res);
|
||||
last_result= 0;
|
||||
counter++;
|
||||
} while (!(err= mysql_next_result(mysql)));
|
||||
if (err >= 1)
|
||||
mysql_error(mysql);
|
||||
|
||||
end:
|
||||
last_result=0;
|
||||
if (ds == &ds_tmp)
|
||||
dynstr_free(&ds_tmp);
|
||||
if (q->type == Q_EVAL)
|
||||
|
@ -2425,7 +2453,7 @@ int main(int argc, char **argv)
|
|||
my_bool require_file=0, q_send_flag=0;
|
||||
char save_file[FN_REFLEN];
|
||||
MY_INIT(argv[0]);
|
||||
{
|
||||
|
||||
DBUG_ENTER("main");
|
||||
DBUG_PROCESS(argv[0]);
|
||||
|
||||
|
@ -2520,6 +2548,10 @@ int main(int argc, char **argv)
|
|||
case Q_DEC: do_dec(q); break;
|
||||
case Q_ECHO: do_echo(q); break;
|
||||
case Q_SYSTEM: do_system(q); break;
|
||||
case Q_DELIMITER:
|
||||
strmake(delimiter, q->first_argument, sizeof(delimiter) - 1);
|
||||
delimiter_length= strlen(delimiter);
|
||||
break;
|
||||
case Q_LET: do_let(q); break;
|
||||
case Q_EVAL_RESULT: eval_result = 1; break;
|
||||
case Q_EVAL:
|
||||
|
@ -2647,7 +2679,7 @@ int main(int argc, char **argv)
|
|||
exit(error ? 1 : 0);
|
||||
return error ? 1 : 0; /* Keep compiler happy */
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Read arguments for embedded server and put them into
|
||||
|
|
33
mysql-test/r/multi_statement.result
Normal file
33
mysql-test/r/multi_statement.result
Normal file
|
@ -0,0 +1,33 @@
|
|||
select 1;
|
||||
1
|
||||
1
|
||||
select 2;
|
||||
select 3;
|
||||
select 4||||
|
||||
2
|
||||
2
|
||||
3
|
||||
3
|
||||
4
|
||||
4
|
||||
select 5;
|
||||
select 6;
|
||||
select 50, 'abc';'abcd'
|
||||
5
|
||||
5
|
||||
6
|
||||
6
|
||||
50 abc
|
||||
50 abc
|
||||
select "abcd'";'abcd'
|
||||
abcd'
|
||||
abcd'
|
||||
select "'abcd";'abcd'
|
||||
'abcd
|
||||
'abcd
|
||||
select 5'abcd'
|
||||
5
|
||||
5
|
||||
select 'finish';
|
||||
finish
|
||||
finish
|
13
mysql-test/t/multi_statement.test
Normal file
13
mysql-test/t/multi_statement.test
Normal file
|
@ -0,0 +1,13 @@
|
|||
select 1;
|
||||
delimiter ||||;
|
||||
select 2;
|
||||
select 3;
|
||||
select 4||||
|
||||
delimiter 'abcd'||||
|
||||
select 5;
|
||||
select 6;
|
||||
select 50, 'abc';'abcd'
|
||||
select "abcd'";'abcd'select "'abcd";'abcd'
|
||||
select 5'abcd'
|
||||
delimiter ;'abcd'
|
||||
select 'finish';
|
Loading…
Add table
Reference in a new issue