MySQL 9.3.0
Source Code Documentation
select.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2023, 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,
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 ROUTER_SRC_MYSQL_REST_SERVICE_INCLUDE_MRS_DATABASE_JSON_MAPPER_VIEW_SELECT_H_
27#define ROUTER_SRC_MYSQL_REST_SERVICE_INCLUDE_MRS_DATABASE_JSON_MAPPER_VIEW_SELECT_H_
28
29#include <map>
30#include <memory>
31#include <set>
32#include <string>
33#include <vector>
37
38namespace mrs {
39namespace database {
40
41// Mapping between column names to SQL values (strings must be 'quoted', binary
42// values must be quoted as _binary'string')
43using PrimaryKeyColumnValues = std::map<std::string, mysqlrouter::sqlstring>;
44
45using ColumnValues = std::vector<mysqlrouter::sqlstring>;
46
47enum class RowLockType { NONE, FOR_UPDATE };
48
49namespace dv {
50
55
57
59 const PrimaryKeyColumnValues &f);
60
62 const std::string &table_name,
64 bool omit_row_owner = false);
65
68 bool omit_row_owner = false);
69
71 const ForeignKeyReference &fk);
72
74 public:
76 std::vector<std::string> filter);
78
79 bool is_included(std::string_view prefix, std::string_view field) const;
80 bool is_filter_configured() const;
81
82 private:
83 std::set<std::string, std::less<>> filter_;
84 bool m_exclusive = true;
85
86 bool is_parent_included(std::string_view prefix) const;
87};
88
90 public:
91 explicit JsonQueryBuilder(const ObjectFieldFilter &filter,
92 const ObjectRowOwnership &row_owner = {},
93 bool for_update = false,
94 bool for_bigins_as_string = false)
95 : filter_(filter),
96 row_owner_(row_owner),
98 bigins_as_string_{for_bigins_as_string} {}
99
100 void process_view(std::shared_ptr<entry::JsonMapping> view);
101
103 mysqlrouter::sqlstring q{"SELECT JSON_OBJECT(?) FROM ?"};
104
105 q << select_items() << from_clause();
106
107 if (for_update_) q.append_preformatted(" FOR UPDATE NOWAIT");
108
109 return q;
110 }
111
113 mysqlrouter::sqlstring q{"SELECT ?.?(?)"};
114
116
117 if (for_update_) q.append_preformatted(" FOR UPDATE NOWAIT");
118
119 return q;
120 }
121
124
125 private:
128 std::shared_ptr<Table> parent_table_;
129 std::shared_ptr<Table> table_;
130 std::string m_path_prefix;
132 bool for_update_ = false;
133 bool bigins_as_string_ = false;
134
135 void process_table(std::shared_ptr<Table> parent_table,
136 std::shared_ptr<Table> table,
137 const std::string &path_prefix);
138
141 const ForeignKeyReference &fk) const;
142
144 const ForeignKeyReference &ref) const;
145
147
148 void add_column_field(const Column &column);
150};
151
152} // namespace dv
153} // namespace database
154} // namespace mrs
155
156#endif // ROUTER_SRC_MYSQL_REST_SERVICE_INCLUDE_MRS_DATABASE_JSON_MAPPER_VIEW_SELECT_H_
Definition: field.h:573
Definition: object_row_ownership.h:45
const ObjectFieldFilter & filter_
Definition: select.h:126
mysqlrouter::sqlstring from_clause() const
Definition: select.cc:283
bool for_update_
Definition: select.h:132
mysqlrouter::sqlstring query() const
Definition: select.h:102
void process_table(std::shared_ptr< Table > parent_table, std::shared_ptr< Table > table, const std::string &path_prefix)
Definition: select.cc:162
std::string m_path_prefix
Definition: select.h:130
mysqlrouter::sqlstring make_subquery(const ForeignKeyReference &ref) const
Definition: select.cc:212
void add_reference_field(const ForeignKeyReference &fk)
Definition: select.cc:273
JsonQueryBuilder(const ObjectFieldFilter &filter, const ObjectRowOwnership &row_owner={}, bool for_update=false, bool for_bigins_as_string=false)
Definition: select.h:91
const mysqlrouter::sqlstring & select_items() const
Definition: select.h:122
mysqlrouter::sqlstring make_subselect_where(const ForeignKeyReference &ref) const
Definition: select.cc:207
mysqlrouter::sqlstring m_select_items
Definition: select.h:131
std::shared_ptr< Table > table_
Definition: select.h:129
mysqlrouter::sqlstring subquery_object(const ForeignKeyReference &fk) const
Definition: select.cc:179
mysqlrouter::sqlstring query_one(const PrimaryKeyColumnValues &pk) const
Definition: select.h:112
void add_column_field(const Column &column)
Definition: select.cc:264
void process_view(std::shared_ptr< entry::JsonMapping > view)
Definition: select.cc:154
bool bigins_as_string_
Definition: select.h:133
const ObjectRowOwnership & row_owner_
Definition: select.h:127
std::shared_ptr< Table > parent_table_
Definition: select.h:128
mysqlrouter::sqlstring subquery_object_array(const ForeignKeyReference &fk) const
Definition: select.cc:193
bool is_included(std::string_view prefix, std::string_view field) const
Definition: select.cc:365
static ObjectFieldFilter from_object(const Table &table)
Definition: select.cc:336
bool is_parent_included(std::string_view prefix) const
Definition: select.cc:345
bool m_exclusive
Definition: select.h:84
std::set< std::string, std::less<> > filter_
Definition: select.h:83
bool is_filter_configured() const
Definition: select.cc:386
static ObjectFieldFilter from_url_filter(const Table &table, std::vector< std::string > filter)
Definition: select.cc:321
Definition: utils_sqlstring.h:67
static PFS_engine_table_share_proxy table
Definition: pfs.cc:61
constexpr value_type for_update
Definition: classic_protocol_constants.h:214
PT & ref(PT *tp)
Definition: tablespace_impl.cc:359
entry::ForeignKeyReference ForeignKeyReference
Definition: select.h:54
entry::Column Column
Definition: select.h:53
entry::Field Field
Definition: select.h:52
mysqlrouter::sqlstring format_where_expr(const Table &table, const std::string &table_name, const PrimaryKeyColumnValues &f, bool omit_row_owner=false)
Definition: select.cc:117
mysqlrouter::sqlstring format_key_names(const Table &table)
Definition: select.cc:74
mysqlrouter::sqlstring format_join_where_expr(const Table &table, const ForeignKeyReference &fk)
Definition: select.cc:53
mysqlrouter::sqlstring format_key(const Table &table, const PrimaryKeyColumnValues &f)
Definition: select.cc:94
entry::Table Table
Definition: select.h:51
std::vector< mysqlrouter::sqlstring > ColumnValues
Definition: select.h:45
RowLockType
Definition: select.h:47
std::map< std::string, mysqlrouter::sqlstring > PrimaryKeyColumnValues
Definition: select.h:43
Definition: authorize_manager.h:48
const char * table_name
Definition: rules_table_service.cc:56
synode_no q[FIFO_SIZE]
Definition: xcom_base.cc:4101