summaryrefslogtreecommitdiff
path: root/sql/item_jsonfunc.cc
diff options
context:
space:
mode:
authorMarko Mäkelä <marko.makela@mariadb.com>2023-01-13 11:22:29 +0200
committerMarko Mäkelä <marko.makela@mariadb.com>2023-01-13 11:22:29 +0200
commit5d5735c181f1300c7b208f865806268b16eec5c6 (patch)
treee18b411c66ad0128689a37af272046d7df8d18a0 /sql/item_jsonfunc.cc
parent820ebcec8651d2478ece554f059a5513f0b2bedf (diff)
parent88c35781cc9f5f3c63de98a8b6e7eb3378d4fae5 (diff)
downloadmariadb-git-5d5735c181f1300c7b208f865806268b16eec5c6.tar.gz
Merge 10.8 into 10.9
Diffstat (limited to 'sql/item_jsonfunc.cc')
-rw-r--r--sql/item_jsonfunc.cc33
1 files changed, 30 insertions, 3 deletions
diff --git a/sql/item_jsonfunc.cc b/sql/item_jsonfunc.cc
index aaee8a99294..2efb8e39439 100644
--- a/sql/item_jsonfunc.cc
+++ b/sql/item_jsonfunc.cc
@@ -285,6 +285,10 @@ static int json_nice(json_engine_t *je, String *nice_js,
static const char *comma= ", ", *colon= "\": ";
uint comma_len, colon_len;
int first_value= 1;
+ int value_size = 0;
+ int curr_state= -1;
+ int64_t value_len= 0;
+ String curr_str{};
nice_js->length(0);
nice_js->set_charset(je->s.cs);
@@ -311,6 +315,7 @@ static int json_nice(json_engine_t *je, String *nice_js,
do
{
+ curr_state= je->state;
switch (je->state)
{
case JST_KEY:
@@ -358,17 +363,23 @@ handle_value:
if (append_simple(nice_js, je->value_begin,
je->value_end - je->value_begin))
goto error;
-
+
+ curr_str.copy((const char *)je->value_begin,
+ je->value_end - je->value_begin, je->s.cs);
+ value_len= je->value_end - je->value_begin;
first_value= 0;
+ if (value_size != -1)
+ value_size++;
}
else
{
if (mode == Item_func_json_format::DETAILED &&
- depth > 0 &&
+ depth > 0 && !(curr_state != JST_KEY) &&
append_tab(nice_js, depth, tab_size))
goto error;
nice_js->append((je->value_type == JSON_VALUE_OBJECT) ? "{" : "[", 1);
first_value= 1;
+ value_size= (je->value_type == JSON_VALUE_OBJECT) ? -1: 0;
depth++;
}
@@ -377,11 +388,27 @@ handle_value:
case JST_OBJ_END:
case JST_ARRAY_END:
depth--;
- if (mode == Item_func_json_format::DETAILED &&
+ if (mode == Item_func_json_format::DETAILED && (value_size > 1 || value_size == -1) &&
append_tab(nice_js, depth, tab_size))
goto error;
+
+ if (mode == Item_func_json_format::DETAILED &&
+ value_size == 1 && je->state != JST_OBJ_END)
+ {
+ for (auto i = 0; i < value_len; i++)
+ {
+ nice_js->chop();
+ }
+ for (auto i = 0; i < (depth + 1) * tab_size + 1; i++)
+ {
+ nice_js->chop();
+ }
+ nice_js->append(curr_str);
+ }
+
nice_js->append((je->state == JST_OBJ_END) ? "}": "]", 1);
first_value= 0;
+ value_size= -1;
break;
default: