MySQL 9.3.0
Source Code Documentation
to_sqlstring.h
Go to the documentation of this file.
1/* Copyright (c) 2022, 2025, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is designed to work with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23*/
24
25#ifndef ROUTER_SRC_REST_MRS_SRC_HELPER_TO_SQLSTRING_H_
26#define ROUTER_SRC_REST_MRS_SRC_HELPER_TO_SQLSTRING_H_
27
28#include <sstream>
29#include <string>
30
31#include <my_rapidjson_size_t.h>
32#include <rapidjson/document.h>
33
36#include "helper/to_string.h"
39
41
42namespace helper {
43namespace json {
44
45template <typename Stream, typename Value>
46Stream &to_stream(Stream &stream, const rapidjson::Value &v,
47 const Value &k_true, const Value &k_false) {
48 if (v.IsNull()) {
49 stream << nullptr;
50 } else if (v.IsBool()) {
51 stream << (v.GetBool() ? k_true : k_false);
52 } else if (v.IsString()) {
53 stream << v.GetString();
54 } else if (v.IsUint()) {
55 stream << v.GetUint();
56 } else if (v.IsInt()) {
57 stream << v.GetInt();
58 } else if (v.IsUint64()) {
59 stream << v.GetUint64();
60 } else if (v.IsInt64()) {
61 stream << v.GetInt64();
62 } else if (v.IsFloat()) {
63 stream << v.GetFloat();
64 } else if (v.IsDouble()) {
65 stream << v.GetDouble();
66 } else if (v.IsArray() || v.IsObject()) {
67 stream << to_string(v);
68 } else {
69 using namespace std::string_literals;
70 throw std::runtime_error(
71 "JSON value to SQLString, received unsupported type:"s +
72 std::to_string(v.GetType()) + ".");
73 }
74
75 return stream;
76}
77
78namespace sql {
79
80// To not keep this function in the same namespace as to_string
82 const rapidjson::Value &v);
83
86 const std::pair<rapidjson::Value *, mrs::database::entry::ColumnType> &v);
87
88} // namespace sql
89} // namespace json
90} // namespace helper
91
92#endif // ROUTER_SRC_REST_MRS_SRC_HELPER_TO_SQLSTRING_H_
Definition: utils_sqlstring.h:67
static std::string to_string(const LEX_STRING &str)
Definition: lex_string.h:50
Define rapidjson::SizeType to be std::uint64_t.
mysqlrouter::sqlstring & operator<<(mysqlrouter::sqlstring &sql, const rapidjson::Value &v)
Definition: to_sqlstring.cc:39
std::string to_string(const rapidjson::Value &value)
Definition: rapid_json_to_text.h:67
Stream & to_stream(Stream &stream, const rapidjson::Value &v, const Value &k_true, const Value &k_false)
Definition: to_sqlstring.h:46
Definition: cache.h:33
const std::string k_true
Definition: to_string.h:34
const std::string k_false
Definition: to_string.h:35