Skip to content

Commit

Permalink
MDEV-28651 quote(NULL) returns incorrect result in view ('NU' instead…
Browse files Browse the repository at this point in the history
… of 'NULL')

Item_func_quote did not calculate its max_length correctly for nullable
arguments.

Fix:

In case if the argument is nullable, reserve at least 4 characters
so the string "NULL" fits.
  • Loading branch information
abarkov committed Jan 23, 2024
1 parent 5ce6a35 commit 81d0185
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
27 changes: 27 additions & 0 deletions mysql-test/main/func_str.result
Original file line number Diff line number Diff line change
Expand Up @@ -5286,3 +5286,30 @@ ERROR 42000: Incorrect parameter count in the call to native function 'DECODE'
#
# End of 10.4 tests
#
#
# Start of 10.5 tests
#
#
# MDEV-28651 quote(NULL) returns incorrect result in view ('NU' instead of 'NULL')
#
CREATE VIEW v1 AS SELECT quote(NULL);
SELECT * FROM v1;
quote(NULL)
NULL
DESCRIBE v1;
Field Type Null Key Default Extra
quote(NULL) varbinary(4) YES NULL
CREATE TABLE t1 AS SELECT * FROM v1;
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`quote(NULL)` varbinary(4) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
SELECT * FROM t1;
quote(NULL)
NULL
DROP TABLE t1;
DROP VIEW v1;
#
# End of 10.5 tests
#
22 changes: 22 additions & 0 deletions mysql-test/main/func_str.test
Original file line number Diff line number Diff line change
Expand Up @@ -2329,3 +2329,25 @@ SELECT DECODE(NULL, NULL, NULL);
--echo #
--echo # End of 10.4 tests
--echo #

--echo #
--echo # Start of 10.5 tests
--echo #

--echo #
--echo # MDEV-28651 quote(NULL) returns incorrect result in view ('NU' instead of 'NULL')
--echo #

CREATE VIEW v1 AS SELECT quote(NULL);
SELECT * FROM v1;
DESCRIBE v1;
CREATE TABLE t1 AS SELECT * FROM v1;
SHOW CREATE TABLE t1;
SELECT * FROM t1;
DROP TABLE t1;
DROP VIEW v1;


--echo #
--echo # End of 10.5 tests
--echo #
3 changes: 3 additions & 0 deletions sql/item_strfunc.h
Original file line number Diff line number Diff line change
Expand Up @@ -1504,6 +1504,9 @@ class Item_func_quote :public Item_str_func
collation.set(args[0]->collation);
ulonglong max_result_length= (ulonglong) args[0]->max_length * 2 +
2 * collation.collation->mbmaxlen;
// NULL argument is returned as a string "NULL" without quotes
if (args[0]->maybe_null)
set_if_bigger(max_result_length, 4 * collation.collation->mbmaxlen);
max_length= (uint32) MY_MIN(max_result_length, MAX_BLOB_WIDTH);
return FALSE;
}
Expand Down

0 comments on commit 81d0185

Please sign in to comment.