Commit 8101af68 authored by Sergei Krivonos's avatar Sergei Krivonos

MDEV-27036: allow Json_writer_[array|object] from Json_writer

parent 70e788b1
......@@ -367,14 +367,24 @@ class Json_writer_struct
*/
bool closed;
public:
explicit Json_writer_struct(THD *thd)
explicit Json_writer_struct(Json_writer *writer)
: my_writer(writer)
{
my_writer= thd->opt_trace.get_current_json();
context.init(my_writer);
closed= false;
}
bool trace_started()
explicit Json_writer_struct(THD *thd)
: Json_writer_struct(thd->opt_trace.get_current_json())
{
}
public:
virtual ~Json_writer_struct()
{
}
bool trace_started() const
{
return my_writer != 0;
}
......@@ -397,8 +407,8 @@ class Json_writer_object : public Json_writer_struct
my_writer->add_member(name);
}
public:
explicit Json_writer_object(THD* thd, const char *str= nullptr)
: Json_writer_struct(thd)
explicit Json_writer_object(Json_writer* writer, const char *str= nullptr)
: Json_writer_struct(writer)
{
if (unlikely(my_writer))
{
......@@ -408,6 +418,11 @@ class Json_writer_object : public Json_writer_struct
}
}
explicit Json_writer_object(THD* thd, const char *str= nullptr)
: Json_writer_object(thd->opt_trace.get_current_json(), str)
{
}
~Json_writer_object()
{
if (my_writer && !closed)
......@@ -567,17 +582,22 @@ 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)
explicit Json_writer_array(Json_writer *writer, const char *str= nullptr)
: Json_writer_struct(writer)
{
if (unlikely(my_writer))
{
if (str)
my_writer->add_member(str);
my_writer->start_array();
}
}
Json_writer_array(THD *thd, const char *str) : Json_writer_struct(thd)
explicit Json_writer_array(THD *thd, const char *str= nullptr)
: Json_writer_array(thd->opt_trace.get_current_json(), str)
{
if (unlikely(my_writer))
my_writer->add_member(str).start_array();
}
~Json_writer_array()
{
if (unlikely(my_writer && !closed))
......@@ -586,6 +606,7 @@ class Json_writer_array : public Json_writer_struct
closed= TRUE;
}
}
void end()
{
DBUG_ASSERT(!closed);
......
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