MDEV-11557 Port MySQL-5.7 JSON tests to MariaDB.

more fixes.
This commit is contained in:
Alexey Botchkov 2017-01-25 00:13:15 +04:00
commit 35760c0000
2 changed files with 20 additions and 16 deletions

View file

@ -1355,7 +1355,7 @@ json_extract('{"a": 1, "b": [1,2,3]}', '$.b[2]')
3
select json_extract('{"a": 1, "b": {"e": "foo", "b": 3}}', '$.a', NULL);
json_extract('{"a": 1, "b": {"e": "foo", "b": 3}}', '$.a', NULL)
[1]
NULL
# returns a JSON value containing just the string "123"
SELECT JSON_EXTRACT('{ "a" : "foo", "b" : [ true, { "c" : "123" } ] }',
'$.b[ 1 ].c');
@ -1736,7 +1736,7 @@ json_insert('{"c":4}', '$.a', 4)
{"c":4, "a":4}
select json_insert('1', '$', 4);
json_insert('1', '$', 4)
[1, 4]
1
select json_insert('1', '$[0]', 4);
json_insert('1', '$[0]', 4)
[1, 4]
@ -2115,7 +2115,7 @@ json_set('{"c":4}', '$.a', 5)
{"c":4, "a":5}
select json_set('1', '$', 4);
json_set('1', '$', 4)
[1, 4]
4
select json_set('1', '$[0]', 4);
json_set('1', '$[0]', 4)
[1, 4]
@ -2277,7 +2277,7 @@ json_replace('{"c":4}', '$.a', 5)
{"c":4}
select json_replace('1', '$', 4);
json_replace('1', '$', 4)
1
4
select json_replace('1', '$[0]', 4);
json_replace('1', '$[0]', 4)
1
@ -3486,7 +3486,7 @@ Warning 4037 Unexpected end of JSON text in argument 1 to function 'json_extract
#
SELECT JSON_SET('1', '$', 100);
JSON_SET('1', '$', 100)
[1, 100]
100
SELECT JSON_SET('1', '$[0]', 100);
JSON_SET('1', '$[0]', 100)
[1, 100]
@ -3502,7 +3502,7 @@ Warnings:
Warning 4037 Unexpected end of JSON text in argument 1 to function 'json_set'
SELECT JSON_SET('[]', '$', 100);
JSON_SET('[]', '$', 100)
[, 100]
100
SELECT JSON_SET('[]', '$[0]', 100);
JSON_SET('[]', '$[0]', 100)
[, 100]
@ -3518,7 +3518,7 @@ Warnings:
Warning 4037 Unexpected end of JSON text in argument 1 to function 'json_set'
SELECT JSON_SET('[1]', '$', 100);
JSON_SET('[1]', '$', 100)
[1, 100]
100
SELECT JSON_SET('[1]', '$[0]', 100);
JSON_SET('[1]', '$[0]', 100)
[100]
@ -3532,7 +3532,7 @@ Warnings:
Warning 4037 Unexpected end of JSON text in argument 1 to function 'json_set'
SELECT JSON_SET('[[1]]', '$', 100);
JSON_SET('[[1]]', '$', 100)
[[1], 100]
100
SELECT JSON_SET('[[1]]', '$[0]', 100);
JSON_SET('[[1]]', '$[0]', 100)
[100]
@ -3544,7 +3544,7 @@ JSON_SET('[[1]]', '$[0][0][0]', 100)
[[[1, 100]]]
SELECT JSON_SET('[[[1]]]', '$', 100);
JSON_SET('[[[1]]]', '$', 100)
[[[1]], 100]
100
SELECT JSON_SET('[[[1]]]', '$[0]', 100);
JSON_SET('[[[1]]]', '$[0]', 100)
[100]
@ -3556,7 +3556,7 @@ JSON_SET('[[[1]]]', '$[0][0][0]', 100)
[[[100]]]
SELECT JSON_REPLACE('1', '$', 100);
JSON_REPLACE('1', '$', 100)
1
100
SELECT JSON_REPLACE('1', '$[0]', 100);
JSON_REPLACE('1', '$[0]', 100)
1
@ -3572,7 +3572,7 @@ Warnings:
Warning 4037 Unexpected end of JSON text in argument 1 to function 'json_update'
SELECT JSON_REPLACE('[]', '$', 100);
JSON_REPLACE('[]', '$', 100)
[]
100
SELECT JSON_REPLACE('[]', '$[0]', 100);
JSON_REPLACE('[]', '$[0]', 100)
[]
@ -3588,7 +3588,7 @@ Warnings:
Warning 4037 Unexpected end of JSON text in argument 1 to function 'json_update'
SELECT JSON_REPLACE('[1]', '$', 100);
JSON_REPLACE('[1]', '$', 100)
[1]
100
SELECT JSON_REPLACE('[1]', '$[0]', 100);
JSON_REPLACE('[1]', '$[0]', 100)
[100]
@ -3602,7 +3602,7 @@ Warnings:
Warning 4037 Unexpected end of JSON text in argument 1 to function 'json_update'
SELECT JSON_REPLACE('[[1]]', '$', 100);
JSON_REPLACE('[[1]]', '$', 100)
[[1]]
100
SELECT JSON_REPLACE('[[1]]', '$[0]', 100);
JSON_REPLACE('[[1]]', '$[0]', 100)
[100]
@ -3614,7 +3614,7 @@ JSON_REPLACE('[[1]]', '$[0][0][0]', 100)
[[1]]
SELECT JSON_REPLACE('[[[1]]]', '$', 100);
JSON_REPLACE('[[[1]]]', '$', 100)
[[[1]]]
100
SELECT JSON_REPLACE('[[[1]]]', '$[0]', 100);
JSON_REPLACE('[[[1]]]', '$[0]', 100)
[100]

View file

@ -605,6 +605,9 @@ String *Item_func_json_extract::val_str(String *str)
}
c_path->parsed= c_path->constant;
}
if (args[n_arg]->null_value)
goto return_null;
}
possible_multiple_values= arg_count > 2 ||
@ -666,7 +669,6 @@ String *Item_func_json_extract::val_str(String *str)
error:
report_json_error(js, &je, 0);
return_null:
/* TODO: launch error messages. */
null_value= 1;
return 0;
}
@ -1958,6 +1960,9 @@ String *Item_func_json_insert::val_str(String *str)
json_scan_start(&je, js->charset(),(const uchar *) js->ptr(),
(const uchar *) js->ptr() + js->length());
if (c_path->p.last_step < c_path->p.steps)
goto v_found;
c_path->cur_step= c_path->p.steps;
if (c_path->p.last_step >= c_path->p.steps &&
@ -2572,7 +2577,6 @@ end:
js_error:
report_json_error(js, &je, 0);
null_return:
/* TODO: launch error messages. */
null_value= 1;
return 0;
}