Debian Codegraph @

mysql-test/suite/json/inc/json_group_concat.inc

raw
1 --echo # ----------------------------------------------------------------------
2 --echo # Test of aggregate function GROUP_CONCAT
3 --echo # ----------------------------------------------------------------------
4 create table t2(j json);
5 insert into t2 values (json_array(ST_GeomFromText('LineString(0 0, 1 1, 2 2)')));
6 select group_concat(j order by j) from t2;
7 drop table t2;
8
9 # MySQL and ECMA strings have different sets of printable control
10 # character conventions. So make sure we get the desired test
11 # characters in by inserting them one by one and checking that we insert
12 # a single character, which we can test JSON_QUOTE on:
13
14 create table t (c varchar(20)) charset utf8mb4;
15 insert into t values ('\\');
16 select char_length(c) from t;
17 insert into t values (X'0C'); # formfeed \f
18 select sum(char_length(c)) from t;
19 insert into t values ('"');
20 select sum(char_length(c)) from t;
21 insert into t values ('\a');
22 select sum(char_length(c)) from t;
23 insert into t values ('\b');
24 select sum(char_length(c)) from t;
25 insert into t values ('\t');
26 select sum(char_length(c)) from t;
27 insert into t values ('\n');
28 select sum(char_length(c)) from t;
29 insert into t values ('\r');
30 select sum(char_length(c)) from t;
31 insert into t values (X'10'); # needs \u escape
32 select sum(char_length(c)) from t;
33
34 --echo # '\b' and X'10' order equal in the default collation, so order on
35 --echo # hex(c) as a tie-breaker to get stable results.
36 select group_concat(c order by c, hex(c)) from t;
37 select char_length(group_concat(c)) from t;
38 select json_quote(group_concat(c order by c, hex(c))) from t;
39 select char_length(json_quote(group_concat(c))) from t;
40
41 select convert(group_concat(c) using utf8mb4) =
42 json_unquote(group_concat(c)) as should_be_equal from t;
43
44 delete from t;
45 alter table t add column (j json);
46 insert into t values (NULL, NULL);
47
48 select json_quote(c), json_quote(j) from t;
49 select json_unquote(c), json_unquote(j) from t;
50
51 drop table t;