summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergei Krivonos <sergeikrivonos@gmail.com>2021-11-14 06:11:12 +0200
committerSergei Krivonos <sergeikrivonos@gmail.com>2021-11-19 01:55:23 +0200
commit8101af68fac5121cc2c44583c77c12f4f7318599 (patch)
treebc2cf5e95be79292e971538d0780d9876cb22351
parent70e788b1e588106f332b88f435e588de3b103e04 (diff)
downloadmariadb-git-8101af68fac5121cc2c44583c77c12f4f7318599.tar.gz
MDEV-27036: allow Json_writer_[array|object] from Json_writer
-rw-r--r--sql/my_json_writer.h41
1 files changed, 31 insertions, 10 deletions
diff --git a/sql/my_json_writer.h b/sql/my_json_writer.h
index 7d209501a87..0bd1e550439 100644
--- a/sql/my_json_writer.h
+++ b/sql/my_json_writer.h
@@ -367,14 +367,24 @@ protected:
*/
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 @@ private:
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 @@ public:
}
}
+ 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 @@ public:
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 @@ public:
closed= TRUE;
}
}
+
void end()
{
DBUG_ASSERT(!closed);