Skip to content

Commit 8101af6

Browse files
committed
MDEV-27036: allow Json_writer_[array|object] from Json_writer
1 parent 70e788b commit 8101af6

File tree

1 file changed

+31
-10
lines changed

1 file changed

+31
-10
lines changed

sql/my_json_writer.h

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -367,14 +367,24 @@ class Json_writer_struct
367367
*/
368368
bool closed;
369369

370-
public:
371-
explicit Json_writer_struct(THD *thd)
370+
explicit Json_writer_struct(Json_writer *writer)
371+
: my_writer(writer)
372372
{
373-
my_writer= thd->opt_trace.get_current_json();
374373
context.init(my_writer);
375374
closed= false;
376375
}
377-
bool trace_started()
376+
explicit Json_writer_struct(THD *thd)
377+
: Json_writer_struct(thd->opt_trace.get_current_json())
378+
{
379+
}
380+
381+
public:
382+
383+
virtual ~Json_writer_struct()
384+
{
385+
}
386+
387+
bool trace_started() const
378388
{
379389
return my_writer != 0;
380390
}
@@ -397,8 +407,8 @@ class Json_writer_object : public Json_writer_struct
397407
my_writer->add_member(name);
398408
}
399409
public:
400-
explicit Json_writer_object(THD* thd, const char *str= nullptr)
401-
: Json_writer_struct(thd)
410+
explicit Json_writer_object(Json_writer* writer, const char *str= nullptr)
411+
: Json_writer_struct(writer)
402412
{
403413
if (unlikely(my_writer))
404414
{
@@ -408,6 +418,11 @@ class Json_writer_object : public Json_writer_struct
408418
}
409419
}
410420

421+
explicit Json_writer_object(THD* thd, const char *str= nullptr)
422+
: Json_writer_object(thd->opt_trace.get_current_json(), str)
423+
{
424+
}
425+
411426
~Json_writer_object()
412427
{
413428
if (my_writer && !closed)
@@ -567,17 +582,22 @@ class Json_writer_object : public Json_writer_struct
567582
class Json_writer_array : public Json_writer_struct
568583
{
569584
public:
570-
Json_writer_array(THD *thd): Json_writer_struct(thd)
585+
explicit Json_writer_array(Json_writer *writer, const char *str= nullptr)
586+
: Json_writer_struct(writer)
571587
{
572588
if (unlikely(my_writer))
589+
{
590+
if (str)
591+
my_writer->add_member(str);
573592
my_writer->start_array();
593+
}
574594
}
575595

576-
Json_writer_array(THD *thd, const char *str) : Json_writer_struct(thd)
596+
explicit Json_writer_array(THD *thd, const char *str= nullptr)
597+
: Json_writer_array(thd->opt_trace.get_current_json(), str)
577598
{
578-
if (unlikely(my_writer))
579-
my_writer->add_member(str).start_array();
580599
}
600+
581601
~Json_writer_array()
582602
{
583603
if (unlikely(my_writer && !closed))
@@ -586,6 +606,7 @@ class Json_writer_array : public Json_writer_struct
586606
closed= TRUE;
587607
}
588608
}
609+
589610
void end()
590611
{
591612
DBUG_ASSERT(!closed);

0 commit comments

Comments
 (0)