Commit 403cac0f authored by Elena Stepanova's avatar Elena Stepanova

Allow multiple error codes inside a variable in --error command

parent 49da8e7e
...@@ -5205,15 +5205,32 @@ const char *get_errname_from_code (uint error_code) ...@@ -5205,15 +5205,32 @@ const char *get_errname_from_code (uint error_code)
void do_get_errcodes(struct st_command *command) void do_get_errcodes(struct st_command *command)
{ {
struct st_match_err *to= saved_expected_errors.err; struct st_match_err *to= saved_expected_errors.err;
char *p= command->first_argument;
uint count= 0;
char *next;
DBUG_ENTER("do_get_errcodes"); DBUG_ENTER("do_get_errcodes");
if (!*p) if (!*command->first_argument)
die("Missing argument(s) to 'error'"); die("Missing argument(s) to 'error'");
/* TODO: Potentially, there is a possibility of variables
being expanded twice, e.g.
let $errcodes = 1,\$a;
let $a = 1051;
error $errcodes;
DROP TABLE unknown_table;
...
Got one of the listed errors
But since it requires manual escaping, it does not seem
particularly dangerous or error-prone.
*/
DYNAMIC_STRING ds;
init_dynamic_string(&ds, 0, command->query_len + 64, 256);
do_eval(&ds, command->first_argument, command->end, !is_windows);
char *p= ds.str;
uint count= 0;
char *next;
do do
{ {
char *end; char *end;
...@@ -5323,11 +5340,15 @@ void do_get_errcodes(struct st_command *command) ...@@ -5323,11 +5340,15 @@ void do_get_errcodes(struct st_command *command)
} while (*p); } while (*p);
command->last_argument= p; command->last_argument= command->first_argument;
while (*command->last_argument)
command->last_argument++;
to->type= ERR_EMPTY; /* End of data */ to->type= ERR_EMPTY; /* End of data */
DBUG_PRINT("info", ("Expected errors: %d", count)); DBUG_PRINT("info", ("Expected errors: %d", count));
saved_expected_errors.count= count; saved_expected_errors.count= count;
dynstr_free(&ds);
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
......
...@@ -690,6 +690,7 @@ Got one of the listed errors ...@@ -690,6 +690,7 @@ Got one of the listed errors
insert into t1 values ("Abcd"); insert into t1 values ("Abcd");
Got one of the listed errors Got one of the listed errors
garbage; garbage;
SELECT * FROM non_existing_table;
drop table t2; drop table t2;
create table t1 ( f1 char(10)); create table t1 ( f1 char(10));
insert into t1 values ("Abcd"); insert into t1 values ("Abcd");
......
...@@ -2120,6 +2120,11 @@ insert into t1 values ("Abcd"); ...@@ -2120,6 +2120,11 @@ insert into t1 values ("Abcd");
--error $errno1,ER_PARSE_ERROR --error $errno1,ER_PARSE_ERROR
garbage; garbage;
let $errno_multi = $errno1,ER_NO_SUCH_TABLE,$errno2,1062;
--error $errno_multi
SELECT * FROM non_existing_table;
drop table t2; drop table t2;
......
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