MySQL 9.3.0
Source Code Documentation
query_attributes.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2017, 2025, 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, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
19 * the GNU General Public License, version 2.0, 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 Foundation, Inc.,
23 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 */
25
26#ifndef ROUTER_SRC_JIT_EXECUTOR_SRC_DATABASE_QUERY_ATTRIBUTES_H_
27#define ROUTER_SRC_JIT_EXECUTOR_SRC_DATABASE_QUERY_ATTRIBUTES_H_
28
29#include <field_types.h>
30#include <mysql_time.h>
31#include <functional>
32#include <memory>
33#include <string>
34#include <vector>
35
37
38namespace shcore {
39namespace polyglot {
40namespace database {
41
43 virtual ~IQuery_attribute_value() = default;
44};
45
47 public:
49 explicit Classic_query_attribute(int64_t val);
50 explicit Classic_query_attribute(uint64_t val);
51 explicit Classic_query_attribute(double val);
52 explicit Classic_query_attribute(const std::string &val);
54
56 *this = std::move(other);
57 }
58
60 *this = other;
61 }
62
65
67
68 private:
69 void update_data_ptr();
70 friend class Session;
71 union {
72 int64_t i;
73 uint64_t ui;
74 std::string *s;
75 double d;
77
80 void *data_ptr = nullptr;
81 unsigned long size = 0;
82 bool is_null = true;
83 int flags = 0;
84};
85
86/**
87 * @brief Normalized query attribute.
88 *
89 * This class represents a normalized query attribute which in general consist
90 * of a name/value pair.
91 *
92 * The value must be valid for the target connector, so the
93 * IQuery_attribute_value interface is used at this level.
94 */
96 Query_attribute(std::string n,
97 std::unique_ptr<IQuery_attribute_value> v) noexcept;
98
99 std::string name;
100 std::unique_ptr<IQuery_attribute_value> value;
101};
102
103/**
104 * @brief Cache for query attributes to be associated to the next user SQL
105 * executed.
106 *
107 * This class serves as container and validator for the query attributes
108 * coming from the following API call
109 *
110 * - setQueryAttributes() API
111 *
112 * Since the defined attributes are meant to be associated to the next user
113 * SQL executed, the data needs to be cached while that happens.
114 */
116 public:
117 bool set(const std::string &name, const shcore::Value &value);
118 bool set(const shcore::Dictionary_t &attributes);
119 void handle_errors(bool raise_error = true);
120 void clear();
121 std::vector<Query_attribute> get_query_attributes(
122 const std::function<std::unique_ptr<IQuery_attribute_value>(
123 const shcore::Value &)> &translator_cb) const;
124
125 private:
126 // Real store of valid query attributes
127 std::unordered_map<std::string, shcore::Value> m_store;
128
129 // Honors the order of the attributes when given through \query_attributes
130 std::vector<std::string> m_order;
131
132 // Used to store the list of invalid attributes
133 std::vector<std::string> m_exceeded;
134 std::vector<std::string> m_invalid_names;
135 std::vector<std::string> m_invalid_value_length;
136 std::vector<std::string> m_unsupported_type;
137};
138
139} // namespace database
140} // namespace polyglot
141} // namespace shcore
142
143#endif // ROUTER_SRC_JIT_EXECUTOR_SRC_DATABASE_QUERY_ATTRIBUTES_H_
Cache for query attributes to be associated to the next user SQL executed.
Definition: query_attributes.h:115
void clear()
Definition: query_attributes.cc:266
std::vector< std::string > m_unsupported_type
Definition: query_attributes.h:136
std::vector< std::string > m_exceeded
Definition: query_attributes.h:133
std::unordered_map< std::string, shcore::Value > m_store
Definition: query_attributes.h:127
std::vector< std::string > m_order
Definition: query_attributes.h:130
std::vector< Query_attribute > get_query_attributes(const std::function< std::unique_ptr< IQuery_attribute_value >(const shcore::Value &)> &translator_cb) const
Definition: query_attributes.cc:275
std::vector< std::string > m_invalid_names
Definition: query_attributes.h:134
bool set(const std::string &name, const shcore::Value &value)
Definition: query_attributes.cc:158
std::vector< std::string > m_invalid_value_length
Definition: query_attributes.h:135
void handle_errors(bool raise_error=true)
Definition: query_attributes.cc:223
Definition: session.h:59
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_NULL
Definition: field_types.h:62
ValueType value(const std::optional< ValueType > &v)
Definition: gtid.h:83
Definition: file_system_exceptions.h:34
Value::Map_type_ref Dictionary_t
Definition: jit_executor_value.h:430
Definition: gcs_xcom_synode.h:64
case opt name
Definition: sslopt-case.h:29
Definition: mysql_time.h:82
Pointer to a function that may be implemented in any language.
Definition: jit_executor_value.h:130
int flags
Definition: query_attributes.h:83
void * data_ptr
Definition: query_attributes.h:80
void update_data_ptr()
Definition: query_attributes.cc:97
double d
Definition: query_attributes.h:75
MYSQL_TIME t
Definition: query_attributes.h:76
bool is_null
Definition: query_attributes.h:82
~Classic_query_attribute()
Definition: query_attributes.cc:91
uint64_t ui
Definition: query_attributes.h:73
unsigned long size
Definition: query_attributes.h:81
std::string * s
Definition: query_attributes.h:74
union shcore::polyglot::database::Classic_query_attribute::@35 value
Classic_query_attribute(const Classic_query_attribute &other)
Definition: query_attributes.h:59
Classic_query_attribute & operator=(const Classic_query_attribute &other)
Definition: query_attributes.cc:121
enum_field_types type
Definition: query_attributes.h:79
int64_t i
Definition: query_attributes.h:72
Normalized query attribute.
Definition: query_attributes.h:95
Query_attribute(std::string n, std::unique_ptr< IQuery_attribute_value > v) noexcept
Definition: query_attributes.cc:43
std::unique_ptr< IQuery_attribute_value > value
Definition: query_attributes.h:100
std::string name
Definition: query_attributes.h:99
int n
Definition: xcom_base.cc:509