Skip to content

Commit 35760c0

Browse files
author
Alexey Botchkov
committed
MDEV-11557 Port MySQL-5.7 JSON tests to MariaDB.
more fixes.
1 parent 1782102 commit 35760c0

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed

mysql-test/suite/json/r/json_no_table.result

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1355,7 +1355,7 @@ json_extract('{"a": 1, "b": [1,2,3]}', '$.b[2]')
13551355
3
13561356
select json_extract('{"a": 1, "b": {"e": "foo", "b": 3}}', '$.a', NULL);
13571357
json_extract('{"a": 1, "b": {"e": "foo", "b": 3}}', '$.a', NULL)
1358-
[1]
1358+
NULL
13591359
# returns a JSON value containing just the string "123"
13601360
SELECT JSON_EXTRACT('{ "a" : "foo", "b" : [ true, { "c" : "123" } ] }',
13611361
'$.b[ 1 ].c');
@@ -1736,7 +1736,7 @@ json_insert('{"c":4}', '$.a', 4)
17361736
{"c":4, "a":4}
17371737
select json_insert('1', '$', 4);
17381738
json_insert('1', '$', 4)
1739-
[1, 4]
1739+
1
17401740
select json_insert('1', '$[0]', 4);
17411741
json_insert('1', '$[0]', 4)
17421742
[1, 4]
@@ -2115,7 +2115,7 @@ json_set('{"c":4}', '$.a', 5)
21152115
{"c":4, "a":5}
21162116
select json_set('1', '$', 4);
21172117
json_set('1', '$', 4)
2118-
[1, 4]
2118+
4
21192119
select json_set('1', '$[0]', 4);
21202120
json_set('1', '$[0]', 4)
21212121
[1, 4]
@@ -2277,7 +2277,7 @@ json_replace('{"c":4}', '$.a', 5)
22772277
{"c":4}
22782278
select json_replace('1', '$', 4);
22792279
json_replace('1', '$', 4)
2280-
1
2280+
4
22812281
select json_replace('1', '$[0]', 4);
22822282
json_replace('1', '$[0]', 4)
22832283
1
@@ -3486,7 +3486,7 @@ Warning 4037 Unexpected end of JSON text in argument 1 to function 'json_extract
34863486
#
34873487
SELECT JSON_SET('1', '$', 100);
34883488
JSON_SET('1', '$', 100)
3489-
[1, 100]
3489+
100
34903490
SELECT JSON_SET('1', '$[0]', 100);
34913491
JSON_SET('1', '$[0]', 100)
34923492
[1, 100]
@@ -3502,7 +3502,7 @@ Warnings:
35023502
Warning 4037 Unexpected end of JSON text in argument 1 to function 'json_set'
35033503
SELECT JSON_SET('[]', '$', 100);
35043504
JSON_SET('[]', '$', 100)
3505-
[, 100]
3505+
100
35063506
SELECT JSON_SET('[]', '$[0]', 100);
35073507
JSON_SET('[]', '$[0]', 100)
35083508
[, 100]
@@ -3518,7 +3518,7 @@ Warnings:
35183518
Warning 4037 Unexpected end of JSON text in argument 1 to function 'json_set'
35193519
SELECT JSON_SET('[1]', '$', 100);
35203520
JSON_SET('[1]', '$', 100)
3521-
[1, 100]
3521+
100
35223522
SELECT JSON_SET('[1]', '$[0]', 100);
35233523
JSON_SET('[1]', '$[0]', 100)
35243524
[100]
@@ -3532,7 +3532,7 @@ Warnings:
35323532
Warning 4037 Unexpected end of JSON text in argument 1 to function 'json_set'
35333533
SELECT JSON_SET('[[1]]', '$', 100);
35343534
JSON_SET('[[1]]', '$', 100)
3535-
[[1], 100]
3535+
100
35363536
SELECT JSON_SET('[[1]]', '$[0]', 100);
35373537
JSON_SET('[[1]]', '$[0]', 100)
35383538
[100]
@@ -3544,7 +3544,7 @@ JSON_SET('[[1]]', '$[0][0][0]', 100)
35443544
[[[1, 100]]]
35453545
SELECT JSON_SET('[[[1]]]', '$', 100);
35463546
JSON_SET('[[[1]]]', '$', 100)
3547-
[[[1]], 100]
3547+
100
35483548
SELECT JSON_SET('[[[1]]]', '$[0]', 100);
35493549
JSON_SET('[[[1]]]', '$[0]', 100)
35503550
[100]
@@ -3556,7 +3556,7 @@ JSON_SET('[[[1]]]', '$[0][0][0]', 100)
35563556
[[[100]]]
35573557
SELECT JSON_REPLACE('1', '$', 100);
35583558
JSON_REPLACE('1', '$', 100)
3559-
1
3559+
100
35603560
SELECT JSON_REPLACE('1', '$[0]', 100);
35613561
JSON_REPLACE('1', '$[0]', 100)
35623562
1
@@ -3572,7 +3572,7 @@ Warnings:
35723572
Warning 4037 Unexpected end of JSON text in argument 1 to function 'json_update'
35733573
SELECT JSON_REPLACE('[]', '$', 100);
35743574
JSON_REPLACE('[]', '$', 100)
3575-
[]
3575+
100
35763576
SELECT JSON_REPLACE('[]', '$[0]', 100);
35773577
JSON_REPLACE('[]', '$[0]', 100)
35783578
[]
@@ -3588,7 +3588,7 @@ Warnings:
35883588
Warning 4037 Unexpected end of JSON text in argument 1 to function 'json_update'
35893589
SELECT JSON_REPLACE('[1]', '$', 100);
35903590
JSON_REPLACE('[1]', '$', 100)
3591-
[1]
3591+
100
35923592
SELECT JSON_REPLACE('[1]', '$[0]', 100);
35933593
JSON_REPLACE('[1]', '$[0]', 100)
35943594
[100]
@@ -3602,7 +3602,7 @@ Warnings:
36023602
Warning 4037 Unexpected end of JSON text in argument 1 to function 'json_update'
36033603
SELECT JSON_REPLACE('[[1]]', '$', 100);
36043604
JSON_REPLACE('[[1]]', '$', 100)
3605-
[[1]]
3605+
100
36063606
SELECT JSON_REPLACE('[[1]]', '$[0]', 100);
36073607
JSON_REPLACE('[[1]]', '$[0]', 100)
36083608
[100]
@@ -3614,7 +3614,7 @@ JSON_REPLACE('[[1]]', '$[0][0][0]', 100)
36143614
[[1]]
36153615
SELECT JSON_REPLACE('[[[1]]]', '$', 100);
36163616
JSON_REPLACE('[[[1]]]', '$', 100)
3617-
[[[1]]]
3617+
100
36183618
SELECT JSON_REPLACE('[[[1]]]', '$[0]', 100);
36193619
JSON_REPLACE('[[[1]]]', '$[0]', 100)
36203620
[100]

