Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
MDEV-26841: ROW_NUMBER is not set and differs from the message upon
ER_WRONG_VALUE_COUNT_ON_ROW for the 1st row

Analysis: Current row for warning does not increment for prepare phase
Fix: Increment current row for warning if number of fields in the table and
row values dont match and number of values in rows is greater than number
of fields
  • Loading branch information
mariadb-RuchaDeodhar authored and vuvova committed Oct 26, 2021
1 parent 635be99 commit 797bd73
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
18 changes: 18 additions & 0 deletions mysql-test/main/get_diagnostics.result
Expand Up @@ -1747,3 +1747,21 @@ SELECT @n, @m;
@n @m
2 Data truncated for column 'a' at row 2
DROP TABLE t1;
#
# MDEV-26841: ROW_NUMBER is not set and differs from the message upon
# ER_WRONG_VALUE_COUNT_ON_ROW for the 1st row
#
CREATE TABLE t1 (a INT);
INSERT INTO t1 VALUES (1,2),(3);
ERROR 21S01: Column count doesn't match value count at row 1
GET DIAGNOSTICS CONDITION 1 @n= ROW_NUMBER, @m= MESSAGE_TEXT;
SELECT @n, @m;
@n @m
1 Column count doesn't match value count at row 1
INSERT INTO t1(a) VALUES(1,2), (3);
ERROR 21S01: Column count doesn't match value count at row 1
GET DIAGNOSTICS CONDITION 1 @n= ROW_NUMBER, @m= MESSAGE_TEXT;
SELECT @n, @m;
@n @m
1 Column count doesn't match value count at row 1
DROP TABLE t1;
21 changes: 21 additions & 0 deletions mysql-test/main/get_diagnostics.test
Expand Up @@ -1632,3 +1632,24 @@ GET DIAGNOSTICS CONDITION 1 @n= ROW_NUMBER, @m= MESSAGE_TEXT;
SELECT @n, @m;

DROP TABLE t1;

--echo #
--echo # MDEV-26841: ROW_NUMBER is not set and differs from the message upon
--echo # ER_WRONG_VALUE_COUNT_ON_ROW for the 1st row
--echo #

CREATE TABLE t1 (a INT);

--error ER_WRONG_VALUE_COUNT_ON_ROW
INSERT INTO t1 VALUES (1,2),(3);

GET DIAGNOSTICS CONDITION 1 @n= ROW_NUMBER, @m= MESSAGE_TEXT;
SELECT @n, @m;

--error ER_WRONG_VALUE_COUNT_ON_ROW
INSERT INTO t1(a) VALUES(1,2), (3);

GET DIAGNOSTICS CONDITION 1 @n= ROW_NUMBER, @m= MESSAGE_TEXT;
SELECT @n, @m;

DROP TABLE t1;
2 changes: 2 additions & 0 deletions sql/sql_insert.cc
Expand Up @@ -229,6 +229,7 @@ static int check_insert_fields(THD *thd, TABLE_LIST *table_list,
}
if (values.elements != table->s->visible_fields)
{
thd->get_stmt_da()->reset_current_row_for_warning(1);
my_error(ER_WRONG_VALUE_COUNT_ON_ROW, MYF(0), 1L);
DBUG_RETURN(-1);
}
Expand All @@ -253,6 +254,7 @@ static int check_insert_fields(THD *thd, TABLE_LIST *table_list,

if (fields.elements != values.elements)
{
thd->get_stmt_da()->reset_current_row_for_warning(1);
my_error(ER_WRONG_VALUE_COUNT_ON_ROW, MYF(0), 1L);
DBUG_RETURN(-1);
}
Expand Down

0 comments on commit 797bd73

Please sign in to comment.