Bug #49878 delimiter under false 'if' makes mysqltest test fail with 'Missing end of block'

delimiter not executed so does not recognize end of block
Always execute delimiter command, revert after false if() block.
This commit is contained in:
Bjorn Munch 2010-01-20 14:18:27 +01:00
parent bdf5ace1a2
commit 37dc5f082a
3 changed files with 54 additions and 1 deletions

View file

@ -132,6 +132,7 @@ struct st_block
int line; /* Start line of block */
my_bool ok; /* Should block be executed */
enum block_cmd cmd; /* Command owning the block */
char delim[MAX_DELIMITER_LENGTH]; /* Delimiter before block */
};
static struct st_block block_stack[32];
@ -5142,6 +5143,12 @@ int do_done(struct st_command *command)
}
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 */
cur_block--;
parser.current_line++;
@ -5200,6 +5207,7 @@ void do_block(enum block_cmd cmd, struct st_command* command)
cur_block++;
cur_block->cmd= cmd;
cur_block->ok= FALSE;
cur_block->delim[0]= '\0';
DBUG_VOID_RETURN;
}
@ -5236,6 +5244,15 @@ void do_block(enum block_cmd cmd, struct st_command* command)
if (not_expr)
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));
var_free(&v);
@ -7798,7 +7815,8 @@ int main(int argc, char **argv)
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
re-iterated over in a true context. This can only happen if there's

View file

@ -377,6 +377,10 @@ test
test2
test3
test4
outer
true-inner
true-inner again
true-outer
Counter is greater than 0, (counter=10)
Counter is not 0, (counter=0)
1

View file

@ -1006,6 +1006,37 @@ echo test3stop
--delimiter ;
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