sql/item_jsonfunc.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,9 @@ String *Item_func_json_extract::val_str(String *str)
605605
}
606606
c_path->parsed= c_path->constant;
607607
}
608+
609+
if (args[n_arg]->null_value)
610+
goto return_null;
608611
}
609612

610613
possible_multiple_values= arg_count > 2 ||
@@ -666,7 +669,6 @@ String *Item_func_json_extract::val_str(String *str)
666669
error:
667670
report_json_error(js, &je, 0);
668671
return_null:
669-
/* TODO: launch error messages. */
670672
null_value= 1;
671673
return 0;
672674
}
@@ -1958,6 +1960,9 @@ String *Item_func_json_insert::val_str(String *str)
19581960
json_scan_start(&je, js->charset(),(const uchar *) js->ptr(),
19591961
(const uchar *) js->ptr() + js->length());
19601962

1963+
if (c_path->p.last_step < c_path->p.steps)
1964+
goto v_found;
1965+
19611966
c_path->cur_step= c_path->p.steps;
19621967

19631968
if (c_path->p.last_step >= c_path->p.steps &&
@@ -2572,7 +2577,6 @@ String *Item_func_json_search::val_str(String *str)
25722577
js_error:
25732578
report_json_error(js, &je, 0);
25742579
null_return:
2575-
/* TODO: launch error messages. */
25762580
null_value= 1;
25772581
return 0;
25782582
}

0 commit comments

Comments
 (0)