summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergei Krivonos <sergei.krivonos@mariadb.com>2021-11-14 06:11:12 +0200
committerSergei Krivonos <sergei.krivonos@mariadb.com>2021-11-14 09:51:07 +0200
commit73f26652952269b7cf9660ad61b0abcbc700e3aa (patch)
tree1e8ee6f420da455e17f13c734d3e44486e948431
parentd270525dfde86bcb92a2327234a0954083e14a94 (diff)
downloadmariadb-git-bb-10.4-MDEV-23766.tar.gz
MDEV-27036: allow Json_writer_[array|object] from Json_writerbb-10.4-MDEV-23766
-rw-r--r--sql/my_json_writer.h34
1 files changed, 25 insertions, 9 deletions
diff --git a/sql/my_json_writer.h b/sql/my_json_writer.h
index 7d209501a87..438167a1325 100644
--- a/sql/my_json_writer.h
+++ b/sql/my_json_writer.h
@@ -367,13 +367,18 @@ 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;
}
+ explicit Json_writer_struct(THD *thd)
+ : Json_writer_struct(thd->opt_trace.get_current_json())
+ {
+ }
+
+public:
bool trace_started()
{
return my_writer != 0;
@@ -397,8 +402,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 +413,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 +577,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 +601,7 @@ public:
closed= TRUE;
}
}
+
void end()
{
DBUG_ASSERT(!closed);