@@ -367,14 +367,24 @@ class Json_writer_struct
367
367
*/
368
368
bool closed;
369
369
370
- public:
371
- explicit Json_writer_struct (THD *thd )
370
+ explicit Json_writer_struct (Json_writer *writer)
371
+ : my_writer(writer )
372
372
{
373
- my_writer= thd->opt_trace .get_current_json ();
374
373
context.init (my_writer);
375
374
closed= false ;
376
375
}
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
378
388
{
379
389
return my_writer != 0 ;
380
390
}
@@ -397,8 +407,8 @@ class Json_writer_object : public Json_writer_struct
397
407
my_writer->add_member (name);
398
408
}
399
409
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 )
402
412
{
403
413
if (unlikely (my_writer))
404
414
{
@@ -408,6 +418,11 @@ class Json_writer_object : public Json_writer_struct
408
418
}
409
419
}
410
420
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
+
411
426
~Json_writer_object ()
412
427
{
413
428
if (my_writer && !closed)
@@ -567,17 +582,22 @@ class Json_writer_object : public Json_writer_struct
567
582
class Json_writer_array : public Json_writer_struct
568
583
{
569
584
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)
571
587
{
572
588
if (unlikely (my_writer))
589
+ {
590
+ if (str)
591
+ my_writer->add_member (str);
573
592
my_writer->start_array ();
593
+ }
574
594
}
575
595
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)
577
598
{
578
- if (unlikely (my_writer))
579
- my_writer->add_member (str).start_array ();
580
599
}
600
+
581
601
~Json_writer_array ()
582
602
{
583
603
if (unlikely (my_writer && !closed))
@@ -586,6 +606,7 @@ class Json_writer_array : public Json_writer_struct
586
606
closed= TRUE ;
587
607
}
588
608
}
609
+
589
610
void end ()
590
611
{
591
612
DBUG_ASSERT (!closed);
0 commit comments