Commit cf8e78a4 authored by Sergei Krivonos's avatar Sergei Krivonos

Implemented Json_writer_array & Json_writer_object subitems name presence control

parent df383043
......@@ -10,8 +10,11 @@
.ninja_*
*.mri
*.mri.tpl
/.cproject
/.project
.gdb_history
.vs/
/.settings/
errmsg.sys
typescript
_CPack_Packages
......
......@@ -260,6 +260,8 @@ void Json_writer::add_str(const String &str)
add_str(str.ptr(), str.length());
}
thread_local std::vector<bool> Json_writer_struct::named_items_expectation;
Json_writer_temp_disable::Json_writer_temp_disable(THD *thd_arg)
{
thd= thd_arg;
......
......@@ -15,8 +15,12 @@
#ifndef JSON_WRITER_INCLUDED
#define JSON_WRITER_INCLUDED
#include "my_base.h"
#include "sql_select.h"
#include <vector>
class Opt_trace_stmt;
class Opt_trace_context;
class Json_writer;
......@@ -308,6 +312,7 @@ class Json_value_helper
/* A common base for Json_writer_object and Json_writer_array */
class Json_writer_struct
{
static thread_local std::vector<bool> named_items_expectation;
protected:
Json_writer* my_writer;
Json_value_helper context;
......@@ -317,16 +322,29 @@ class Json_writer_struct
bool closed;
public:
explicit Json_writer_struct(THD *thd)
explicit Json_writer_struct(THD *thd, bool expect_named_children)
{
my_writer= thd->opt_trace.get_current_json();
context.init(my_writer);
closed= false;
named_items_expectation.push_back(expect_named_children);
}
virtual ~Json_writer_struct()
{
named_items_expectation.pop_back();
}
bool trace_started()
bool trace_started() const
{
return my_writer != 0;
}
bool named_item_expected() const
{
return named_items_expectation.size() > 1
&& *(named_items_expectation.rbegin() + 1);
}
};
......@@ -347,15 +365,17 @@ class Json_writer_object : public Json_writer_struct
}
public:
explicit Json_writer_object(THD *thd)
: Json_writer_struct(thd)
: Json_writer_struct(thd, true)
{
DBUG_ASSERT(!named_item_expected());
if (unlikely(my_writer))
my_writer->start_object();
}
explicit Json_writer_object(THD* thd, const char *str)
: Json_writer_struct(thd)
: Json_writer_struct(thd, true)
{
DBUG_ASSERT(named_item_expected());
if (unlikely(my_writer))
my_writer->add_member(str).start_object();
}
......@@ -519,14 +539,18 @@ class Json_writer_object : public Json_writer_struct
class Json_writer_array : public Json_writer_struct
{
public:
Json_writer_array(THD *thd): Json_writer_struct(thd)
Json_writer_array(THD *thd)
: Json_writer_struct(thd, false)
{
DBUG_ASSERT(!named_item_expected());
if (unlikely(my_writer))
my_writer->start_array();
}
Json_writer_array(THD *thd, const char *str) : Json_writer_struct(thd)
Json_writer_array(THD *thd, const char *str)
: Json_writer_struct(thd, false)
{
DBUG_ASSERT(named_item_expected());
if (unlikely(my_writer))
my_writer->add_member(str).start_array();
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment