From abdc39b0a72f2912e5c4d2e8e0212370d5fdf1c3 Mon Sep 17 00:00:00 2001 From: Alexey Botchkov Date: Wed, 17 Mar 2021 10:51:44 +0400 Subject: [PATCH] MDEV-25143 JSON_TABLE: Server crashes in handler::print_error / hton_name upon ERROR ON EMPTY. should return some error code from ha_json_table::rnd_pos() not just 1. --- mysql-test/suite/json/r/json_table.result | 5 +++++ mysql-test/suite/json/t/json_table.test | 6 ++++++ sql/json_table.cc | 2 +- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/mysql-test/suite/json/r/json_table.result b/mysql-test/suite/json/r/json_table.result index 0b0b1aa1ca6..29157ac6be2 100644 --- a/mysql-test/suite/json/r/json_table.result +++ b/mysql-test/suite/json/r/json_table.result @@ -508,5 +508,10 @@ a EXECUTE stmt; a # +# MDEV-JSON_TABLE: Server crashes in handler::print_error / hton_name upon ERROR ON EMPTY +# +SELECT a, b FROM JSON_TABLE('[]', '$' COLUMNS (a FOR ORDINALITY, b INT PATH '$[*]' ERROR ON EMPTY)) AS t ORDER BY a; +ERROR HY000: Field 'b' can't be set for JSON_TABLE 't'. +# # End of 10.6 tests # diff --git a/mysql-test/suite/json/t/json_table.test b/mysql-test/suite/json/t/json_table.test index 8da1a5e3865..c09f3301889 100644 --- a/mysql-test/suite/json/t/json_table.test +++ b/mysql-test/suite/json/t/json_table.test @@ -395,6 +395,12 @@ PREPARE stmt FROM "SELECT * FROM (SELECT * FROM JSON_TABLE(LOAD_FILE('x'), '$' C EXECUTE stmt; EXECUTE stmt; +--echo # +--echo # MDEV-JSON_TABLE: Server crashes in handler::print_error / hton_name upon ERROR ON EMPTY +--echo # +--error ER_JSON_TABLE_ERROR_ON_FIELD +SELECT a, b FROM JSON_TABLE('[]', '$' COLUMNS (a FOR ORDINALITY, b INT PATH '$[*]' ERROR ON EMPTY)) AS t ORDER BY a; + --echo # --echo # End of 10.6 tests --echo # diff --git a/sql/json_table.cc b/sql/json_table.cc index f8b97a627f8..f7605fbda73 100644 --- a/sql/json_table.cc +++ b/sql/json_table.cc @@ -445,7 +445,7 @@ error_return: int ha_json_table::rnd_pos(uchar * buf, uchar *pos) { - return fill_column_values(buf, pos); + return fill_column_values(buf, pos) ? HA_ERR_TABLE_IN_FK_CHECK : 0; }