diff options
author | Sergei Krivonos <name@localhost.localdomain> | 2021-10-16 02:35:16 +0300 |
---|---|---|
committer | Sergei Krivonos <name@localhost.localdomain> | 2021-10-16 02:35:16 +0300 |
commit | cf8e78a40170118e2595e35c9c5f43aedeca91a0 (patch) | |
tree | 70c2c3f3c39ef3ef3bb6b9b59aeb1b6e5460c1df | |
parent | df383043427fb22b0735fe31968db860f4cdb7a0 (diff) | |
download | mariadb-git-cf8e78a40170118e2595e35c9c5f43aedeca91a0.tar.gz |
Implemented Json_writer_array & Json_writer_object subitems name presence control
-rw-r--r-- | .gitignore | 3 | ||||
-rw-r--r-- | sql/my_json_writer.cc | 2 | ||||
-rw-r--r-- | sql/my_json_writer.h | 36 |
3 files changed, 35 insertions, 6 deletions
diff --git a/.gitignore b/.gitignore index 5005dbae363..9abb2b075bc 100644 --- a/.gitignore +++ b/.gitignore @@ -10,8 +10,11 @@ .ninja_* *.mri *.mri.tpl +/.cproject +/.project .gdb_history .vs/ +/.settings/ errmsg.sys typescript _CPack_Packages diff --git a/sql/my_json_writer.cc b/sql/my_json_writer.cc index 3234b8f9995..e4033ed0c02 100644 --- a/sql/my_json_writer.cc +++ b/sql/my_json_writer.cc @@ -260,6 +260,8 @@ void Json_writer::add_str(const String &str) add_str(str.ptr(), str.length()); } +thread_local std::vector<bool> Json_writer_struct::named_items_expectation; + Json_writer_temp_disable::Json_writer_temp_disable(THD *thd_arg) { thd= thd_arg; diff --git a/sql/my_json_writer.h b/sql/my_json_writer.h index bc8002de529..f91a7c9ba8c 100644 --- a/sql/my_json_writer.h +++ b/sql/my_json_writer.h @@ -15,8 +15,12 @@ #ifndef JSON_WRITER_INCLUDED #define JSON_WRITER_INCLUDED + #include "my_base.h" #include "sql_select.h" + +#include <vector> + class Opt_trace_stmt; class Opt_trace_context; class Json_writer; @@ -308,6 +312,7 @@ public: /* A common base for Json_writer_object and Json_writer_array */ class Json_writer_struct { + static thread_local std::vector<bool> named_items_expectation; protected: Json_writer* my_writer; Json_value_helper context; @@ -317,16 +322,29 @@ protected: bool closed; public: - explicit Json_writer_struct(THD *thd) + explicit Json_writer_struct(THD *thd, bool expect_named_children) { my_writer= thd->opt_trace.get_current_json(); context.init(my_writer); closed= false; + named_items_expectation.push_back(expect_named_children); + } + + virtual ~Json_writer_struct() + { + named_items_expectation.pop_back(); } - bool trace_started() + + bool trace_started() const { return my_writer != 0; } + + bool named_item_expected() const + { + return named_items_expectation.size() > 1 + && *(named_items_expectation.rbegin() + 1); + } }; @@ -347,15 +365,17 @@ private: } public: explicit Json_writer_object(THD *thd) - : Json_writer_struct(thd) + : Json_writer_struct(thd, true) { + DBUG_ASSERT(!named_item_expected()); if (unlikely(my_writer)) my_writer->start_object(); } explicit Json_writer_object(THD* thd, const char *str) - : Json_writer_struct(thd) + : Json_writer_struct(thd, true) { + DBUG_ASSERT(named_item_expected()); if (unlikely(my_writer)) my_writer->add_member(str).start_object(); } @@ -519,14 +539,18 @@ public: class Json_writer_array : public Json_writer_struct { public: - Json_writer_array(THD *thd): Json_writer_struct(thd) + Json_writer_array(THD *thd) + : Json_writer_struct(thd, false) { + DBUG_ASSERT(!named_item_expected()); if (unlikely(my_writer)) my_writer->start_array(); } - Json_writer_array(THD *thd, const char *str) : Json_writer_struct(thd) + Json_writer_array(THD *thd, const char *str) + : Json_writer_struct(thd, false) { + DBUG_ASSERT(named_item_expected()); if (unlikely(my_writer)) my_writer->add_member(str).start_array(); } |