diff options
-rw-r--r-- | mysql-test/main/get_diagnostics.result | 18 | ||||
-rw-r--r-- | mysql-test/main/get_diagnostics.test | 21 | ||||
-rw-r--r-- | sql/sql_yacc.yy | 7 |
3 files changed, 43 insertions, 3 deletions
diff --git a/mysql-test/main/get_diagnostics.result b/mysql-test/main/get_diagnostics.result index 2e749fa21d7..d923390b429 100644 --- a/mysql-test/main/get_diagnostics.result +++ b/mysql-test/main/get_diagnostics.result @@ -1811,3 +1811,21 @@ SELECT @n; @n 4 DROP TABLE t; +# +# MDEV-26878: Query failing with syntax error sets ROW_NUMBER to +# non-zero +# +CREATE TABLE t1 (id1 INT); +INSERT INTO t1 VALUES XXX (1),(2); +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'XXX (1),(2)' at line 1 +GET DIAGNOSTICS CONDITION 1 @n= ROW_NUMBER; +SELECT @n; +@n +0 +INSERT INTO t1 VALUES (1), (ALL); +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'ALL)' at line 1 +GET DIAGNOSTICS CONDITION 1 @num=ROW_NUMBER; +SELECT @num; +@num +2 +DROP TABLE t1; diff --git a/mysql-test/main/get_diagnostics.test b/mysql-test/main/get_diagnostics.test index e8d81dca1e6..55c8f50e9fe 100644 --- a/mysql-test/main/get_diagnostics.test +++ b/mysql-test/main/get_diagnostics.test @@ -1687,3 +1687,24 @@ GET DIAGNOSTICS CONDITION 3 @n = ROW_NUMBER; SELECT @n; DROP TABLE t; + +--echo # +--echo # MDEV-26878: Query failing with syntax error sets ROW_NUMBER to +--echo # non-zero +--echo # + +CREATE TABLE t1 (id1 INT); + +--error ER_PARSE_ERROR +INSERT INTO t1 VALUES XXX (1),(2); + +GET DIAGNOSTICS CONDITION 1 @n= ROW_NUMBER; +SELECT @n; + +--error ER_PARSE_ERROR +INSERT INTO t1 VALUES (1), (ALL); + +GET DIAGNOSTICS CONDITION 1 @num=ROW_NUMBER; +SELECT @num; + +DROP TABLE t1; diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 8ebefbb3d82..47ed3ded4a7 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -8426,6 +8426,8 @@ query_specification_start: { SELECT_LEX *sel; LEX *lex= Lex; + if (lex->sql_command == SQLCOM_INSERT) + thd->get_stmt_da()->inc_current_row_for_warning(); if (!(sel= lex->alloc_select(TRUE)) || lex->push_select(sel)) MYSQL_YYABORT; sel->init_select(); @@ -12909,7 +12911,6 @@ insert: Lex->sql_command= SQLCOM_INSERT; Lex->duplicates= DUP_ERROR; thd->get_stmt_da()->opt_clear_warning_info(thd->query_id); - thd->get_stmt_da()->reset_current_row_for_warning(1); } insert_start insert_lock_option opt_ignore opt_into insert_table { @@ -12929,7 +12930,6 @@ replace: Lex->sql_command = SQLCOM_REPLACE; Lex->duplicates= DUP_REPLACE; thd->get_stmt_da()->opt_clear_warning_info(thd->query_id); - thd->get_stmt_da()->reset_current_row_for_warning(1); } insert_start replace_lock_option opt_into insert_table { @@ -13008,6 +13008,7 @@ insert_field_spec: | SET { LEX *lex=Lex; + thd->get_stmt_da()->inc_current_row_for_warning(); if (unlikely(!(lex->insert_list= new (thd->mem_root) List_item)) || unlikely(lex->many_values.push_back(lex->insert_list, thd->mem_root))) @@ -13084,13 +13085,13 @@ opt_by: no_braces: '(' { + thd->get_stmt_da()->inc_current_row_for_warning(); if (unlikely(!(Lex->insert_list= new (thd->mem_root) List_item))) MYSQL_YYABORT; } opt_values ')' { LEX *lex=Lex; - thd->get_stmt_da()->inc_current_row_for_warning(); if (unlikely(lex->many_values.push_back(lex->insert_list, thd->mem_root))) MYSQL_YYABORT; |