diff options
author | Sergei Krivonos <sergeikrivonos@gmail.com> | 2021-11-14 06:11:12 +0200 |
---|---|---|
committer | Sergei Krivonos <sergeikrivonos@gmail.com> | 2021-11-24 13:01:18 +0200 |
commit | 691f7e165a4cd1b645a6f8960effc463f4e9b94c (patch) | |
tree | 64c6a5f8417cdb8d68e87af7b636d20f3ac219d3 | |
parent | 917b4210124a0241689a699bd532be9ba6628f0f (diff) | |
download | mariadb-git-691f7e165a4cd1b645a6f8960effc463f4e9b94c.tar.gz |
MDEV-27036: allow Json_writer_[array|object] from Json_writer
-rw-r--r-- | sql/my_json_writer.h | 38 |
1 files changed, 25 insertions, 13 deletions
diff --git a/sql/my_json_writer.h b/sql/my_json_writer.h index 07ab433abda..619eafd9bc6 100644 --- a/sql/my_json_writer.h +++ b/sql/my_json_writer.h @@ -372,15 +372,21 @@ protected: bool closed; public: - explicit Json_writer_struct(THD *thd, bool expect_named_children) + explicit Json_writer_struct(Json_writer *writer) + : my_writer(writer) { - my_writer= thd->opt_trace.get_current_json(); context.init(my_writer); closed= false; #ifdef ENABLED_JSON_WRITER_CONSISTENCY_CHECKS named_items_expectation.push_back(expect_named_children); #endif } + explicit Json_writer_struct(THD *thd) + : Json_writer_struct(thd->opt_trace.get_current_json()) + { + } + +public: virtual ~Json_writer_struct() { @@ -420,8 +426,8 @@ private: my_writer->add_member(name); } public: - explicit Json_writer_object(THD* thd, const char *str= nullptr) - : Json_writer_struct(thd, true) + explicit Json_writer_object(Json_writer* writer, const char *str= nullptr) + : Json_writer_struct(writer) { #ifdef ENABLED_JSON_WRITER_CONSISTENCY_CHECKS DBUG_ASSERT(named_item_expected()); @@ -434,6 +440,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) @@ -593,25 +604,25 @@ public: class Json_writer_array : public Json_writer_struct { public: - Json_writer_array(THD *thd) - : Json_writer_struct(thd, false) + explicit Json_writer_array(Json_writer *writer, const char *str= nullptr) + : Json_writer_struct(writer) { #ifdef ENABLED_JSON_WRITER_CONSISTENCY_CHECKS DBUG_ASSERT(!named_item_expected()); #endif 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, false) + explicit Json_writer_array(THD *thd, const char *str= nullptr) + : Json_writer_array(thd->opt_trace.get_current_json(), str) { -#ifdef ENABLED_JSON_WRITER_CONSISTENCY_CHECKS - DBUG_ASSERT(named_item_expected()); -#endif - if (unlikely(my_writer)) - my_writer->add_member(str).start_array(); } + ~Json_writer_array() { if (unlikely(my_writer && !closed)) @@ -620,6 +631,7 @@ public: closed= TRUE; } } + void end() { DBUG_ASSERT(!closed); |