MySQL 9.7.0
Source Code Documentation
json_dom.h
Go to the documentation of this file.
1#ifndef JSON_DOM_INCLUDED
2#define JSON_DOM_INCLUDED
3
4/* Copyright (c) 2015, 2026, Oracle and/or its affiliates.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License, version 2.0,
8 as published by the Free Software Foundation.
9
10 This program is designed to work with certain software (including
11 but not limited to OpenSSL) that is licensed under separate terms,
12 as designated in a particular file or component or in included license
13 documentation. The authors of MySQL hereby grant you an additional
14 permission to link the program and your derivative works with the
15 separately licensed software that they have either included with
16 the program or referenced in the documentation.
17
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License, version 2.0, for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
26
27#include <assert.h>
28#include <stddef.h>
29#include <iterator>
30#include <map>
31#include <memory> // unique_ptr
32#include <new>
33#include <string>
34#include <string_view>
35#include <type_traits> // is_base_of
36#include <unordered_set>
37#include <utility>
38#include <vector>
39
40#include "field_types.h" // enum_field_types
41#include "my_byteorder.h"
42#include "my_inttypes.h"
43#include "my_time.h" // my_time_flags_t
44#include "mysql_time.h" // MYSQL_TIME
45#include "prealloced_array.h" // Prealloced_array
46#include "sql-common/json_binary.h" // json_binary::Value
48#include "sql-common/my_decimal.h" // my_decimal
49#include "sql/malloc_allocator.h" // Malloc_allocator
50
51class Field_json;
52class Json_array;
53class Json_container;
54class Json_dom;
55class Json_object;
56class Json_path;
58class Json_wrapper;
60class String;
61
62struct CHARSET_INFO;
63
66
67using Json_dom_ptr = std::unique_ptr<Json_dom>;
68using Json_array_ptr = std::unique_ptr<Json_array>;
69using Json_object_ptr = std::unique_ptr<Json_object>;
70using ha_checksum = std::uint32_t;
71
72/**
73 @file
74 JSON DOM.
75
76 When a JSON value is retrieved from a column, a prior it exists in
77 a binary form, cf. Json_binary::Value class.
78
79 However, when we need to manipulate the JSON values we mostly convert them
80 from binary form to a structured in-memory from called DOM (from domain
81 object model) which uses a recursive tree representation of the JSON value
82 corresponding closely to a parse tree. This form is more suitable for
83 manipulation.
84
85 The JSON type is mostly represented internally as a Json_wrapper which hides
86 if the representation is a binary or DOM one. This makes is possible to avoid
87 building a DOM unless we really need one.
88
89 The file defines two sets of classes: a) The Json_dom hierarchy and
90 b) Json_wrapper and its companion classes Json_wrapper_object_iterator and
91 Json_object_wrapper. For both sets, arrays are traversed using an operator[].
92*/
93
94/**
95 Json values in MySQL comprises the stand set of JSON values plus a
96 MySQL specific set. A Json _number_ type is subdivided into _int_,
97 _uint_, _double_ and _decimal_.
98
99 MySQL also adds four built-in date/time values: _date_, _time_,
100 _datetime_ and _timestamp_. An additional _opaque_ value can
101 store any other MySQL type.
102
103 The enumeration is common to Json_dom and Json_wrapper.
104
105 The enumeration is also used by Json_wrapper::compare() to
106 determine the ordering when comparing values of different types,
107 so the order in which the values are defined in the enumeration,
108 is significant. The expected order is null < number < string <
109 object < array < boolean < date < time < datetime/timestamp <
110 opaque.
111*/
112enum class enum_json_type {
113 J_NULL,
114 J_DECIMAL,
115 J_INT,
116 J_UINT,
117 J_DOUBLE,
118 J_STRING,
119 J_OBJECT,
120 J_ARRAY,
121 J_BOOLEAN,
122 J_DATE,
123 J_TIME,
126 J_OPAQUE,
127 J_ERROR
128};
129
130/**
131 Allocate a new Json_dom object and return a std::unique_ptr which points to
132 it.
133
134 @param args the arguments to pass to the constructor
135
136 @tparam T the type of Json_dom to create
137 @tparam Args the type of the arguments to pass to the constructor
138
139 @return a pointer to the allocated object
140*/
141template <typename T, typename... Args>
142inline std::unique_ptr<T> create_dom_ptr(Args &&...args) {
143 return std::unique_ptr<T>(new (std::nothrow) T(std::forward<Args>(args)...));
144}
145
146/**
147 JSON DOM abstract base class.
148
149 MySQL representation of in-memory JSON objects used by the JSON type
150 Supports access, deep cloning, and updates. See also Json_wrapper and
151 json_binary::Value.
152 Uses heap for space allocation for now. FIXME.
153
154 Class hierarchy:
155 <code><pre>
156 Json_dom (abstract)
157 Json_scalar (abstract)
158 Json_string
159 Json_number (abstract)
160 Json_decimal
161 Json_int
162 Json_uint
163 Json_double
164 Json_boolean
165 Json_null
166 Json_temporal
167 Json_time
168 Json_date
169 Json_datetime
170 Json_opaque
171 Json_container (abstract)
172 Json_object
173 Json_array
174 </pre></code>
175 At the outset, object and array add/insert/append operations takes
176 a clone unless specified in the method, e.g. add_alias hands the
177 responsibility for the passed in object over to the object.
178*/
179class Json_dom {
180 // so that these classes can call set_parent()
181 friend class Json_object;
182 friend class Json_array;
183
184 private:
185 /**
186 Set the parent dom to which this dom is attached.
187
188 @param[in] parent the parent we're being attached to
189 */
191
192 public:
193 virtual ~Json_dom() = default;
194
195 /**
196 Allocate space on the heap for a Json_dom object.
197
198 @return pointer to the allocated memory, or NULL if memory could
199 not be allocated (in which case my_error() will have been called
200 with the appropriate error message)
201 */
202 void *operator new(size_t size, const std::nothrow_t &) noexcept;
203
204 /**
205 Deallocate the space used by a Json_dom object.
206 */
207 void operator delete(void *ptr) noexcept;
208
209 /**
210 Nothrow delete.
211 */
212 void operator delete(void *ptr, const std::nothrow_t &) noexcept;
213
214 /**
215 Get the parent dom to which this dom is attached.
216
217 @return the parent dom.
218 */
219 Json_container *parent() const { return m_parent; }
220
221 /**
222 @return the type corresponding to the actual Json_dom subclass
223 */
224 virtual enum_json_type json_type() const = 0;
225
226 /**
227 @return true if the object is a subclass of Json_scalar
228 */
229 virtual bool is_scalar() const { return false; }
230
231 /**
232 @return true of the object is a subclass of Json_number
233 */
234 virtual bool is_number() const { return false; }
235
236 /**
237 Compute the depth of a document. This is the value which would be
238 returned by the JSON_DEPTH() system function.
239
240 - for scalar values, empty array and empty object: 1
241 - for non-empty array: 1+ max(depth of array elements)
242 - for non-empty objects: 1+ max(depth of object values)
243
244 For example:
245 "abc", [] and {} have depth 1.
246 ["abc", [3]] and {"a": "abc", "b": [3]} have depth 3.
247
248 @return the depth of the document
249 */
250 virtual uint32 depth() const = 0;
251
252 /**
253 Make a deep clone. The ownership of the returned object is
254 henceforth with the caller.
255
256 @return a cloned Json_dom object.
257 */
258 virtual Json_dom_ptr clone() const = 0;
259
260 /**
261 Parse Json text to DOM (using rapidjson). The text must be valid JSON.
262 The results when supplying an invalid document is undefined.
263 The ownership of the returned object is henceforth with the caller.
264
265 If the parsing fails because of a syntax error, the errmsg and
266 offset arguments will be given values that point to a detailed
267 error message and where the syntax error was located. The caller
268 will have to generate an error message with my_error() in this
269 case.
270
271 If the parsing fails because of some other error (such as out of
272 memory), errmsg will point to a location that holds the value
273 NULL. In this case, parse() will already have called my_error(),
274 and the caller doesn't need to generate an error message.
275
276 @param[in] text the JSON text
277 @param[in] length the length of the text
278 @param[in] error_handler Pointer to a function that should handle
279 reporting of parsing error.
280 @param[in] depth_handler Pointer to a function that should handle error
281 occurred when depth is exceeded.
282
283
284 @result the built DOM if JSON text was parseable, else NULL
285 */
286 static Json_dom_ptr parse(const char *text, size_t length,
287 const JsonParseErrorHandler &error_handler,
288 const JsonErrorHandler &depth_handler);
289
290 /**
291 Construct a DOM object based on a binary JSON value. The ownership
292 of the returned object is henceforth with the caller.
293
294 @param v the binary value to parse
295 @return a DOM representation of the binary value, or NULL on error
296 */
297 static Json_dom_ptr parse(const json_binary::Value &v);
298
299 /**
300 Get the path location of this dom, measured from the outermost
301 document it nests inside.
302 */
303 Json_path get_location() const;
304
305 /**
306 Finds all of the json sub-documents which match the path expression.
307 Adds a vector element for each match.
308
309 See the header comment for Json_wrapper.seek() for a discussion
310 of complexities involving path expression with more than one
311 ellipsis (**) token.
312
313 @param[in] path the (possibly wildcarded) address of the sub-documents
314 @param[in] legs the number of legs to use from @a path
315 @param[out] hits one element per match
316 @param[in] auto_wrap
317 if true, match a tailing [0] to scalar at that position.
318 @param[in] only_need_one True if we can stop after finding one match
319 @return false on success, true on error
320 */
321 bool seek(const Json_seekable_path &path, size_t legs, Json_dom_vector *hits,
322 bool auto_wrap, bool only_need_one);
323
324 private:
325 /** Parent pointer */
327};
328
329/**
330 Abstract base class of all JSON container types (Json_object and Json_array).
331*/
332class Json_container : public Json_dom {
333 public:
334 /**
335 Replace oldv contained inside this container array or object) with newv. If
336 this container does not contain oldv, calling the method is a no-op.
337
338 @param[in] oldv the value to be replaced
339 @param[in] newv the new value to put in the container
340 */
341 virtual void replace_dom_in_container(const Json_dom *oldv,
342 Json_dom_ptr newv) = 0;
343};
344
345/**
346 A comparator that is used for ordering keys in a Json_object. It
347 orders the keys on length, and lexicographically if the keys have
348 the same length. The ordering is ascending. This ordering was chosen
349 for speed of look-up. See usage in Json_object_map.
350*/
352 // is_transparent must be defined in order to make std::map::find() accept
353 // keys that are of a different type than the key_type of the map. In
354 // particular, this is needed to make it possible to call find() with
355 // a std::string_view argument or anything implicitly convertible to
356 // std::string_view.
357 using is_transparent = void;
358
359 bool operator()(std::string_view key1, std::string_view key2) const;
360};
361
362/**
363 A type used to hold JSON object elements in a map, see the
364 Json_object class.
365*/
369
370/**
371 Represents a JSON container value of type "object" (ECMA), type
372 J_OBJECT here.
373*/
374class Json_object final : public Json_container {
375 private:
376 /**
377 Map to hold the object elements.
378 */
380
381 public:
382 Json_object();
384
385 /**
386 Insert a clone of the value into the object. If the key already
387 exists in the object, the existing value is replaced ("last value
388 wins").
389
390 @param[in] key the JSON element key of to be added
391 @param[in] value a JSON value: the element key's value
392 @retval false on success
393 @retval true on failure
394 */
395 bool add_clone(std::string_view key, const Json_dom *value) {
396 return value == nullptr || add_alias(key, value->clone());
397 }
398
399 /**
400 Insert the value into the object. If the key already exists in the
401 object, the existing value is replaced ("last value wins").
402
403 Ownership of the value is effectively transferred to the
404 object and the value will be deallocated by the object so only add
405 values that can be deallocated safely (no stack variables please!)
406
407 New code should prefer #add_alias(std::string_view, Json_dom_ptr)
408 to this function, because that makes the transfer of ownership
409 more explicit. This function might be removed in the future.
410
411 @param[in] key the JSON key of to be added
412 @param[in] value a JSON value: the key's value
413 @retval false on success
414 @retval true on failure
415 */
416 bool add_alias(std::string_view key, Json_dom *value) {
418 }
419
420 /**
421 Insert the value into the object. If the key already exists in the
422 object, the existing value is replaced ("last value wins").
423
424 The ownership of the value is transferred to the object.
425
426 @param[in] key the key of the value to be added
427 @param[in] value the value to add
428 @return false on success, true on failure
429 */
430 bool add_alias(std::string_view key, Json_dom_ptr value);
431
432 /**
433 Transfer all of the key/value pairs in the other object into this
434 object. The other object is deleted. If this object and the other
435 object share a key, then the two values of the key are merged.
436
437 @param [in] other a pointer to the object which will be consumed
438 @retval false on success
439 @retval true on failure
440 */
441 bool consume(Json_object_ptr other);
442
443 /**
444 Return the value at key. The value is not cloned, so make
445 one if you need it. Do not delete the returned value, please!
446 If the key is not present, return a null pointer.
447
448 @param[in] key the key of the element whose value we want
449 @return the value associated with the key, or NULL if the key is not found
450 */
451 Json_dom *get(std::string_view key) const;
452
453 /**
454 Remove the child element addressed by key. The removed child is deleted.
455
456 @param key the key of the element to remove
457 @retval true if an element was removed
458 @retval false if there was no element with that key
459 */
460 bool remove(std::string_view key);
461
462 /**
463 @return The number of elements in the JSON object.
464 */
465 size_t cardinality() const;
466
467 uint32 depth() const override;
468
469 Json_dom_ptr clone() const override;
470
471 void replace_dom_in_container(const Json_dom *oldv,
472 Json_dom_ptr newv) override;
473
474 /**
475 Remove all elements in the object.
476 */
477 void clear() { m_map.clear(); }
478
479 /**
480 Constant iterator over the elements in the JSON object. Each
481 element is represented as a std::pair where first is a std::string
482 that represents the key name, and second is a pointer to a
483 Json_dom that represents the value.
484 */
485 typedef Json_object_map::const_iterator const_iterator;
486
487 /// Returns a const_iterator that refers to the first element.
488 const_iterator begin() const { return m_map.begin(); }
489
490 /// Returns a const_iterator that refers past the last element.
491 const_iterator end() const { return m_map.end(); }
492
493 /**
494 Implementation of the MergePatch function specified in RFC 7396:
495
496 define MergePatch(Target, Patch):
497 if Patch is an Object:
498 if Target is not an Object:
499 Target = {} # Ignore the contents and set it to an empty Object
500 for each Key/Value pair in Patch:
501 if Value is null:
502 if Key exists in Target:
503 remove the Key/Value pair from Target
504 else:
505 Target[Key] = MergePatch(Target[Key], Value)
506 return Target
507 else:
508 return Patch
509
510 @param patch the object that describes the patch
511 @retval false on success
512 @retval true on memory allocation error
513 */
514 bool merge_patch(Json_object_ptr patch);
515};
516
517/**
518 Represents a JSON array container, i.e. type J_ARRAY here.
519*/
520class Json_array final : public Json_container {
521 private:
522 /// Holds the array values.
523 std::vector<Json_dom_ptr, Malloc_allocator<Json_dom_ptr>> m_v;
524
525 public:
526 Json_array();
527
529
530 /**
531 Append a clone of the value to the end of the array.
532 @param[in] value a JSON value to be appended
533 @retval false on success
534 @retval true on failure
535 */
537 return insert_clone(size(), value);
538 }
539
540 /**
541 Append the value to the end of the array.
542
543 Ownership of the value is effectively transferred to the array and
544 the value will be deallocated by the array so only append values
545 that can be deallocated safely (no stack variables please!)
546
547 New code should prefer #append_alias(Json_dom_ptr) to this
548 function, because that makes the transfer of ownership more
549 explicit. This function might be removed in the future.
550
551 @param[in] value a JSON value to be appended
552 @retval false on success
553 @retval true on failure
554 */
557 }
558
559 /**
560 Append the value to the end of the array and take over the
561 ownership of the value.
562
563 @param value the JSON value to be appended
564 @return false on success, true on failure
565 */
567 return insert_alias(size(), std::move(value));
568 }
569
570 /**
571 Moves all of the elements in the other array to the end of
572 this array. The other array is deleted.
573
574 @param [in] other a pointer to the array which will be consumed
575 @retval false on success
576 @retval true on failure
577 */
578 bool consume(Json_array_ptr other);
579
580 /**
581 Insert a clone of the value at position index of the array. If beyond the
582 end, insert at the end.
583
584 @param[in] index the position at which to insert
585 @param[in] value a JSON value to be inserted
586 @retval false on success
587 @retval true on failure
588 */
589 bool insert_clone(size_t index, const Json_dom *value) {
590 return value == nullptr || insert_alias(index, value->clone());
591 }
592
593 /**
594 Insert the value at position index of the array.
595 If beyond the end, insert at the end.
596
597 Ownership of the value is effectively transferred to the array and
598 the value will be deallocated by the array so only append values
599 that can be deallocated safely (no stack variables please!)
600
601 @param[in] index the position at which to insert
602 @param[in] value a JSON value to be inserted
603 @retval false on success
604 @retval true on failure
605 */
606 bool insert_alias(size_t index, Json_dom_ptr value);
607
608 /**
609 Remove the value at this index. A no-op if index is larger than
610 size. Deletes the value.
611 @param[in] index the index of the value to remove
612 @return true if a value was removed, false otherwise.
613 */
614 bool remove(size_t index);
615
616 /**
617 The cardinality of the array (number of values).
618 @return the size
619 */
620 size_t size() const { return m_v.size(); }
621
622 uint32 depth() const override;
623
624 Json_dom_ptr clone() const override;
625
626 /**
627 Get the value at position index. The value has not been cloned so
628 it is the responsibility of the user to make a copy if needed. Do
629 not try to deallocate the returned value - it is owned by the array
630 and will be deallocated by it in time. It is admissible to modify
631 its contents (in place; without a clone being taken) if it is a
632 compound.
633
634 @param[in] index the array index
635 @return the value at index
636 */
637 Json_dom *operator[](size_t index) const {
638 assert(m_v[index]->parent() == this);
639 return m_v[index].get();
640 }
641
642 /**
643 Remove the values in the array.
644 */
645 void clear() { m_v.clear(); }
646
647 /// Constant iterator over the elements in the JSON array.
649
650 /// Returns a const_iterator that refers to the first element.
651 const_iterator begin() const { return m_v.begin(); }
652
653 /// Returns a const_iterator that refers past the last element.
654 const_iterator end() const { return m_v.end(); }
655
656 void replace_dom_in_container(const Json_dom *oldv,
657 Json_dom_ptr newv) override;
658
659 /// Sort the array
660 void sort(const CHARSET_INFO *cs = nullptr);
661 /// Sort the array using a user-defined comparator.
662 template <class T>
663 void sort(const T &comparator) {
664 std::sort(m_v.begin(), m_v.end(), comparator);
665 }
666
667 /**
668 Check if the given value appears in the array
669
670 @param val value to look for
671
672 @returns
673 true value is found
674 false otherwise
675 */
676 bool binary_search(Json_dom *val);
677
678 /**
679 Sort array and remove duplicate elements.
680 Used by multi-value index implementation.
681 */
682 void remove_duplicates(const CHARSET_INFO *cs);
683
684 friend Json_dom;
685};
686
687/**
688 Abstract base class for all Json scalars.
689*/
690class Json_scalar : public Json_dom {
691 public:
692 uint32 depth() const final { return 1; }
693
694 bool is_scalar() const final { return true; }
695};
696
697/**
698 Represents a JSON string value (ECMA), of type J_STRING here.
699*/
700class Json_string final : public Json_scalar {
701 private:
702 std::string m_str; //!< holds the string
703 public:
704 /*
705 Construct a Json_string object.
706 @param args any arguments accepted by std::string's constructors
707 */
708 template <typename... Args>
709 explicit Json_string(Args &&...args)
710 : Json_scalar(), m_str(std::forward<Args>(args)...) {}
711
713
714 Json_dom_ptr clone() const override {
715 return create_dom_ptr<Json_string>(m_str);
716 }
717
718 /**
719 Get the reference to the value of the JSON string.
720 @return the string reference
721 */
722 const std::string &value() const { return m_str; }
723
724 /**
725 Get the number of characters in the string.
726 @return the number of characters
727 */
728 size_t size() const { return m_str.size(); }
729};
730
731/**
732 Abstract base class of all JSON number (ECMA) types (subclasses
733 represent MySQL extensions).
734*/
735class Json_number : public Json_scalar {
736 public:
737 bool is_number() const final { return true; }
738};
739
740/**
741 Represents a MySQL decimal number, type J_DECIMAL.
742*/
743class Json_decimal final : public Json_number {
744 private:
745 my_decimal m_dec; //!< holds the decimal number
746
747 public:
749
750 explicit Json_decimal(const my_decimal &value);
751
752 /**
753 Get the number of bytes needed to store this decimal in a Json_opaque.
754 @return the number of bytes.
755 */
756 int binary_size() const;
757
758 /**
759 Get the binary representation of the wrapped my_decimal, so that this
760 value can be stored inside of a Json_opaque.
761
762 @param dest the destination buffer to which the binary representation
763 is written
764 @return false on success, true on error
765 */
766 bool get_binary(char *dest) const;
767
768 enum_json_type json_type() const override {
770 }
771
772 /**
773 Get a pointer to the MySQL decimal held by this object. Ownership
774 is _not_ transferred.
775 @return the decimal
776 */
777 const my_decimal *value() const { return &m_dec; }
778
779 Json_dom_ptr clone() const override {
780 return create_dom_ptr<Json_decimal>(m_dec);
781 }
782
783 /**
784 Convert a binary value produced by get_binary() back to a my_decimal.
785
786 @details
787 This and two next functions help storage engine to deal with
788 decimal value in a serialized JSON document. This function converts
789 serialized value to my_decimal. The later two functions extract the
790 decimal value from serialized JSON, so SE can index it in multi-valued
791 index.
792
793 @param[in] bin decimal value in binary format
794 @param[in] len length of the binary value
795 @param[out] dec my_decimal object to store the value to
796 @return false on success, true on failure
797 */
798 static bool convert_from_binary(const char *bin, size_t len, my_decimal *dec);
799 /**
800 Returns stored DECIMAL binary
801
802 @param bin serialized Json_decimal object
803
804 @returns
805 pointer to the binary decimal value
806
807 @see #convert_from_binary
808 */
809 static const char *get_encoded_binary(const char *bin) {
810 // Skip stored precision and scale
811 return bin + 2;
812 }
813 /**
814 Returns length of stored DECIMAL binary
815
816 @param length length of serialized Json_decimal object
817
818 @returns
819 length of the binary decimal value
820
821 @see #convert_from_binary
822 */
823 static size_t get_encoded_binary_len(size_t length) {
824 // Skip stored precision and scale
825 return length - 2;
826 }
827};
828
829/**
830 Represents a MySQL double JSON scalar (an extension of the ECMA
831 number value), type J_DOUBLE.
832*/
833class Json_double final : public Json_number {
834 private:
835 double m_f; //!< holds the double value
836 public:
837 explicit Json_double(double value) : Json_number(), m_f(value) {}
838
840
841 Json_dom_ptr clone() const override {
842 return create_dom_ptr<Json_double>(m_f);
843 }
844
845 /**
846 Return the double value held by this object.
847 @return the value
848 */
849 double value() const { return m_f; }
850};
851
852/**
853 Represents a MySQL integer (64 bits signed) JSON scalar (an extension
854 of the ECMA number value), type J_INT.
855*/
856class Json_int final : public Json_number {
857 private:
858 longlong m_i; //!< holds the value
859 public:
861
862 enum_json_type json_type() const override { return enum_json_type::J_INT; }
863
864 /**
865 Return the signed int held by this object.
866 @return the value
867 */
868 longlong value() const { return m_i; }
869
870 /**
871 @return true if the number can be held by a 16 bit signed integer
872 */
873 bool is_16bit() const { return INT_MIN16 <= m_i && m_i <= INT_MAX16; }
874
875 /**
876 @return true if the number can be held by a 32 bit signed integer
877 */
878 bool is_32bit() const { return INT_MIN32 <= m_i && m_i <= INT_MAX32; }
879
880 Json_dom_ptr clone() const override { return create_dom_ptr<Json_int>(m_i); }
881};
882
883/**
884 Represents a MySQL integer (64 bits unsigned) JSON scalar (an extension
885 of the ECMA number value), type J_UINT.
886*/
887
888class Json_uint final : public Json_number {
889 private:
890 ulonglong m_i; //!< holds the value
891 public:
893
895
896 /**
897 Return the unsigned int held by this object.
898 @return the value
899 */
900 ulonglong value() const { return m_i; }
901
902 /**
903 @return true if the number can be held by a 16 bit unsigned
904 integer.
905 */
906 bool is_16bit() const { return m_i <= UINT_MAX16; }
907
908 /**
909 @return true if the number can be held by a 32 bit unsigned
910 integer.
911 */
912 bool is_32bit() const { return m_i <= UINT_MAX32; }
913
914 Json_dom_ptr clone() const override { return create_dom_ptr<Json_uint>(m_i); }
915};
916
917/**
918 Represents a JSON null type (ECMA), type J_NULL here.
919*/
920class Json_null final : public Json_scalar {
921 public:
923 Json_dom_ptr clone() const override { return create_dom_ptr<Json_null>(); }
924};
925
926/**
927 Represents a MySQL temporal value (DATE, TIME, DATETIME or TIMESTAMP) -
928 an extension to the ECMA set of JSON scalar types, types J_DATE, J_TIME,
929 J_DATETIME and J_TIMESTAMP respectively. The method field_type identifies
930 which of the four it is. This is an abstract class with three child classes:
931 Json_datetime, Json_time and Json_date.
932*/
934 public:
936
937 /**
938 @returns One of MYSQL_TYPE_TIME, MYSQL_TYPE_DATE, MYSQL_TYPE_DATETIME
939 or MYSQL_TYPE_TIMESTAMP.
940 */
941 virtual enum_field_types field_type() const = 0;
942
943 /// Datetimes are packed in eight bytes.
944 static const size_t PACKED_SIZE = 8;
945};
946
947/// MySQL TIME value
948class Json_time final : public Json_temporal {
949 public:
950 /**
951 Constructs an object to hold a MySQL time value.
952
953 @param time the time value
954 */
955 explicit Json_time(const Time_val time) : Json_temporal(), m_time(time) {}
956
958
959 Json_dom_ptr clone() const override;
960
961 /// @returns the time value.
962 Time_val value() const { return m_time; }
963
964 /// @returns kind of temporal value this object holds: MYSQL_TYPE_TIME
965 enum_field_types field_type() const override { return MYSQL_TYPE_TIME; }
966
967 /**
968 Convert the TIME value to the packed format used for storage.
969 @param dest the destination buffer to write the packed time value to
970 (must at least have size PACKED_SIZE)
971 */
972 void to_packed(char *dest) const;
973
974 /**
975 Convert a packed time back to a time value.
976 @param from the buffer to read from (must have at least PACKED_SIZE bytes)
977 @param to the time field to write the value to
978 */
979 static void from_packed(const char *from, Time_val *to);
980
981#ifdef MYSQL_SERVER
982 /**
983 Convert a packed time value to key string for indexing by SE
984 @param from the buffer to read from
985 @param to the destination buffer
986 @param dec value's decimals
987 */
988 static void from_packed_to_key(const char *from, uchar *to, uint8 dec);
989#endif
990
991 private:
992 /// Holds the time value
994};
995
996/// MySQL DATE value
997class Json_date final : public Json_temporal {
998 public:
999 /**
1000 Constructs an object to hold a MySQL date value.
1001
1002 @param date the date value
1003 */
1004 explicit Json_date(const Date_val date) : Json_temporal(), m_date(date) {}
1005
1007
1008 Json_dom_ptr clone() const override;
1009
1010 /// @returns the date value.
1011 const Date_val value() const { return m_date; }
1012
1013 /// @returns kind of temporal value this object holds: MYSQL_TYPE_DATE
1014 enum_field_types field_type() const override { return MYSQL_TYPE_DATE; }
1015
1016 /**
1017 Convert the DATE value to the packed format used for storage.
1018 @param dest the destination buffer to write the packed date value to
1019 (must at least have size PACKED_SIZE)
1020 */
1021 void to_packed(char *dest) const;
1022
1023 /**
1024 Convert a packed date back to a date value.
1025 @param from the buffer to read from (must have at least PACKED_SIZE bytes)
1026 @param to the date field to write the value to
1027 */
1028 static void from_packed(const char *from, Date_val *to);
1029
1030#ifdef MYSQL_SERVER
1031 /**
1032 Convert a packed date value to key string for indexing by SE
1033 @param from the buffer to read from
1034 @param to the destination buffer
1035 */
1036 static void from_packed_to_key(const char *from, uchar *to);
1037#endif
1038 private:
1039 /// Holds the date value
1041};
1042
1043/**
1044 MySQL temporal value that represents a DATETIME or TIMESTAMP value.
1045*/
1046class Json_datetime final : public Json_temporal {
1047 public:
1048 /**
1049 Constructs an object to hold a MySQL datetime value.
1050
1051 @param[in] t the datetime value
1052 @param[in] ft field type: either MYSQL_TYPE_DATETIME or
1053 MYSQL_TYPE_TIMESTAMP.
1054 */
1056 : Json_temporal(), m_t(t), m_field_type(ft) {
1057 assert(ft != MYSQL_TYPE_TIME && ft != MYSQL_TYPE_DATE);
1058 }
1059
1060 enum_json_type json_type() const override;
1061
1062 Json_dom_ptr clone() const override;
1063
1064 /**
1065 @returns a pointer to the date/time value. Ownership is _not_ transferred.
1066 To identify which time time the value represents, use @c field_type.
1067 */
1068 const Datetime_val *value() const { return &m_t; }
1069
1070 enum_field_types field_type() const override { return m_field_type; }
1071
1072 /**
1073 Convert the datetime to the packed format used for storage.
1074 @param dest the destination buffer to write the packed datetime to
1075 (must at least have size PACKED_SIZE)
1076 */
1077 void to_packed(char *dest) const;
1078
1079 /**
1080 Convert a packed datetime back to a MYSQL_TIME.
1081 @param from the buffer to read from (must have at least PACKED_SIZE bytes)
1082 @param ft the field type of the value
1083 @param to the MYSQL_TIME to write the value to
1084 */
1085 static void from_packed(const char *from, enum_field_types ft,
1086 MYSQL_TIME *to);
1087
1088#ifdef MYSQL_SERVER
1089 /**
1090 Convert a packed datetime to key string for indexing by SE
1091 @param from the buffer to read from
1092 @param ft the field type of the value
1093 @param to the destination buffer
1094 @param dec value's decimals
1095 */
1096 static void from_packed_to_key(const char *from, enum_field_types ft,
1097 uchar *to, uint8 dec);
1098#endif
1099
1100 private:
1101 Datetime_val m_t; //!< holds the date/time value
1102 enum_field_types m_field_type; //!< identifies which type of date/time
1103};
1104
1105/**
1106 Represents a MySQL value opaquely, i.e. the Json DOM can not
1107 serialize or deserialize these values. This should be used to store
1108 values that don't map to the other Json_scalar classes. Using the
1109 "to_string" method on such values (via Json_wrapper) will yield a base
1110 64 encoded string tagged with the MySQL type with this syntax:
1111
1112 "base64:typeXX:<base 64 encoded value>"
1113*/
1114class Json_opaque final : public Json_scalar {
1115 private:
1117 std::string m_val;
1118
1119 public:
1120 /**
1121 An opaque MySQL value.
1122
1123 @param[in] mytype the MySQL type of the value
1124 @param[in] args arguments to construct the binary value to be stored
1125 in the DOM (anything accepted by the std::string
1126 constructors)
1127 @see #enum_field_types
1128 @see Class documentation
1129 */
1130 template <typename... Args>
1131 explicit Json_opaque(enum_field_types mytype, Args &&...args)
1132 : Json_scalar(), m_mytype(mytype), m_val(std::forward<Args>(args)...) {}
1133
1135
1136 /**
1137 @return a pointer to the opaque value. Use #size() to get its size.
1138 */
1139 const char *value() const { return m_val.data(); }
1140
1141 /**
1142 @return the MySQL type of the value
1143 */
1144 enum_field_types type() const { return m_mytype; }
1145 /**
1146 @return the size in bytes of the value
1147 */
1148 size_t size() const { return m_val.size(); }
1149
1150 Json_dom_ptr clone() const override;
1151};
1152
1153/**
1154 Represents a JSON true or false value, type J_BOOLEAN here.
1155*/
1156class Json_boolean final : public Json_scalar {
1157 private:
1158 bool m_v; //!< false or true: represents the eponymous JSON literal
1159 public:
1160 explicit Json_boolean(bool value) : Json_scalar(), m_v(value) {}
1161
1162 enum_json_type json_type() const override {
1164 }
1165
1166 /**
1167 @return false for JSON false, true for JSON true
1168 */
1169 bool value() const { return m_v; }
1170
1171 Json_dom_ptr clone() const override {
1172 return create_dom_ptr<Json_boolean>(m_v);
1173 }
1174};
1175
1176/**
1177 Perform quoting on a JSON string to make an external representation
1178 of it. It wraps double quotes (text quotes) around the string (cptr)
1179 and also performs escaping according to the following table:
1180 <pre>
1181 @verbatim
1182 Common name C-style Original unescaped Transformed to
1183 escape UTF-8 bytes escape sequence
1184 notation in UTF-8 bytes
1185 ---------------------------------------------------------------
1186 quote \" %x22 %x5C %x22
1187 backslash \\ %x5C %x5C %x5C
1188 backspace \b %x08 %x5C %x62
1189 formfeed \f %x0C %x5C %x66
1190 linefeed \n %x0A %x5C %x6E
1191 carriage-return \r %x0D %x5C %x72
1192 tab \t %x09 %x5C %x74
1193 unicode \uXXXX A hex number in the %x5C %x75
1194 range of 00-1F, followed by
1195 except for the ones 4 hex digits
1196 handled above (backspace,
1197 formfeed, linefeed,
1198 carriage-return,
1199 and tab).
1200 ---------------------------------------------------------------
1201 @endverbatim
1202 </pre>
1203
1204 @param[in] cptr pointer to string data
1205 @param[in] length the length of the string
1206 @param[in,out] buf the destination buffer
1207 @retval true on error
1208*/
1209bool double_quote(const char *cptr, size_t length, String *buf);
1210
1211/**
1212 Merge two doms. The right dom is either subsumed into the left dom
1213 or the contents of the right dom are transferred to the left dom
1214 and the right dom is deleted. After calling this function, the
1215 caller should not reference the right dom again. It has been
1216 deleted.
1217
1218 Returns NULL if there is a memory allocation failure. In this case
1219 both doms are deleted.
1220
1221 scalars - If any of the documents that are being merged is a scalar,
1222 each scalar document is autowrapped as a single value array before merging.
1223
1224 arrays - When merging a left array with a right array,
1225 then the result is the left array concatenated
1226 with the right array. For instance, [ 1, 2 ] merged with [ 3, 4 ]
1227 is [ 1, 2, 3, 4 ].
1228
1229 array and object - When merging an array with an object,
1230 the object is autowrapped as an array and then the rule above
1231 is applied. So [ 1, 2 ] merged with { "a" : true }
1232 is [ 1, 2, { "a": true } ].
1233
1234 objects - When merging two objects, the two objects are concatenated
1235 into a single, larger object. So { "a" : "foo" } merged with { "b" : 5 }
1236 is { "a" : "foo", "b" : 5 }.
1237
1238 duplicates - When two objects are merged and they share a key,
1239 the values associated with the shared key are merged.
1240
1241 @param [in,out] left The recipient dom.
1242 @param [in,out] right The dom to be consumed
1243
1244 @return A composite dom which subsumes the left and right doms, or NULL
1245 if a failure happened while merging
1246*/
1248
1249constexpr uchar JSON_KEY_NULL = '\x00';
1250constexpr uchar JSON_KEY_OBJECT = '\x05';
1251constexpr uchar JSON_KEY_ARRAY = '\x06';
1252constexpr uchar JSON_KEY_FALSE = '\x07';
1253constexpr uchar JSON_KEY_TRUE = '\x08';
1254
1255/**
1256 Abstraction for accessing JSON values irrespective of whether they
1257 are (started out as) binary JSON values or JSON DOM values. The
1258 purpose of this is to allow uniform access for callers. It allows us
1259 to access binary JSON values without necessarily building a DOM (and
1260 thus having to read the entire value unless necessary, e.g. for
1261 accessing only a single array slot or object field).
1262
1263 Instances of this class are usually created on the stack. In some
1264 cases instances are cached in an Item and reused, in which case they
1265 are allocated from query-duration memory (by allocating them on a
1266 MEM_ROOT).
1267*/
1269 private:
1270 /*
1271 A Json_wrapper wraps either a Json_dom or a json_binary::Value,
1272 never both at the same time.
1273 */
1274 union {
1275 /// The DOM representation, only used if m_is_dom is true.
1276 struct {
1278 /// If true, don't deallocate m_dom_value in destructor.
1281 /// The binary representation, only used if m_is_dom is false.
1283 };
1284 bool m_is_dom; //!< Wraps a DOM iff true
1285 public:
1286 /**
1287 Get the wrapped datetime value in the packed format.
1288
1289 @param[in,out] buffer a char buffer with space for at least
1290 Json_datetime::PACKED_SIZE characters
1291 @return a char buffer that contains the packed representation of the
1292 datetime (may or may not be the same as buffer)
1293 */
1294 const char *get_datetime_packed(char *buffer) const;
1295 const char *get_time_packed(char *buffer) const;
1296 const char *get_date_packed(char *buffer) const;
1297
1298 /**
1299 Create an empty wrapper. Cf #empty().
1300 */
1301 Json_wrapper() : m_dom{nullptr, true}, m_is_dom(true) {}
1302
1303 /**
1304 Wrap the supplied DOM value (no copy taken). The wrapper takes
1305 ownership, unless alias is true or @c set_alias is called after
1306 construction.
1307 In the latter case the lifetime of the DOM is determined by
1308 the owner of the DOM, so clients need to ensure that that
1309 lifetime is sufficient, lest dead storage is attempted accessed.
1310
1311 @param[in,out] dom_value the DOM value
1312 @param alias Whether the wrapper is an alias to DOM
1313 */
1314 explicit Json_wrapper(Json_dom *dom_value, bool alias = false);
1315
1316 /**
1317 Wrap the supplied DOM value. The wrapper takes over the ownership.
1318 */
1319 explicit Json_wrapper(Json_dom_ptr dom_value)
1320 : Json_wrapper(dom_value.release()) {}
1321
1322 /**
1323 Only meaningful iff the wrapper encapsulates a DOM. Marks the
1324 wrapper as not owning the DOM object, i.e. it will not be
1325 deallocated in the wrapper's destructor. Useful if one wants a wrapper
1326 around a DOM owned by someone else.
1327 */
1328 void set_alias() { m_dom.m_alias = true; }
1329
1330 /**
1331 Wrap a binary value. Does not copy the underlying buffer, so
1332 lifetime is limited the that of the supplied value.
1333
1334 @param[in] value the binary value
1335 */
1336 explicit Json_wrapper(const json_binary::Value &value);
1337
1338 /**
1339 Copy constructor. Does a deep copy of any owned DOM. If a DOM
1340 os not owned (aliased), the copy will also be aliased.
1341 */
1342 Json_wrapper(const Json_wrapper &old);
1343
1344 /**
1345 Move constructor. Take over the ownership of the other wrapper's
1346 DOM, unless it's aliased. If the other wrapper is aliased, this
1347 wrapper becomes an alias too. Any already owned DOM will be
1348 deallocated.
1349
1350 @param old the wrapper whose contents to take over
1351 */
1352 Json_wrapper(Json_wrapper &&old) noexcept;
1353
1354 /**
1355 Assignment operator. Does a deep copy of any owned DOM. If a DOM
1356 os not owned (aliased), the copy will also be aliased. Any owned
1357 DOM in the left side will be deallocated.
1358 */
1359 Json_wrapper &operator=(const Json_wrapper &old);
1360
1361 /**
1362 Move-assignment operator. Take over the ownership of the other
1363 wrapper's DOM, unless it's aliased. If the other wrapper is
1364 aliased, this wrapper becomes an alias too. Any already owned DOM
1365 will be deallocated.
1366
1367 @param old the wrapper whose contents to take over
1368 */
1369 Json_wrapper &operator=(Json_wrapper &&old) noexcept;
1370
1371 ~Json_wrapper();
1372
1373 /**
1374 A Wrapper is defined to be empty if it is passed a NULL value with the
1375 constructor for JSON dom, or if the default constructor is used.
1376
1377 @return true if the wrapper is empty.
1378 */
1379 bool empty() const { return m_is_dom && !m_dom.m_value; }
1380
1381 /**
1382 Does this wrapper contain a DOM?
1383
1384 @retval true if the wrapper contains a DOM representation
1385 @retval false if the wrapper contains a binary representation
1386 */
1387 bool is_dom() const { return m_is_dom; }
1388
1389 /**
1390 Get the wrapped contents in DOM form. The DOM is (still) owned by the
1391 wrapper. If this wrapper originally held a value, it is now converted
1392 to hold (and eventually release) the DOM version.
1393
1394 @return pointer to a DOM object, or NULL if the DOM could not be allocated
1395 */
1396 Json_dom *to_dom();
1397
1398 /**
1399 Gets a pointer to the wrapped Json_dom object, if this wrapper holds a DOM.
1400 If is_dom() returns false, the result of calling this function is undefined.
1401 */
1402 const Json_dom *get_dom() const {
1403 assert(m_is_dom);
1404 return m_dom.m_value;
1405 }
1406
1407 /**
1408 Gets the wrapped json_binary::Value object, if this wrapper holds a binary
1409 JSON value. If is_dom() returns true, the result of calling this function is
1410 undefined.
1411 */
1413 assert(!m_is_dom);
1414 return m_value;
1415 }
1416
1417 /**
1418 Get the wrapped contents in DOM form. Same as to_dom(), except it returns
1419 a clone of the original DOM instead of the actual, internal DOM tree.
1420
1421 @return pointer to a DOM object, or NULL if the DOM could not be allocated
1422 */
1423 Json_dom_ptr clone_dom() const;
1424
1425 /**
1426 Get the wrapped contents in binary value form.
1427
1428 @param error_handler a handler that is invoked if an error occurs
1429 @param[in,out] str a string that will be filled with the binary value
1430
1431 @retval false on success
1432 @retval true on error
1433 */
1434 bool to_binary(const JsonSerializationErrorHandler &error_handler,
1435 String *str) const;
1436
1437 /**
1438 Check if the wrapped JSON document is a binary value (a
1439 json_binary::Value), and if that binary is pointing to data stored in the
1440 given string.
1441
1442 This function can be used to check if overwriting the data in the string
1443 might overwrite and corrupt the document contained in this wrapper.
1444
1445 @param str a string which contains JSON binary data
1446 @retval true if the string contains data that the wrapped document
1447 points to from its json_binary::Value representation
1448 @retval false otherwise
1449 */
1450 bool is_binary_backed_by(const String *str) const {
1451 return !m_is_dom && m_value.is_backed_by(str);
1452 }
1453
1454 /**
1455 Format the JSON value to an external JSON string in buffer in
1456 the format of ISO/IEC 10646.
1457
1458 @param[in,out] buffer the formatted string is appended, so make sure
1459 the length is set correctly before calling
1460 @param[in] json_quoted if the JSON value is a string and json_quoted
1461 is false, don't perform quoting on the string.
1462 This is only used by JSON_UNQUOTE.
1463 @param[in] func_name The name of the function that called to_string().
1464
1465 @return false formatting went well, else true
1466 */
1467 bool to_string(String *buffer, bool json_quoted, const char *func_name,
1468 const JsonErrorHandler &depth_handler) const;
1469
1470 /**
1471 Print this JSON document to the debug trace.
1472
1473 @param[in] message If given, the JSON document is prefixed with
1474 this message.
1475 */
1476 void dbug_print(const char *message,
1477 const JsonErrorHandler &depth_handler) const;
1478
1479 /**
1480 Format the JSON value to an external JSON string in buffer in the format of
1481 ISO/IEC 10646. Add newlines and indentation for readability.
1482
1483 @param[in,out] buffer the buffer that receives the formatted string
1484 (the string is appended, so make sure the length
1485 is set correctly before calling)
1486 @param[in] func_name the name of the calling function
1487
1488 @retval false on success
1489 @retval true on error
1490 */
1491 bool to_pretty_string(String *buffer, const char *func_name,
1492 const JsonErrorHandler &depth_handler) const;
1493
1494 // Accessors
1495
1496 /**
1497 Return the type of the wrapped JSON value
1498
1499 @return the type, or Json_dom::J_ERROR if the wrapper does not contain
1500 a JSON value
1501 */
1502 enum_json_type type() const;
1503
1504 /**
1505 Return the MYSQL type of the opaque value, see #type(). Valid for
1506 J_OPAQUE. Calling this method if the type is not J_OPAQUE will give
1507 undefined results.
1508
1509 @return the type
1510 */
1512
1513 /**
1514 If this wrapper holds a JSON array, get an array value by indexing
1515 into the array. Valid for J_ARRAY. Calling this method if the type is
1516 not J_ARRAY will give undefined results.
1517
1518 @return the array value
1519 */
1520 Json_wrapper operator[](size_t index) const;
1521
1522 /**
1523 If this wrapper holds a JSON object, get the value corresponding
1524 to the member key. Valid for J_OBJECT. Calling this method if the type is
1525 not J_OBJECT will give undefined results.
1526
1527 @param[in] key name for identifying member
1528
1529 @return The member value. If there is no member with the specified
1530 name, a value with type Json_dom::J_ERROR is returned.
1531 */
1532 Json_wrapper lookup(std::string_view key) const;
1533
1534 /**
1535 Get a pointer to the data of a JSON string or JSON opaque value.
1536 The data is still owner by the wrapper. The data may not be null
1537 terminated, so use in conjunction with @c get_data_length.
1538 Valid for J_STRING and J_OPAQUE. Calling this method if the type is
1539 not one of those will give undefined results.
1540
1541 @return the pointer
1542 */
1543 const char *get_data() const;
1544
1545 /**
1546 Get the length to the data of a JSON string or JSON opaque value.
1547 Valid for J_STRING and J_OPAQUE. Calling this method if the type is
1548 not one of those will give undefined results.
1549
1550 @return the length
1551 */
1552 size_t get_data_length() const;
1553
1554 /**
1555 Get the MySQL representation of a JSON decimal value.
1556 Valid for J_DECIMAL. Calling this method if the type is
1557 not J_DECIMAL will give undefined results.
1558
1559 @param[out] d the decimal value
1560 @return false on success, true on failure (which would indicate an
1561 internal error)
1562 */
1563 bool get_decimal_data(my_decimal *d) const;
1564
1565 /**
1566 Get the value of a JSON double number.
1567 Valid for J_DOUBLE. Calling this method if the type is
1568 not J_DOUBLE will give undefined results.
1569
1570 @return the value
1571 */
1572 double get_double() const;
1573
1574 /**
1575 Get the value of a JSON signed integer number.
1576 Valid for J_INT. Calling this method if the type is
1577 not J_INT will give undefined results.
1578
1579 @return the value
1580 */
1581 longlong get_int() const;
1582
1583 /**
1584 Get the value of a JSON unsigned integer number.
1585 Valid for J_UINT. Calling this method if the type is
1586 not J_UINT will give undefined results.
1587
1588 @return the value
1589 */
1590 ulonglong get_uint() const;
1591
1592 /**
1593 Get the value of a JSON date/time value. Valid for J_DATETIME
1594 and J_TIMESTAMP. Calling this method if the type is not one of those
1595 will give undefined results.
1596
1597 @param[out] t the date/time value
1598 */
1599 void get_datetime(MYSQL_TIME *t) const;
1600
1601 /**
1602 Get the value of a JSON time value. Valid for J_TIME.
1603 Calling this method if the type is not J_TIME will give undefined results.
1604
1605 @param[out] time the time value
1606 */
1607 void get_time(Time_val *time) const;
1608
1609 /**
1610 Get the value of a JSON date value. Valid for J_DATE.
1611 Calling this method if the type is not J_DATE will give undefined results.
1612
1613 @param[out] date the date value
1614 */
1615 void get_date(Date_val *date) const;
1616
1617 /**
1618 Get a boolean value (a JSON true or false literal).
1619 Valid for J_BOOLEAN. Calling this method if the type is
1620 not J_BOOLEAN will give undefined results.
1621
1622 @return the value
1623 */
1624 bool get_boolean() const;
1625
1626 /**
1627 Finds all of the json sub-documents which match the path expression.
1628 Puts the matches on an evolving vector of results.
1629 This is a bit inefficient for binary wrappers because you can't
1630 build up a binary array incrementally from its cells. Instead, you
1631 have to turn each cell into a dom and then add the doms to a
1632 dom array.
1633
1634 Calling this if #empty() returns true is an error.
1635
1636 Special care must be taken when the path expression contains more than one
1637 ellipsis (**) token. That is because multiple paths with ellipses may
1638 identify the same value. Consider the following document:
1639
1640 { "a": { "x" : { "b": { "y": { "b": { "z": { "c": 100 } } } } } } }
1641
1642 The innermost value (the number 100) has the following unique,
1643 non-wildcarded address:
1644
1645 $.a.x.b.y.b.z.c
1646
1647 That location is reached by both of the following paths which include
1648 the ellipsis token:
1649
1650 $.a.x.b**.c
1651 $.a.x.b.y.b**.c
1652
1653 And those addresses both satisfy the following path expression which has
1654 two ellipses:
1655
1656 $.a**.b**.c
1657
1658 In this case, we only want to return one instance of $.a.x.b.y.b.z.c
1659
1660 Similarly, special care must be taken if an auto-wrapping array
1661 path leg follows an ellipsis. Consider the following document:
1662
1663 { "a": { "b" : [ 1, 2, 3 ] } }
1664
1665 The first element of the array (the number 1) can be reached with
1666 either of these two non-wildcarded addresses, due to array auto-wrapping:
1667
1668 $.a.b[0]
1669 $.a.b[0][0]
1670
1671 Both of those addresses match the following path expression, which
1672 has an ellipsis followed by an auto-wrapping path leg:
1673
1674 $**[0]
1675
1676 @param[in] path the (possibly wildcarded) address of the sub-documents
1677 @param[in] legs the number of legs to use from @a path
1678 @param[out] hits the result of the search
1679 @param[in] auto_wrap true of we match a final scalar with search for [0]
1680 @param[in] only_need_one True if we can stop after finding one match
1681
1682 @retval false on success
1683 @retval true on error
1684 */
1685 bool seek(const Json_seekable_path &path, size_t legs,
1686 Json_wrapper_vector *hits, bool auto_wrap, bool only_need_one);
1687
1688 /**
1689 Compute the length of a document. This is the value which would be
1690 returned by the JSON_LENGTH() system function. So, this returns
1691
1692 - for scalar values: 1
1693 - for objects: the number of members
1694 - for arrays: the number of cells
1695
1696 @returns 1, the number of members, or the number of cells
1697 */
1698 size_t length() const;
1699
1700 /**
1701 Compare this JSON value to another JSON value.
1702 @param[in] other the other JSON value
1703 @param[in] cs if given, this charset will be used in comparison of
1704 string values
1705 @retval -1 if this JSON value is less than the other JSON value
1706 @retval 0 if the two JSON values are equal
1707 @retval 1 if this JSON value is greater than the other JSON value
1708 */
1709 int compare(const Json_wrapper &other,
1710 const CHARSET_INFO *cs = nullptr) const;
1711
1712 /**
1713 Extract an int (signed or unsigned) from the JSON if possible
1714 coercing if need be.
1715
1716 @param[in] error_handler function to be called on conversion errors
1717 @param[out] err true <=> error occur during coercion
1718 @param[out] unsigned_flag Whether the value read from JSON data is
1719 unsigned
1720
1721 @returns json value coerced to int
1722 */
1723 longlong coerce_int(const JsonCoercionHandler &error_handler, bool *err,
1724 bool *unsigned_flag) const;
1725
1726 /// Shorthand for coerce_int(error_handler, nullptr, nullptr).
1727 longlong coerce_int(const JsonCoercionHandler &error_handler) const {
1728 return coerce_int(error_handler, nullptr, nullptr);
1729 }
1730
1731 /**
1732 Extract a real from the JSON if possible, coercing if need be.
1733
1734 @param[in] error_handler function to be called on conversion errors
1735 @param[out] err true <=> error occur during coercion
1736 @returns json value coerced to real
1737 */
1738 double coerce_real(const JsonCoercionHandler &error_handler, bool *err) const;
1739
1740 /// Shorthand for coerce_real(error_handler, nullptr).
1741 double coerce_real(const JsonCoercionHandler &error_handler) const {
1742 return coerce_real(error_handler, nullptr);
1743 }
1744
1745 /**
1746 Extract a decimal from the JSON if possible, coercing if need be.
1747
1748 @param[in] error_handler function to be called on conversion errors
1749 @param[in,out] decimal_value a value buffer
1750 @param[out] err true <=> error occur during coercion
1751 @returns json value coerced to decimal
1752 */
1753 my_decimal *coerce_decimal(const JsonCoercionHandler &error_handler,
1754 my_decimal *decimal_value, bool *err) const;
1755
1756 /// Shorthand for coerce_decimal(error_handler, decimal_value, nullptr).
1758 my_decimal *decimal_value) const {
1759 return coerce_decimal(error_handler, decimal_value, nullptr);
1760 }
1761
1762 /**
1763 Extract a date from the JSON if possible, coercing if need be.
1764
1765 @param[in] error_handler function to be called on conversion errors
1766 @param[in] deprecation_checker function to be called to check for
1767 deprecated datetime format in ltime
1768 @param[in,out] date a value buffer
1769 @param[in] flags Flags to use for string -> date conversion
1770 @returns json value coerced to date
1771 */
1772 bool coerce_date(const JsonCoercionHandler &error_handler,
1773 const JsonCoercionDeprecatedHandler &deprecation_checker,
1774 Date_val *date, my_time_flags_t flags = 0) const;
1775
1776 /**
1777 Extract a time value from the JSON if possible, coercing if need be.
1778
1779 @param[in] error_handler function to be called on conversion errors
1780 @param[in] deprecation_checker function to be called to check for
1781 deprecated datetime format in ltime
1782 @param[in,out] time a value buffer
1783
1784 @returns json value coerced to time
1785 */
1786 bool coerce_time(const JsonCoercionHandler &error_handler,
1787 const JsonCoercionDeprecatedHandler &deprecation_checker,
1788 Time_val *time) const;
1789
1790 /**
1791 Extract a datetime from the JSON if possible, coercing if need be.
1792
1793 @param[in] error_handler function to be called on conversion errors
1794 @param[in] deprecation_checker function to be called to check for
1795 deprecated datetime format in ltime
1796 @param[in,out] dt a value buffer
1797 @param[in] flags Flags to use for string -> date conversion
1798 @returns json value coerced to date
1799 */
1800 bool coerce_datetime(const JsonCoercionHandler &error_handler,
1801 const JsonCoercionDeprecatedHandler &deprecation_checker,
1802 Datetime_val *dt, my_time_flags_t flags = 0) const;
1803
1804 /**
1805 Make a sort key that can be used by filesort to order JSON values.
1806
1807 @param[out] to a buffer to which the sort key is written
1808 @param[in] length the length of the sort key
1809
1810 @details Key storage format is following:
1811 @verbatim
1812 |<json type>< sort key >|
1813 1 byte / variable length /
1814 @endverbatim
1815
1816 JSON is assumed to be non-sql-null and valid (checked by caller).
1817 Key length contains full length - the len prefix itself, json type and the
1818 sort key.
1819 All numeric types are stored as a number, without distinction to
1820 double/decimal/int/etc. See @c make_json_numeric_sort_key().
1821 Same is done to DATETIME and TIMESTAMP types.
1822 For string and opaque types only the prefix that fits into the output buffer
1823 is stored.
1824 For JSON objects and arrays only their length (number of elements) is
1825 stored, this is a limitation of current implementation.
1826 */
1827 size_t make_sort_key(uchar *to, size_t length) const;
1828
1829 /**
1830 Make a hash key that can be used by sql_executor.cc/unique_hash
1831 in order to support SELECT DISTINCT
1832
1833 @param[in] hash_val An initial hash value.
1834 */
1835 ulonglong make_hash_key(ulonglong hash_val) const;
1836
1838
1839 /**
1840 Calculate the amount of unused space inside a JSON binary value.
1841
1842 @param[in] error_handler the handler that is invoked if an error occurs
1843 @param[out] space the amount of unused space, or zero if this is a DOM
1844 @return false on success
1845 @return true if the JSON binary value was invalid
1846 */
1847 bool get_free_space(const JsonSerializationErrorHandler &error_handler,
1848 size_t *space) const;
1849
1850#ifdef MYSQL_SERVER
1851 /**
1852 Attempt a binary partial update by replacing the value at @a path with @a
1853 new_value. On successful completion, the updated document will be available
1854 in @a result, and this Json_wrapper will point to @a result instead of the
1855 original binary representation. The modifications that have been applied,
1856 will also be collected as binary diffs, which can be retrieved via
1857 TABLE::get_binary_diffs().
1858
1859 @param field the column being updated
1860 @param path the path of the value to update
1861 @param new_value the new value
1862 @param replace true if we use JSON_REPLACE semantics
1863 @param[in,out] result buffer that holds the updated JSON document (is
1864 empty if no partial update has been performed on
1865 this Json_wrapper so far, or contains the binary
1866 representation of the document in this wrapper
1867 otherwise)
1868 @param[out] partially_updated gets set to true if partial update was
1869 successful, also if it was a no-op
1870 @param[out] replaced_path gets set to true if the path was replaced,
1871 will be false if this update is a no-op
1872
1873 @retval false if the update was successful, or if it was determined
1874 that a full update was needed
1875 @retval true if an error occurred
1876 */
1877 bool attempt_binary_update(const Field_json *field,
1878 const Json_seekable_path &path,
1879 Json_wrapper *new_value, bool replace,
1880 String *result, bool *partially_updated,
1881 bool *replaced_path);
1882
1883 /**
1884 Remove a path from a binary JSON document. On successful completion, the
1885 updated document will be available in @a result, and this Json_wrapper will
1886 point to @a result instead of the original binary representation. The
1887 modifications that have been applied, will also be collected as binary
1888 diffs, which can be retrieved via TABLE::get_binary_diffs().
1889
1890 @param field the column being updated
1891 @param path the path to remove from the document
1892 @param[in,out] result buffer that holds the updated JSON document (is
1893 empty if no partial update has been performed on
1894 this Json_wrapper so far, or contains the binary
1895 representation of the document in this wrapper
1896 otherwise)
1897 @param[out] found_path gets set to true if the path is found in the
1898 document, false otherwise
1899
1900 @retval false if the value was successfully updated
1901 @retval true if an error occurred
1902 */
1903 bool binary_remove(const Field_json *field, const Json_seekable_path &path,
1904 String *result, bool *found_path);
1905#endif // ifdef MYSQL_SERVER
1906
1907 /**
1908 Sort contents. Applicable to JSON arrays only.
1909 */
1910 void sort(const CHARSET_INFO *cs = nullptr);
1911 /**
1912 Remove duplicate values. Applicable to JSON arrays only, array will be
1913 sorted.
1914 */
1915 void remove_duplicates(const CHARSET_INFO *cs = nullptr);
1916};
1917
1918/**
1919 Class that iterates over all members of a JSON object that is wrapped in a
1920 Json_wrapper instance.
1921*/
1923 public:
1924 // Type aliases required by ForwardIterator.
1925 using value_type = std::pair<std::string_view, Json_wrapper>;
1926 using reference = const value_type &;
1927 using pointer = const value_type *;
1928 using difference_type = ptrdiff_t;
1929 using iterator_category = std::forward_iterator_tag;
1930
1931 /**
1932 Creates an iterator that iterates over all members of the given
1933 Json_wrapper, if it wraps a JSON object. If the wrapper does not wrap a JSON
1934 object, the result is undefined.
1935
1936 @param wrapper the Json_wrapper to iterate over
1937 @param begin true to construct an iterator that points to the first member
1938 of the object, false to construct a past-the-end iterator
1939 */
1940 Json_wrapper_object_iterator(const Json_wrapper &wrapper, bool begin);
1941
1942 /// Forward iterators must be default constructible.
1944
1945 /// Advances the iterator to the next element.
1947 if (is_dom())
1948 ++m_iter;
1949 else
1952 return *this;
1953 }
1954
1955 /**
1956 Advances the iterator to the next element and returns an iterator that
1957 points to the current element (post-increment operator).
1958 */
1961 ++(*this);
1962 return copy;
1963 }
1964
1965 /// Checks two iterators for equality.
1966 bool operator==(const Json_wrapper_object_iterator &other) const {
1967 return is_dom() ? m_iter == other.m_iter
1969 }
1970
1971 /// Checks two iterators for inequality.
1972 bool operator!=(const Json_wrapper_object_iterator &other) const {
1973 return !(*this == other);
1974 }
1975
1978 return &m_current_member;
1979 }
1980
1981 reference operator*() { return *this->operator->(); }
1982
1983 private:
1984 /// Pair holding the key and value of the member pointed to by the iterator.
1986 /// True if #m_current_member is initialized.
1988 /// The binary JSON object being iterated over, or nullptr for DOMs.
1990 /// The index of the current member in the binary JSON object.
1992 /// Iterator pointing to the current member in the JSON DOM object.
1994 /// Returns true if iterating over a DOM.
1995 bool is_dom() const { return m_binary_value == nullptr; }
1996 /// Fill #m_current_member with the key and value of the current member.
1998};
1999
2000/**
2001 A wrapper over a JSON object which provides an interface that can be iterated
2002 over with a for-each loop.
2003*/
2005 public:
2007 explicit Json_object_wrapper(const Json_wrapper &wrapper)
2008 : m_wrapper(wrapper) {}
2010 const_iterator cend() const { return const_iterator(m_wrapper, false); }
2011 const_iterator begin() const { return cbegin(); }
2012 const_iterator end() const { return cend(); }
2013
2014 private:
2016};
2017
2018/**
2019 Check if a string contains valid JSON text, without generating a
2020 Json_dom representation of the document.
2021
2022 @param[in] text pointer to the beginning of the string
2023 @param[in] length the length of the string
2024 @return true if the string is valid JSON text, false otherwise
2025*/
2026bool is_valid_json_syntax(const char *text, size_t length);
2027
2028/**
2029 A class that is capable of holding objects of any sub-type of
2030 Json_scalar. Used for pre-allocating space in query-duration memory
2031 for JSON scalars that are to be returned by get_json_atom_wrapper().
2032
2033 This class should be replaced by std::variant when moving to C++17.
2034*/
2036 /// Union of all concrete subclasses of Json_scalar.
2049 /// Constructor which initializes the union to hold a Json_null value.
2051 /// Destructor which delegates to Json_scalar's virtual destructor.
2053 // All members have the same address, and all members are sub-types of
2054 // Json_scalar, so we can take the address of an arbitrary member and
2055 // convert it to Json_scalar.
2056 Json_scalar *scalar = &m_null;
2057 scalar->~Json_scalar();
2058 }
2059 };
2060
2061 /// The buffer in which the Json_scalar value is stored.
2063
2064 /// Pointer to the held scalar, or nullptr if no value is held.
2066
2067 public:
2068 /// Get a pointer to the held object, or nullptr if there is none.
2070
2071 /**
2072 Construct a new Json_scalar value in this Json_scalar_holder.
2073 If a value is already held, the old value is destroyed and replaced.
2074 @tparam T which type of Json_scalar to create
2075 @param args the arguments to T's constructor
2076 */
2077 template <typename T, typename... Args>
2078 void emplace(Args &&...args) {
2079 static_assert(std::is_base_of<Json_scalar, T>::value, "Not a Json_scalar");
2080 static_assert(sizeof(T) <= sizeof(m_buffer), "Buffer is too small");
2082 m_scalar_ptr->~Json_scalar();
2083 ::new (m_scalar_ptr) T(std::forward<Args>(args)...);
2084 }
2085};
2086
2087/**
2088 Check if one Json_wrapper contains all the elements of another
2089 Json_wrapper.
2090
2091 @param[in] doc_wrapper the containing document
2092 @param[in] containee_wr the possibly contained document
2093 @param[out] result true if doc_wrapper contains containee_wr,
2094 false otherwise
2095 @retval false on success
2096 @retval true on failure
2097*/
2098bool json_wrapper_contains(const Json_wrapper &doc_wrapper,
2099 const Json_wrapper &containee_wr, bool *result);
2100
2101/// Returns the name of the type of the JSON document contained in "doc".
2102std::string_view json_type_name(const Json_wrapper &doc);
2103
2104/// The maximum length of the type name returned from JSON_TYPE.
2105extern const size_t kMaxJsonTypeNameLength;
2106
2107#endif /* JSON_DOM_INCLUDED */
Kerberos Client Authentication nullptr
Definition: auth_kerberos_client_plugin.cc:247
Date_val is a temporal type that represents dates within the range 0000-01-01 and 9999-12-31.
Definition: my_temporal.h:421
Definition: my_temporal.h:341
A field that stores a JSON value.
Definition: field.h:3908
Error handler for the functions that serialize a JSON value in the JSON binary storage format.
Definition: json_error_handler.h:49
Represents a JSON array container, i.e.
Definition: json_dom.h:520
void sort(const CHARSET_INFO *cs=nullptr)
Sort the array.
Definition: json_dom.cc:1132
Json_dom * operator[](size_t index) const
Get the value at position index.
Definition: json_dom.h:637
Json_array()
Definition: json_dom.cc:1033
bool binary_search(Json_dom *val)
Check if the given value appears in the array.
Definition: json_dom.cc:1141
bool remove(size_t index)
Remove the value at this index.
Definition: json_dom.cc:1057
const_iterator end() const
Returns a const_iterator that refers past the last element.
Definition: json_dom.h:654
decltype(m_v)::const_iterator const_iterator
Constant iterator over the elements in the JSON array.
Definition: json_dom.h:648
bool append_alias(Json_dom_ptr value)
Append the value to the end of the array and take over the ownership of the value.
Definition: json_dom.h:566
void replace_dom_in_container(const Json_dom *oldv, Json_dom_ptr newv) override
Replace oldv contained inside this container array or object) with newv.
Definition: json_dom.cc:851
bool consume(Json_array_ptr other)
Moves all of the elements in the other array to the end of this array.
Definition: json_dom.cc:1035
bool insert_alias(size_t index, Json_dom_ptr value)
Insert the value at position index of the array.
Definition: json_dom.cc:1045
Json_dom_ptr clone() const override
Make a deep clone.
Definition: json_dom.cc:1075
void clear()
Remove the values in the array.
Definition: json_dom.h:645
void sort(const T &comparator)
Sort the array using a user-defined comparator.
Definition: json_dom.h:663
size_t size() const
The cardinality of the array (number of values).
Definition: json_dom.h:620
std::vector< Json_dom_ptr, Malloc_allocator< Json_dom_ptr > > m_v
Holds the array values.
Definition: json_dom.h:523
void remove_duplicates(const CHARSET_INFO *cs)
Sort array and remove duplicate elements.
Definition: json_dom.cc:1136
bool append_alias(Json_dom *value)
Append the value to the end of the array.
Definition: json_dom.h:555
friend Json_dom
Definition: json_dom.h:684
bool insert_clone(size_t index, const Json_dom *value)
Insert a clone of the value at position index of the array.
Definition: json_dom.h:589
uint32 depth() const override
Compute the depth of a document.
Definition: json_dom.cc:1066
const_iterator begin() const
Returns a const_iterator that refers to the first element.
Definition: json_dom.h:651
bool append_clone(const Json_dom *value)
Append a clone of the value to the end of the array.
Definition: json_dom.h:536
enum_json_type json_type() const override
Definition: json_dom.h:528
Represents a JSON true or false value, type J_BOOLEAN here.
Definition: json_dom.h:1156
bool value() const
Definition: json_dom.h:1169
enum_json_type json_type() const override
Definition: json_dom.h:1162
Json_boolean(bool value)
Definition: json_dom.h:1160
Json_dom_ptr clone() const override
Make a deep clone.
Definition: json_dom.h:1171
bool m_v
false or true: represents the eponymous JSON literal
Definition: json_dom.h:1158
Abstract base class of all JSON container types (Json_object and Json_array).
Definition: json_dom.h:332
virtual void replace_dom_in_container(const Json_dom *oldv, Json_dom_ptr newv)=0
Replace oldv contained inside this container array or object) with newv.
MySQL DATE value.
Definition: json_dom.h:997
static void from_packed_to_key(const char *from, uchar *to)
Convert a packed date value to key string for indexing by SE.
Definition: json_dom.cc:1359
enum_json_type json_type() const override
Definition: json_dom.h:1006
void to_packed(char *dest) const
Convert the DATE value to the packed format used for storage.
Definition: json_dom.cc:1290
Json_date(const Date_val date)
Constructs an object to hold a MySQL date value.
Definition: json_dom.h:1004
static void from_packed(const char *from, Date_val *to)
Convert a packed date back to a date value.
Definition: json_dom.cc:1294
enum_field_types field_type() const override
Definition: json_dom.h:1014
const Date_val value() const
Definition: json_dom.h:1011
Date_val m_date
Holds the date value.
Definition: json_dom.h:1040
Json_dom_ptr clone() const override
Make a deep clone.
Definition: json_dom.cc:1286
MySQL temporal value that represents a DATETIME or TIMESTAMP value.
Definition: json_dom.h:1046
enum_field_types m_field_type
identifies which type of date/time
Definition: json_dom.h:1102
enum_json_type json_type() const override
Definition: json_dom.cc:1298
void to_packed(char *dest) const
Convert the datetime to the packed format used for storage.
Definition: json_dom.cc:1316
enum_field_types field_type() const override
Definition: json_dom.h:1070
Datetime_val m_t
holds the date/time value
Definition: json_dom.h:1101
const Datetime_val * value() const
Definition: json_dom.h:1068
static void from_packed(const char *from, enum_field_types ft, MYSQL_TIME *to)
Convert a packed datetime back to a MYSQL_TIME.
Definition: json_dom.cc:1321
Json_datetime(const Datetime_val &t, enum_field_types ft)
Constructs an object to hold a MySQL datetime value.
Definition: json_dom.h:1055
static void from_packed_to_key(const char *from, enum_field_types ft, uchar *to, uint8 dec)
Convert a packed datetime to key string for indexing by SE.
Definition: json_dom.cc:1327
Json_dom_ptr clone() const override
Make a deep clone.
Definition: json_dom.cc:1312
Represents a MySQL decimal number, type J_DECIMAL.
Definition: json_dom.h:743
Json_decimal(const my_decimal &value)
Definition: json_dom.cc:1227
my_decimal m_dec
holds the decimal number
Definition: json_dom.h:745
bool get_binary(char *dest) const
Get the binary representation of the wrapped my_decimal, so that this value can be stored inside of a...
Definition: json_dom.cc:1238
enum_json_type json_type() const override
Definition: json_dom.h:768
const my_decimal * value() const
Get a pointer to the MySQL decimal held by this object.
Definition: json_dom.h:777
static const int MAX_BINARY_SIZE
Definition: json_dom.h:748
static const char * get_encoded_binary(const char *bin)
Returns stored DECIMAL binary.
Definition: json_dom.h:809
Json_dom_ptr clone() const override
Make a deep clone.
Definition: json_dom.h:779
static bool convert_from_binary(const char *bin, size_t len, my_decimal *dec)
Convert a binary value produced by get_binary() back to a my_decimal.
Definition: json_dom.cc:1251
int binary_size() const
Get the number of bytes needed to store this decimal in a Json_opaque.
Definition: json_dom.cc:1230
static size_t get_encoded_binary_len(size_t length)
Returns length of stored DECIMAL binary.
Definition: json_dom.h:823
JSON DOM abstract base class.
Definition: json_dom.h:179
virtual bool is_scalar() const
Definition: json_dom.h:229
Json_container * parent() const
Get the parent dom to which this dom is attached.
Definition: json_dom.h:219
bool seek(const Json_seekable_path &path, size_t legs, Json_dom_vector *hits, bool auto_wrap, bool only_need_one)
Finds all of the json sub-documents which match the path expression.
Definition: json_dom.cc:2056
virtual ~Json_dom()=default
virtual uint32 depth() const =0
Compute the depth of a document.
Json_path get_location() const
Get the path location of this dom, measured from the outermost document it nests inside.
Definition: json_dom.cc:2029
static Json_dom_ptr parse(const char *text, size_t length, const JsonParseErrorHandler &error_handler, const JsonErrorHandler &depth_handler)
Parse Json text to DOM (using rapidjson).
Definition: json_dom.cc:644
void set_parent(Json_container *parent)
Set the parent dom to which this dom is attached.
Definition: json_dom.h:190
virtual bool is_number() const
Definition: json_dom.h:234
Json_container * m_parent
Parent pointer.
Definition: json_dom.h:326
virtual enum_json_type json_type() const =0
virtual Json_dom_ptr clone() const =0
Make a deep clone.
Represents a MySQL double JSON scalar (an extension of the ECMA number value), type J_DOUBLE.
Definition: json_dom.h:833
double m_f
holds the double value
Definition: json_dom.h:835
Json_dom_ptr clone() const override
Make a deep clone.
Definition: json_dom.h:841
enum_json_type json_type() const override
Definition: json_dom.h:839
double value() const
Return the double value held by this object.
Definition: json_dom.h:849
Json_double(double value)
Definition: json_dom.h:837
Represents a MySQL integer (64 bits signed) JSON scalar (an extension of the ECMA number value),...
Definition: json_dom.h:856
enum_json_type json_type() const override
Definition: json_dom.h:862
bool is_16bit() const
Definition: json_dom.h:873
Json_int(longlong value)
Definition: json_dom.h:860
Json_dom_ptr clone() const override
Make a deep clone.
Definition: json_dom.h:880
longlong m_i
holds the value
Definition: json_dom.h:858
bool is_32bit() const
Definition: json_dom.h:878
longlong value() const
Return the signed int held by this object.
Definition: json_dom.h:868
Represents a JSON null type (ECMA), type J_NULL here.
Definition: json_dom.h:920
Json_dom_ptr clone() const override
Make a deep clone.
Definition: json_dom.h:923
enum_json_type json_type() const override
Definition: json_dom.h:922
Abstract base class of all JSON number (ECMA) types (subclasses represent MySQL extensions).
Definition: json_dom.h:735
bool is_number() const final
Definition: json_dom.h:737
A wrapper over a JSON object which provides an interface that can be iterated over with a for-each lo...
Definition: json_dom.h:2004
Json_wrapper_object_iterator const_iterator
Definition: json_dom.h:2006
const_iterator end() const
Definition: json_dom.h:2012
Json_object_wrapper(const Json_wrapper &wrapper)
Definition: json_dom.h:2007
const_iterator begin() const
Definition: json_dom.h:2011
const_iterator cbegin() const
Definition: json_dom.h:2009
const_iterator cend() const
Definition: json_dom.h:2010
const Json_wrapper & m_wrapper
Definition: json_dom.h:2015
Represents a JSON container value of type "object" (ECMA), type J_OBJECT here.
Definition: json_dom.h:374
Json_dom_ptr clone() const override
Make a deep clone.
Definition: json_dom.cc:956
Json_object_map m_map
Map to hold the object elements.
Definition: json_dom.h:379
bool add_alias(std::string_view key, Json_dom *value)
Insert the value into the object.
Definition: json_dom.h:416
Json_object_map::const_iterator const_iterator
Constant iterator over the elements in the JSON object.
Definition: json_dom.h:485
enum_json_type json_type() const override
Definition: json_dom.h:383
bool consume(Json_object_ptr other)
Transfer all of the key/value pairs in the other object into this object.
Definition: json_dom.cc:901
Json_object()
Definition: json_dom.cc:431
const_iterator end() const
Returns a const_iterator that refers past the last element.
Definition: json_dom.h:491
size_t cardinality() const
Definition: json_dom.cc:944
uint32 depth() const override
Compute the depth of a document.
Definition: json_dom.cc:946
bool remove(std::string_view key)
Remove the child element addressed by key.
Definition: json_dom.cc:936
Json_dom * get(std::string_view key) const
Return the value at key.
Definition: json_dom.cc:925
bool add_clone(std::string_view key, const Json_dom *value)
Insert a clone of the value into the object.
Definition: json_dom.h:395
bool merge_patch(Json_object_ptr patch)
Implementation of the MergePatch function specified in RFC 7396:
Definition: json_dom.cc:968
void clear()
Remove all elements in the object.
Definition: json_dom.h:477
const_iterator begin() const
Returns a const_iterator that refers to the first element.
Definition: json_dom.h:488
void replace_dom_in_container(const Json_dom *oldv, Json_dom_ptr newv) override
Replace oldv contained inside this container array or object) with newv.
Definition: json_dom.cc:860
Represents a MySQL value opaquely, i.e.
Definition: json_dom.h:1114
enum_field_types type() const
Definition: json_dom.h:1144
Json_opaque(enum_field_types mytype, Args &&...args)
An opaque MySQL value.
Definition: json_dom.h:1131
size_t size() const
Definition: json_dom.h:1148
enum_json_type json_type() const override
Definition: json_dom.h:1134
Json_dom_ptr clone() const override
Make a deep clone.
Definition: json_dom.cc:1367
std::string m_val
Definition: json_dom.h:1117
const char * value() const
Definition: json_dom.h:1139
enum_field_types m_mytype
Definition: json_dom.h:1116
A JSON path expression.
Definition: json_path.h:350
A class that is capable of holding objects of any sub-type of Json_scalar.
Definition: json_dom.h:2035
Json_scalar * m_scalar_ptr
Pointer to the held scalar, or nullptr if no value is held.
Definition: json_dom.h:2065
void emplace(Args &&...args)
Construct a new Json_scalar value in this Json_scalar_holder.
Definition: json_dom.h:2078
Json_scalar * get()
Get a pointer to the held object, or nullptr if there is none.
Definition: json_dom.h:2069
Any_json_scalar m_buffer
The buffer in which the Json_scalar value is stored.
Definition: json_dom.h:2062
Abstract base class for all Json scalars.
Definition: json_dom.h:690
uint32 depth() const final
Compute the depth of a document.
Definition: json_dom.h:692
bool is_scalar() const final
Definition: json_dom.h:694
A path expression which can be used to seek to a position inside a JSON value.
Definition: json_path.h:295
Represents a JSON string value (ECMA), of type J_STRING here.
Definition: json_dom.h:700
std::string m_str
holds the string
Definition: json_dom.h:702
Json_string(Args &&...args)
Definition: json_dom.h:709
enum_json_type json_type() const override
Definition: json_dom.h:712
Json_dom_ptr clone() const override
Make a deep clone.
Definition: json_dom.h:714
size_t size() const
Get the number of characters in the string.
Definition: json_dom.h:728
const std::string & value() const
Get the reference to the value of the JSON string.
Definition: json_dom.h:722
Represents a MySQL temporal value (DATE, TIME, DATETIME or TIMESTAMP) - an extension to the ECMA set ...
Definition: json_dom.h:933
virtual enum_field_types field_type() const =0
Json_temporal()
Definition: json_dom.h:935
static const size_t PACKED_SIZE
Datetimes are packed in eight bytes.
Definition: json_dom.h:944
MySQL TIME value.
Definition: json_dom.h:948
void to_packed(char *dest) const
Convert the TIME value to the packed format used for storage.
Definition: json_dom.cc:1278
static void from_packed_to_key(const char *from, uchar *to, uint8 dec)
Convert a packed time value to key string for indexing by SE.
Definition: json_dom.cc:1353
Time_val m_time
Holds the time value.
Definition: json_dom.h:993
enum_json_type json_type() const override
Definition: json_dom.h:957
Json_time(const Time_val time)
Constructs an object to hold a MySQL time value.
Definition: json_dom.h:955
Time_val value() const
Definition: json_dom.h:962
static void from_packed(const char *from, Time_val *to)
Convert a packed time back to a time value.
Definition: json_dom.cc:1282
Json_dom_ptr clone() const override
Make a deep clone.
Definition: json_dom.cc:1274
enum_field_types field_type() const override
Definition: json_dom.h:965
Represents a MySQL integer (64 bits unsigned) JSON scalar (an extension of the ECMA number value),...
Definition: json_dom.h:888
enum_json_type json_type() const override
Definition: json_dom.h:894
Json_uint(ulonglong value)
Definition: json_dom.h:892
Json_dom_ptr clone() const override
Make a deep clone.
Definition: json_dom.h:914
ulonglong value() const
Return the unsigned int held by this object.
Definition: json_dom.h:900
ulonglong m_i
holds the value
Definition: json_dom.h:890
bool is_16bit() const
Definition: json_dom.h:906
bool is_32bit() const
Definition: json_dom.h:912
Helper class for building a hash key.
Definition: json_hash.h:45
Class that iterates over all members of a JSON object that is wrapped in a Json_wrapper instance.
Definition: json_dom.h:1922
bool operator==(const Json_wrapper_object_iterator &other) const
Checks two iterators for equality.
Definition: json_dom.h:1966
const json_binary::Value * m_binary_value
The binary JSON object being iterated over, or nullptr for DOMs.
Definition: json_dom.h:1989
const value_type * pointer
Definition: json_dom.h:1927
size_t m_current_element_index
The index of the current member in the binary JSON object.
Definition: json_dom.h:1991
std::forward_iterator_tag iterator_category
Definition: json_dom.h:1929
const Json_wrapper_object_iterator operator++(int)
Advances the iterator to the next element and returns an iterator that points to the current element ...
Definition: json_dom.h:1959
bool is_dom() const
Returns true if iterating over a DOM.
Definition: json_dom.h:1995
void initialize_current_member()
Fill m_current_member with the key and value of the current member.
Definition: json_dom.cc:1384
const value_type & reference
Definition: json_dom.h:1926
bool m_current_member_initialized
True if m_current_member is initialized.
Definition: json_dom.h:1987
bool operator!=(const Json_wrapper_object_iterator &other) const
Checks two iterators for inequality.
Definition: json_dom.h:1972
std::pair< std::string_view, Json_wrapper > value_type
Definition: json_dom.h:1925
Json_object::const_iterator m_iter
Iterator pointing to the current member in the JSON DOM object.
Definition: json_dom.h:1993
pointer operator->()
Definition: json_dom.h:1976
Json_wrapper_object_iterator & operator++()
Advances the iterator to the next element.
Definition: json_dom.h:1946
ptrdiff_t difference_type
Definition: json_dom.h:1928
value_type m_current_member
Pair holding the key and value of the member pointed to by the iterator.
Definition: json_dom.h:1985
Json_wrapper_object_iterator()=default
Forward iterators must be default constructible.
reference operator*()
Definition: json_dom.h:1981
Abstraction for accessing JSON values irrespective of whether they are (started out as) binary JSON v...
Definition: json_dom.h:1268
const char * get_data() const
Get a pointer to the data of a JSON string or JSON opaque value.
Definition: json_dom.cc:1907
const Json_dom * get_dom() const
Gets a pointer to the wrapped Json_dom object, if this wrapper holds a DOM.
Definition: json_dom.h:1402
void make_hash_key_common(Json_wrapper_hasher &hash_key) const
Definition: json_dom.cc:3481
bool to_pretty_string(String *buffer, const char *func_name, const JsonErrorHandler &depth_handler) const
Format the JSON value to an external JSON string in buffer in the format of ISO/IEC 10646.
Definition: json_dom.cc:1819
void set_alias()
Only meaningful iff the wrapper encapsulates a DOM.
Definition: json_dom.h:1328
size_t get_data_length() const
Get the length to the data of a JSON string or JSON opaque value.
Definition: json_dom.cc:1917
bool get_decimal_data(my_decimal *d) const
Get the MySQL representation of a JSON decimal value.
Definition: json_dom.cc:1927
ulonglong get_uint() const
Get the value of a JSON unsigned integer number.
Definition: json_dom.cc:1953
longlong coerce_int(const JsonCoercionHandler &error_handler, bool *err, bool *unsigned_flag) const
Extract an int (signed or unsigned) from the JSON if possible coercing if need be.
Definition: json_dom.cc:2820
bool get_boolean() const
Get a boolean value (a JSON true or false literal).
Definition: json_dom.cc:2021
enum_field_types field_type() const
Return the MYSQL type of the opaque value, see type().
Definition: json_dom.cc:1873
bool to_string(String *buffer, bool json_quoted, const char *func_name, const JsonErrorHandler &depth_handler) const
Format the JSON value to an external JSON string in buffer in the format of ISO/IEC 10646.
Definition: json_dom.cc:1811
void remove_duplicates(const CHARSET_INFO *cs=nullptr)
Remove duplicate values.
Definition: json_dom.cc:3794
bool m_alias
If true, don't deallocate m_dom_value in destructor.
Definition: json_dom.h:1279
bool coerce_time(const JsonCoercionHandler &error_handler, const JsonCoercionDeprecatedHandler &deprecation_checker, Time_val *time) const
Extract a time value from the JSON if possible, coercing if need be.
Definition: json_dom.cc:3033
const char * get_date_packed(char *buffer) const
Definition: json_dom.cc:2010
Json_dom * to_dom()
Get the wrapped contents in DOM form.
Definition: json_dom.cc:1471
bool coerce_datetime(const JsonCoercionHandler &error_handler, const JsonCoercionDeprecatedHandler &deprecation_checker, Datetime_val *dt, my_time_flags_t flags=0) const
Extract a datetime from the JSON if possible, coercing if need be.
Definition: json_dom.cc:3000
longlong get_int() const
Get the value of a JSON signed integer number.
Definition: json_dom.cc:1945
const char * get_datetime_packed(char *buffer) const
Get the wrapped datetime value in the packed format.
Definition: json_dom.cc:1988
Json_wrapper operator[](size_t index) const
If this wrapper holds a JSON array, get an array value by indexing into the array.
Definition: json_dom.cc:1893
void get_date(Date_val *date) const
Get the value of a JSON date value.
Definition: json_dom.cc:1979
bool m_is_dom
Wraps a DOM iff true.
Definition: json_dom.h:1284
const json_binary::Value & get_binary_value() const
Gets the wrapped json_binary::Value object, if this wrapper holds a binary JSON value.
Definition: json_dom.h:1412
void get_datetime(MYSQL_TIME *t) const
Get the value of a JSON date/time value.
Definition: json_dom.cc:1961
bool attempt_binary_update(const Field_json *field, const Json_seekable_path &path, Json_wrapper *new_value, bool replace, String *result, bool *partially_updated, bool *replaced_path)
Attempt a binary partial update by replacing the value at path with new_value.
Definition: json_dom.cc:3567
longlong coerce_int(const JsonCoercionHandler &error_handler) const
Shorthand for coerce_int(error_handler, nullptr, nullptr).
Definition: json_dom.h:1727
enum_json_type type() const
Return the type of the wrapped JSON value.
Definition: json_dom.cc:1840
void dbug_print(const char *message, const JsonErrorHandler &depth_handler) const
Print this JSON document to the debug trace.
Definition: json_dom.cc:1827
Json_wrapper()
Create an empty wrapper.
Definition: json_dom.h:1301
bool to_binary(const JsonSerializationErrorHandler &error_handler, String *str) const
Get the wrapped contents in binary value form.
Definition: json_dom.cc:1491
int compare(const Json_wrapper &other, const CHARSET_INFO *cs=nullptr) const
Compare this JSON value to another JSON value.
Definition: json_dom.cc:2583
void sort(const CHARSET_INFO *cs=nullptr)
Sort contents.
Definition: json_dom.cc:3789
bool get_free_space(const JsonSerializationErrorHandler &error_handler, size_t *space) const
Calculate the amount of unused space inside a JSON binary value.
Definition: json_dom.cc:3556
ulonglong make_hash_key(ulonglong hash_val) const
Make a hash key that can be used by sql_executor.cc/unique_hash in order to support SELECT DISTINCT.
Definition: json_dom.cc:3475
my_decimal * coerce_decimal(const JsonCoercionHandler &error_handler, my_decimal *decimal_value, bool *err) const
Extract a decimal from the JSON if possible, coercing if need be.
Definition: json_dom.cc:2942
bool seek(const Json_seekable_path &path, size_t legs, Json_wrapper_vector *hits, bool auto_wrap, bool only_need_one)
Finds all of the json sub-documents which match the path expression.
Definition: json_dom.cc:2285
Json_wrapper & operator=(const Json_wrapper &old)
Assignment operator.
Definition: json_dom.cc:1463
void get_time(Time_val *time) const
Get the value of a JSON time value.
Definition: json_dom.cc:1970
bool is_binary_backed_by(const String *str) const
Check if the wrapped JSON document is a binary value (a json_binary::Value), and if that binary is po...
Definition: json_dom.h:1450
double get_double() const
Get the value of a JSON double number.
Definition: json_dom.cc:1937
size_t make_sort_key(uchar *to, size_t length) const
Make a sort key that can be used by filesort to order JSON values.
Definition: json_dom.cc:3351
bool binary_remove(const Field_json *field, const Json_seekable_path &path, String *result, bool *found_path)
Remove a path from a binary JSON document.
Definition: json_dom.cc:3712
double coerce_real(const JsonCoercionHandler &error_handler) const
Shorthand for coerce_real(error_handler, nullptr).
Definition: json_dom.h:1741
size_t length() const
Compute the length of a document.
Definition: json_dom.cc:2321
Json_wrapper lookup(std::string_view key) const
If this wrapper holds a JSON object, get the value corresponding to the member key.
Definition: json_dom.cc:1881
struct Json_wrapper::@42::@44 m_dom
The DOM representation, only used if m_is_dom is true.
bool empty() const
A Wrapper is defined to be empty if it is passed a NULL value with the constructor for JSON dom,...
Definition: json_dom.h:1379
Json_wrapper(Json_dom_ptr dom_value)
Wrap the supplied DOM value.
Definition: json_dom.h:1319
my_decimal * coerce_decimal(const JsonCoercionHandler &error_handler, my_decimal *decimal_value) const
Shorthand for coerce_decimal(error_handler, decimal_value, nullptr).
Definition: json_dom.h:1757
~Json_wrapper()
Definition: json_dom.cc:1436
Json_dom * m_value
Definition: json_dom.h:1277
bool is_dom() const
Does this wrapper contain a DOM?
Definition: json_dom.h:1387
double coerce_real(const JsonCoercionHandler &error_handler, bool *err) const
Extract a real from the JSON if possible, coercing if need be.
Definition: json_dom.cc:2894
const char * get_time_packed(char *buffer) const
Definition: json_dom.cc:1999
bool coerce_date(const JsonCoercionHandler &error_handler, const JsonCoercionDeprecatedHandler &deprecation_checker, Date_val *date, my_time_flags_t flags=0) const
Extract a date from the JSON if possible, coercing if need be.
Definition: json_dom.cc:3066
Json_dom_ptr clone_dom() const
Get the wrapped contents in DOM form.
Definition: json_dom.cc:1483
json_binary::Value m_value
The binary representation, only used if m_is_dom is false.
Definition: json_dom.h:1282
Malloc_allocator is a C++ STL memory allocator based on my_malloc/my_free.
Definition: malloc_allocator.h:63
Using this class is fraught with peril, and you need to be very careful when doing so.
Definition: sql_string.h:169
Time_val is a temporal type that represents only time.
Definition: my_temporal.h:57
Class used for reading JSON values that are stored in the binary format.
Definition: json_binary.h:234
my_decimal class limits 'decimal_t' type to what we need in MySQL.
Definition: my_decimal.h:97
This file contains the field type.
enum_field_types
Column types for MySQL Note: Keep include/mysql/components/services/bits/stored_program_bits....
Definition: field_types.h:55
@ MYSQL_TYPE_TIME
Definition: field_types.h:67
@ MYSQL_TYPE_DATE
Definition: field_types.h:66
static const std::string dec("DECRYPTION")
static int flags[50]
Definition: hp_test1.cc:40
static uint16 key1[1001]
Definition: hp_test2.cc:50
#define T
Definition: jit_executor_value.cc:373
This file specifies the interface for serializing JSON values into binary representation,...
constexpr uchar JSON_KEY_OBJECT
Definition: json_dom.h:1250
bool json_wrapper_contains(const Json_wrapper &doc_wrapper, const Json_wrapper &containee_wr, bool *result)
Check if one Json_wrapper contains all the elements of another Json_wrapper.
Definition: json_dom.cc:3828
std::unique_ptr< Json_dom > Json_dom_ptr
Definition: json_dom.h:67
Prealloced_array< Json_dom *, 16 > Json_dom_vector
Definition: json_dom.h:65
constexpr uchar JSON_KEY_TRUE
Definition: json_dom.h:1253
constexpr uchar JSON_KEY_FALSE
Definition: json_dom.h:1252
std::unique_ptr< T > create_dom_ptr(Args &&...args)
Allocate a new Json_dom object and return a std::unique_ptr which points to it.
Definition: json_dom.h:142
std::map< std::string, Json_dom_ptr, Json_key_comparator, Malloc_allocator< std::pair< const std::string, Json_dom_ptr > > > Json_object_map
A type used to hold JSON object elements in a map, see the Json_object class.
Definition: json_dom.h:368
constexpr uchar JSON_KEY_ARRAY
Definition: json_dom.h:1251
bool is_valid_json_syntax(const char *text, size_t length)
Check if a string contains valid JSON text, without generating a Json_dom representation of the docum...
std::unique_ptr< Json_object > Json_object_ptr
Definition: json_dom.h:69
enum_json_type
Json values in MySQL comprises the stand set of JSON values plus a MySQL specific set.
Definition: json_dom.h:112
std::string_view json_type_name(const Json_wrapper &doc)
Returns the name of the type of the JSON document contained in "doc".
Definition: json_dom.cc:4033
constexpr uchar JSON_KEY_NULL
Definition: json_dom.h:1249
std::unique_ptr< Json_array > Json_array_ptr
Definition: json_dom.h:68
bool double_quote(const char *cptr, size_t length, String *buf)
Perform quoting on a JSON string to make an external representation of it.
Definition: json_dom.cc:1195
const size_t kMaxJsonTypeNameLength
The maximum length of the type name returned from JSON_TYPE.
Definition: json_dom.cc:4028
Prealloced_array< Json_wrapper, 16 > Json_wrapper_vector
Definition: json_dom.h:62
Json_dom_ptr merge_doms(Json_dom_ptr left, Json_dom_ptr right)
Merge two doms.
Definition: json_dom.cc:185
std::function< void(MYSQL_TIME_STATUS &status)> JsonCoercionDeprecatedHandler
Definition: json_error_handler.h:40
std::function< void(const char *target_type, int error_code)> JsonCoercionHandler
Definition: json_error_handler.h:38
std::function< void()> JsonErrorHandler
Definition: json_error_handler.h:36
std::function< void(const char *parse_err, size_t err_offset)> JsonParseErrorHandler
Definition: json_error_handler.h:35
Functions for reading and storing in machine-independent format.
std::uint32_t ha_checksum
Definition: my_checksum.h:106
It is interface module to fixed precision decimals library.
static constexpr int DECIMAL_MAX_FIELD_SIZE
maximum size of packet length.
Definition: my_decimal.h:83
Some integer typedefs for easier portability.
#define UINT_MAX16
Definition: my_inttypes.h:85
unsigned long long int ulonglong
Definition: my_inttypes.h:56
uint8_t uint8
Definition: my_inttypes.h:63
unsigned char uchar
Definition: my_inttypes.h:52
#define INT_MAX16
Definition: my_inttypes.h:84
#define INT_MIN32
Definition: my_inttypes.h:77
long long int longlong
Definition: my_inttypes.h:55
#define INT_MAX32
Definition: my_inttypes.h:78
#define INT_MIN16
Definition: my_inttypes.h:83
uint32_t uint32
Definition: my_inttypes.h:67
#define UINT_MAX32
Definition: my_inttypes.h:79
Interface for low level time utilities.
unsigned int my_time_flags_t
Flags to str_to_datetime and int_to_datetime.
Definition: my_time.h:87
static char * path
Definition: mysqldump.cc:150
static bool replace
Definition: mysqlimport.cc:70
void copy(Shards< COUNT > &dst, const Shards< COUNT > &src) noexcept
Copy the counters, overwrite destination.
Definition: ut0counter.h:354
std::string str(const mysqlrouter::ConfigGenerator::Options::Endpoint &ep)
Definition: config_generator.cc:1077
Definition: buf0block_hint.cc:30
Definition: commit_order_queue.h:34
bool length(const dd::Spatial_reference_system *srs, const Geometry *g1, double *length, bool *null) noexcept
Computes the length of linestrings and multilinestrings.
Definition: length.cc:76
void right(std::string *to_trim)
Definition: trim.h:41
bool index(const std::string &value, const String &search_for, uint32_t *idx)
Definition: contains.h:76
void left(std::string *to_trim)
Definition: trim.h:35
static Value err()
Create a Value object that represents an error condition.
Definition: json_binary.cc:943
ValueType value(const std::optional< ValueType > &v)
Definition: gtid.h:83
const char * begin(const char *const c)
Definition: base64.h:44
size_t size(const char *const c)
Definition: base64.h:46
mutable_buffer buffer(void *p, size_t n) noexcept
Definition: buffer.h:418
Define std::hash<Gtid>.
Definition: gtid.h:355
std::map< Key, Value, Compare, ut::allocator< std::pair< const Key, Value > > > map
Specialization of map which uses ut_allocator.
Definition: ut0new.h:2898
required string key
Definition: replication_asynchronous_connection_failover.proto:60
const uchar * hash_key(const uchar *el, size_t *length)
Definition: sql_auth_cache.cc:3309
Definition: m_ctype.h:421
A comparator that is used for ordering keys in a Json_object.
Definition: json_dom.h:351
bool operator()(std::string_view key1, std::string_view key2) const
Compare two keys from a JSON object and determine whether or not the first key is less than the secon...
Definition: json_dom.cc:1025
void is_transparent
Definition: json_dom.h:357
Definition: mysql_time.h:82
Definition: result.h:30
Union of all concrete subclasses of Json_scalar.
Definition: json_dom.h:2037
Json_null m_null
Definition: json_dom.h:2044
Json_date m_date
Definition: json_dom.h:2046
Json_time m_time
Definition: json_dom.h:2045
Json_boolean m_boolean
Definition: json_dom.h:2043
Json_decimal m_decimal
Definition: json_dom.h:2039
Json_datetime m_datetime
Definition: json_dom.h:2047
Json_double m_double
Definition: json_dom.h:2042
Json_opaque m_opaque
Definition: json_dom.h:2048
~Any_json_scalar()
Destructor which delegates to Json_scalar's virtual destructor.
Definition: json_dom.h:2052
Json_int m_int
Definition: json_dom.h:2040
Any_json_scalar()
Constructor which initializes the union to hold a Json_null value.
Definition: json_dom.h:2050
Json_uint m_uint
Definition: json_dom.h:2041
Json_string m_string
Definition: json_dom.h:2038