summaryrefslogtreecommitdiff
path: root/sql/my_json_writer.h
diff options
context:
space:
mode:
authorMarko Mäkelä <marko.makela@mariadb.com>2021-11-25 08:08:42 +0200
committerMarko Mäkelä <marko.makela@mariadb.com>2021-11-25 08:08:42 +0200
commit3cfbfa58de20057c07ddcc066b6eb4956f77c9e1 (patch)
tree9778934aaed011c97a5baa1548a10732475f6389 /sql/my_json_writer.h
parentde7db5517de11a58d57d2a41d0bc6f38b6f92dd8 (diff)
parentca2695392411adc7f1d19f85d464213128e4f285 (diff)
downloadmariadb-git-3cfbfa58de20057c07ddcc066b6eb4956f77c9e1.tar.gz
Merge 10.5 into 10.6
Diffstat (limited to 'sql/my_json_writer.h')
-rw-r--r--sql/my_json_writer.h67
1 files changed, 39 insertions, 28 deletions
diff --git a/sql/my_json_writer.h b/sql/my_json_writer.h
index e2d60df4bf5..089abd0ad48 100644
--- a/sql/my_json_writer.h
+++ b/sql/my_json_writer.h
@@ -19,6 +19,9 @@
#include "my_base.h"
#if !defined(NDEBUG) || defined(JSON_WRITER_UNIT_TEST) || defined ENABLED_JSON_WRITER_CONSISTENCY_CHECKS
+#include <set>
+#include <stack>
+#include <string>
#include <vector>
#endif
@@ -32,6 +35,8 @@ constexpr uint FAKE_SELECT_LEX_ID= UINT_MAX;
#define VALIDITY_ASSERT(x) DBUG_ASSERT(x)
#endif
+#include <type_traits>
+
class Opt_trace_stmt;
class Opt_trace_context;
class Json_writer;
@@ -372,16 +377,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()
{
@@ -421,8 +431,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());
@@ -435,6 +445,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)
@@ -452,17 +467,22 @@ public:
}
return *this;
}
+
Json_writer_object& add(const char *name, ulonglong value)
{
DBUG_ASSERT(!closed);
if (my_writer)
{
add_member(name);
- context.add_ll(static_cast<longlong>(value));
+ my_writer->add_ull(value);
}
return *this;
}
- Json_writer_object& add(const char *name, longlong value)
+
+ template<class IntT,
+ typename= typename ::std::enable_if<std::is_integral<IntT>::value>::type
+ >
+ Json_writer_object& add(const char *name, IntT value)
{
DBUG_ASSERT(!closed);
if (my_writer)
@@ -472,6 +492,7 @@ public:
}
return *this;
}
+
Json_writer_object& add(const char *name, double value)
{
DBUG_ASSERT(!closed);
@@ -482,18 +503,7 @@ public:
}
return *this;
}
- #ifndef _WIN64
- Json_writer_object& add(const char *name, size_t value)
- {
- DBUG_ASSERT(!closed);
- if (my_writer)
- {
- add_member(name);
- context.add_ll(static_cast<longlong>(value));
- }
- return *this;
- }
- #endif
+
Json_writer_object& add(const char *name, const char *value)
{
DBUG_ASSERT(!closed);
@@ -594,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))
@@ -621,6 +631,7 @@ public:
closed= TRUE;
}
}
+
void end()
{
DBUG_ASSERT(!closed);