Commit 8b046e60 authored by Bjorn Munch's avatar Bjorn Munch

upmerge 43005,48888,49837,49878,50471

parents a7dc95fb acc2b1ba
...@@ -134,6 +134,7 @@ struct st_block ...@@ -134,6 +134,7 @@ struct st_block
int line; /* Start line of block */ int line; /* Start line of block */
my_bool ok; /* Should block be executed */ my_bool ok; /* Should block be executed */
enum block_cmd cmd; /* Command owning the block */ enum block_cmd cmd; /* Command owning the block */
char delim[MAX_DELIMITER_LENGTH]; /* Delimiter before block */
}; };
static struct st_block block_stack[32]; static struct st_block block_stack[32];
...@@ -2650,6 +2651,10 @@ void do_exec(struct st_command *command) ...@@ -2650,6 +2651,10 @@ void do_exec(struct st_command *command)
#endif #endif
#endif #endif
/* exec command is interpreted externally and will not take newlines */
while(replace(&ds_cmd, "\n", 1, " ", 1) == 0)
;
DBUG_PRINT("info", ("Executing '%s' as '%s'", DBUG_PRINT("info", ("Executing '%s' as '%s'",
command->first_argument, ds_cmd.str)); command->first_argument, ds_cmd.str));
...@@ -5109,6 +5114,12 @@ int do_done(struct st_command *command) ...@@ -5109,6 +5114,12 @@ int do_done(struct st_command *command)
} }
else else
{ {
if (*cur_block->delim)
{
/* Restore "old" delimiter after false if block */
strcpy (delimiter, cur_block->delim);
delimiter_length= strlen(delimiter);
}
/* Pop block from stack, goto next line */ /* Pop block from stack, goto next line */
cur_block--; cur_block--;
parser.current_line++; parser.current_line++;
...@@ -5167,6 +5178,7 @@ void do_block(enum block_cmd cmd, struct st_command* command) ...@@ -5167,6 +5178,7 @@ void do_block(enum block_cmd cmd, struct st_command* command)
cur_block++; cur_block++;
cur_block->cmd= cmd; cur_block->cmd= cmd;
cur_block->ok= FALSE; cur_block->ok= FALSE;
cur_block->delim[0]= '\0';
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
...@@ -5203,6 +5215,15 @@ void do_block(enum block_cmd cmd, struct st_command* command) ...@@ -5203,6 +5215,15 @@ void do_block(enum block_cmd cmd, struct st_command* command)
if (not_expr) if (not_expr)
cur_block->ok = !cur_block->ok; cur_block->ok = !cur_block->ok;
if (cur_block->ok)
{
cur_block->delim[0]= '\0';
} else
{
/* Remember "old" delimiter if entering a false if block */
strcpy (cur_block->delim, delimiter);
}
DBUG_PRINT("info", ("OK: %d", cur_block->ok)); DBUG_PRINT("info", ("OK: %d", cur_block->ok));
var_free(&v); var_free(&v);
...@@ -7629,7 +7650,14 @@ int main(int argc, char **argv) ...@@ -7629,7 +7650,14 @@ int main(int argc, char **argv)
1024, 0, 0, get_var_key, var_free, MYF(0))) 1024, 0, 0, get_var_key, var_free, MYF(0)))
die("Variable hash initialization failed"); die("Variable hash initialization failed");
var_set_string("$MYSQL_SERVER_VERSION", MYSQL_SERVER_VERSION); var_set_string("MYSQL_SERVER_VERSION", MYSQL_SERVER_VERSION);
var_set_string("MYSQL_SYSTEM_TYPE", SYSTEM_TYPE);
var_set_string("MYSQL_MACHINE_TYPE", MACHINE_TYPE);
if (sizeof(void *) == 8) {
var_set_string("MYSQL_SYSTEM_ARCHITECTURE", "64");
} else {
var_set_string("MYSQL_SYSTEM_ARCHITECTURE", "32");
}
memset(&master_pos, 0, sizeof(master_pos)); memset(&master_pos, 0, sizeof(master_pos));
...@@ -7759,7 +7787,8 @@ int main(int argc, char **argv) ...@@ -7759,7 +7787,8 @@ int main(int argc, char **argv)
command->type= Q_COMMENT; command->type= Q_COMMENT;
} }
my_bool ok_to_do= cur_block->ok; /* delimiter needs to be executed so we can continue to parse */
my_bool ok_to_do= cur_block->ok || command->type == Q_DELIMITER;
/* /*
Some commands need to be "done" the first time if they may get Some commands need to be "done" the first time if they may get
re-iterated over in a true context. This can only happen if there's re-iterated over in a true context. This can only happen if there's
...@@ -9417,7 +9446,7 @@ int insert_pointer_name(reg1 POINTER_ARRAY *pa,char * name) ...@@ -9417,7 +9446,7 @@ int insert_pointer_name(reg1 POINTER_ARRAY *pa,char * name)
if (pa->length+length >= pa->max_length) if (pa->length+length >= pa->max_length)
{ {
if (!(new_pos= (uchar*) my_realloc((uchar*) pa->str, if (!(new_pos= (uchar*) my_realloc((uchar*) pa->str,
(uint) (pa->max_length+PS_MALLOC), (uint) (pa->length+length+PS_MALLOC),
MYF(MY_WME)))) MYF(MY_WME))))
DBUG_RETURN(1); DBUG_RETURN(1);
if (new_pos != pa->str) if (new_pos != pa->str)
...@@ -9428,7 +9457,7 @@ int insert_pointer_name(reg1 POINTER_ARRAY *pa,char * name) ...@@ -9428,7 +9457,7 @@ int insert_pointer_name(reg1 POINTER_ARRAY *pa,char * name)
char*); char*);
pa->str=new_pos; pa->str=new_pos;
} }
pa->max_length+=PS_MALLOC; pa->max_length= pa->length+length+PS_MALLOC;
} }
if (pa->typelib.count >= pa->max_count-1) if (pa->typelib.count >= pa->max_count-1)
{ {
......
...@@ -186,13 +186,19 @@ int main(int argc, const char** argv ) ...@@ -186,13 +186,19 @@ int main(int argc, const char** argv )
die("No real args -> nothing to do"); die("No real args -> nothing to do");
/* Copy the remaining args to child_arg */ /* Copy the remaining args to child_arg */
for (int j= i+1; j < argc; j++) { for (int j= i+1; j < argc; j++) {
if (strchr (argv[j], ' ')) { arg= argv[j];
/* Protect with "" if this arg contains a space */ if (strchr (arg, ' ') &&
arg[0] != '\"' &&
arg[strlen(arg)] != '\"')
{
/* Quote arg that contains spaces and are not quoted already */
to+= _snprintf(to, child_args + sizeof(child_args) - to, to+= _snprintf(to, child_args + sizeof(child_args) - to,
"\"%s\" ", argv[j]); "\"%s\" ", arg);
} else { }
else
{
to+= _snprintf(to, child_args + sizeof(child_args) - to, to+= _snprintf(to, child_args + sizeof(child_args) - to,
"%s ", argv[j]); "%s ", arg);
} }
} }
break; break;
......
...@@ -216,6 +216,12 @@ source database ...@@ -216,6 +216,12 @@ source database
echo message echo message echo message echo message
mysqltest: At line 1: Missing argument in exec mysqltest: At line 1: Missing argument in exec
1
1
2
2
X
3
MySQL MySQL
"MySQL" "MySQL"
MySQL: The MySQL: The
...@@ -377,6 +383,10 @@ test ...@@ -377,6 +383,10 @@ test
test2 test2
test3 test3
test4 test4
outer
true-inner
true-inner again
true-outer
Counter is greater than 0, (counter=10) Counter is greater than 0, (counter=10)
Counter is not 0, (counter=0) Counter is not 0, (counter=0)
1 1
...@@ -417,6 +427,9 @@ mysqltest: At line 1: Wrong number of arguments to replace_column in 'replace_co ...@@ -417,6 +427,9 @@ mysqltest: At line 1: Wrong number of arguments to replace_column in 'replace_co
mysqltest: At line 1: Wrong column number to replace_column in 'replace_column a b' mysqltest: At line 1: Wrong column number to replace_column in 'replace_column a b'
mysqltest: At line 1: Wrong column number to replace_column in 'replace_column a 1' mysqltest: At line 1: Wrong column number to replace_column in 'replace_column a 1'
mysqltest: At line 1: Wrong column number to replace_column in 'replace_column 1 b c ' mysqltest: At line 1: Wrong column number to replace_column in 'replace_column 1 b c '
select "LONG_STRING" as x;
x
LONG_STRING
mysqltest: At line 1: Invalid integer argument "10!" mysqltest: At line 1: Invalid integer argument "10!"
mysqltest: At line 1: Invalid integer argument "a" mysqltest: At line 1: Invalid integer argument "a"
mysqltest: At line 1: Missing required argument 'connection name' to command 'connect' mysqltest: At line 1: Missing required argument 'connection name' to command 'connect'
......
...@@ -605,6 +605,15 @@ echo ; ...@@ -605,6 +605,15 @@ echo ;
--error 1 --error 1
--exec echo "--exec " | $MYSQL_TEST 2>&1 --exec echo "--exec " | $MYSQL_TEST 2>&1
# Multi-line exec
exec $MYSQL
test -e "select 1";
exec $MYSQL test -e "select
2";
let $query = select 3
as X;
exec $MYSQL test -e "$query";
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------
# Test let command # Test let command
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------
...@@ -1006,6 +1015,37 @@ echo test3stop ...@@ -1006,6 +1015,37 @@ echo test3stop
--delimiter ; --delimiter ;
echo test4; echo test4;
# ----------------------------------------------------------------------------
# Test that delimiter within if() works in in various combinations
# ----------------------------------------------------------------------------
if (0)
{
delimiter ||;
echo false-inner||
if (0)
{
delimiter *||
echo false-innerer*
delimiter ||*
}
echo false-inner again||
}
echo outer;
if (1)
{
delimiter /;
echo true-inner/
if (0)
{
delimiter %/
echo true-innerer%
}
echo true-inner again/
}
echo true-outer/
delimiter ;/
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------
# Test if # Test if
...@@ -1285,6 +1325,17 @@ select "a" as col1, "c" as col2; ...@@ -1285,6 +1325,17 @@ select "a" as col1, "c" as col2;
--error 1 --error 1
--exec echo "--replace_column 1 b c " | $MYSQL_TEST 2>&1 --exec echo "--replace_column 1 b c " | $MYSQL_TEST 2>&1
let $long_rep= 1234567890123456789012345678901234567890;
let $long_rep= $long_rep,$long_rep;
let $long_rep= $long_rep,$long_rep;
let $long_rep= $long_rep,$long_rep;
let $long_rep= $long_rep,$long_rep;
let $long_rep= $long_rep,$long_rep;
# This tests from strings > 1024 (here 1311)
--replace_result $long_rep LONG_STRING
eval select "$long_rep" as x;
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------
# Test sync_with_master # Test sync_with_master
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment