Skip to content

Commit a8227a1

Browse files
committed
MDEV-16814 CREATE TABLE SELECT JSON_QUOTE(multibyte_charset_expr) makes a field of a wrong length
1 parent 45ab00f commit a8227a1

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

mysql-test/r/func_json.result

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ json_quote('foo')
297297
show create table t1;
298298
Table Create Table
299299
t1 CREATE TABLE `t1` (
300-
`json_quote('foo')` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL
300+
`json_quote('foo')` varchar(38) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL
301301
) ENGINE=MyISAM DEFAULT CHARSET=latin1
302302
drop table t1;
303303
select json_merge('string');
@@ -747,3 +747,16 @@ INSERT INTO t1 VALUES ('foo'),('bar');
747747
SELECT * FROM t1 WHERE c IN (JSON_EXTRACT('{"a":"b"}', '$.*'));
748748
c
749749
DROP TABLE t1;
750+
#
751+
# MDEV-16814 CREATE TABLE SELECT JSON_QUOTE(multibyte_charset_expr) makes a field of a wrong length
752+
#
753+
CREATE TABLE t1 AS SELECT
754+
JSON_QUOTE(_latin1'foo') AS c1,
755+
JSON_QUOTE(_utf8'foo') AS c2;
756+
SHOW CREATE TABLE t1;
757+
Table Create Table
758+
t1 CREATE TABLE `t1` (
759+
`c1` varchar(38) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL,
760+
`c2` varchar(38) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL
761+
) ENGINE=MyISAM DEFAULT CHARSET=latin1
762+
DROP TABLE t1;

mysql-test/t/func_json.test

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,3 +413,12 @@ INSERT INTO t1 VALUES ('foo'),('bar');
413413
SELECT * FROM t1 WHERE c IN (JSON_EXTRACT('{"a":"b"}', '$.*'));
414414
DROP TABLE t1;
415415

416+
--echo #
417+
--echo # MDEV-16814 CREATE TABLE SELECT JSON_QUOTE(multibyte_charset_expr) makes a field of a wrong length
418+
--echo #
419+
420+
CREATE TABLE t1 AS SELECT
421+
JSON_QUOTE(_latin1'foo') AS c1,
422+
JSON_QUOTE(_utf8'foo') AS c2;
423+
SHOW CREATE TABLE t1;
424+
DROP TABLE t1;

sql/item_jsonfunc.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ bool Item_func_json_quote::fix_length_and_dec()
575575
Odd but realistic worst case is when all characters
576576
of the argument turn into '\uXXXX\uXXXX', which is 12.
577577
*/
578-
max_length= args[0]->max_length * 12 + 2;
578+
fix_char_length_ulonglong((ulonglong) args[0]->max_char_length() * 12 + 2);
579579
return FALSE;
580580
}
581581

0 commit comments

Comments
 (0)