MySQL 8.4.0
Source Code Documentation
sql_value.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2022, 2024, Oracle and/or its affiliates.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License, version 2.0,
6 as published by the Free Software Foundation.
7
8 This program is designed to work with certain software (including
9 but not limited to OpenSSL) that is licensed under separate terms,
10 as designated in a particular file or component or in included license
11 documentation. The authors of MySQL hereby grant you an additional
12 permission to link the program and your derivative works with the
13 separately licensed software that they have either included with
14 the program or referenced in the documentation.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24*/
25
26#ifndef ROUTING_SQL_VALUE_INCLUDED
27#define ROUTING_SQL_VALUE_INCLUDED
28
29#include <optional>
30#include <string>
31
32/**
33 * a nullable SQL value.
34 *
35 * For now, supports NULL and strings.
36 *
37 * Note: In the future, may switch to std::variant<> or
38 * similar to cover more types if needed.
39 */
40class Value {
41 public:
42 using value_type = std::optional<std::string>;
43
44 Value(value_type v) : value_{std::move(v)} {}
45
46 const value_type &value() const & { return value_; }
47
48 /**
49 * "NULL" or the quoted string.
50 */
51 std::string to_string() const;
52
53 private:
55};
56
57inline bool operator==(const Value &lhs, const Value &rhs) {
58 return lhs.value() == rhs.value();
59}
60
61inline bool operator==(const Value &lhs, const std::string_view &rhs) {
62 if (!lhs.value()) return false;
63
64 return std::string_view(*(lhs.value())) == rhs;
65}
66
67inline bool operator!=(const Value &lhs, const Value &rhs) {
68 return !(lhs == rhs);
69}
70
71inline bool operator!=(const Value &lhs, const std::string_view &rhs) {
72 return !(lhs == rhs);
73}
74
75#endif
a nullable SQL value.
Definition: sql_value.h:40
const value_type & value() const &
Definition: sql_value.h:46
std::optional< std::string > value_type
Definition: sql_value.h:42
Value(value_type v)
Definition: sql_value.h:44
std::string to_string() const
"NULL" or the quoted string.
Definition: sql_value.cc:93
value_type value_
Definition: sql_value.h:54
Definition: gcs_xcom_synode.h:64
bool operator==(const Value &lhs, const Value &rhs)
Definition: sql_value.h:57
bool operator!=(const Value &lhs, const Value &rhs)
Definition: sql_value.h:67