MySQL 9.1.0
Source Code Documentation
service_rules_table.h
Go to the documentation of this file.
1#ifndef SERVICE_RULES_TABLE_INCLUDED
2#define SERVICE_RULES_TABLE_INCLUDED
3
4/* Copyright (c) 2015, 2024, 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 <string>
28
29#include "my_dbug.h"
30
31#ifndef MYSQL_ABI_CHECK
32#include <stdlib.h>
33#endif
34
35/**
36 @file include/mysql/service_rules_table.h
37
38 Plugin service that provides access to the rewrite rules table that is used
39 by the Rewriter plugin. No other use intended.
40*/
41
42class THD;
43class Table_ref;
44class Field;
45
47
48/**
49 There must be one function of this kind in order for the symbols in the
50 server's dynamic library to be visible to plugins.
51*/
53
54/**
55 Frees a const char pointer allocated in the server's dynamic library using
56 new[].
57*/
58void free_string(const char *str);
59
60/**
61 Writable cursor that allows reading and updating of rows in a persistent
62 table.
63*/
64class Cursor {
65 public:
66 typedef int column_id;
67
68 static const column_id ILLEGAL_COLUMN_ID = -1;
69
70 /**
71 Creates a cursor to an already-opened table. The constructor is kept
72 explicit because of implicit conversions from void*.
73 */
74 explicit Cursor(THD *thd);
75
76 /// Creates a past-the-end cursor.
78
79 Cursor(const Cursor &) = default;
80
84 }
91 }
92
93 /**
94 True if the table does not contain columns named 'pattern', 'replacement',
95 'enabled' and 'message'. In this case the cursor is equal to any
96 past-the-end Cursor.
97 */
99
100 /**
101 Fetches the value of the column with the given number as a C string.
102
103 This interface is meant for crossing dynamic library boundaries, hence the
104 use of C-style const char*. The function casts a column value to a C
105 string and returns a copy, allocated in the callee's DL. The pointer
106 must be freed using free_string().
107
108 @param fieldno One of PATTERN_COLUMN, REPLACEMENT_COLUMN, ENABLED_COLUMN
109 or MESSAGE_COLUMN.
110 */
111 const char *fetch_string(int fieldno);
112
113 /**
114 Equality operator. The only cursors that are equal are past-the-end
115 cursors.
116 */
117 bool operator==(const Cursor &other) const {
118 return (m_is_finished == other.m_is_finished);
119 }
120
121 /**
122 Inequality operator. All cursors are considered different except
123 past-the-end cursors.
124 */
125 bool operator!=(const Cursor &other) { return !(*this == other); }
126
127 /**
128 Advances this Cursor. Read errors are kept, and had_serious_read_error()
129 will tell if there was an unexpected error (e.g. not EOF) while reading.
130 */
132 if (!m_is_finished) read();
133 return *this;
134 }
135
136 /// Prepares the write buffer for updating the current row.
137 void make_writeable();
138
139 /**
140 Sets the value of column colno to a string value.
141
142 @param colno The column number.
143 @param str The string.
144 @param length The string's length.
145 */
146 void set(int colno, const char *str, size_t length);
147
148 /// Writes the row in the write buffer to the table at the current row.
149 int write();
150
151 /// True if there was an unexpected error while reading, e.g. other than EOF.
152 bool had_serious_read_error() const;
153
154 /// Closes the table scan if initiated and commits the transaction.
155 ~Cursor();
156
157 private:
158 int field_index(const char *field_name);
159
167
170
174
175 int read();
176};
177
178/**
179 A past-the-end Cursor. All past-the-end cursors are considered equal
180 when compared with operator ==.
181*/
182Cursor end();
183
184} // namespace rules_table_service
185
186#endif // SERVICE_RULES_TABLE_INCLUDED
Kerberos Client Authentication nullptr
Definition: auth_kerberos_client_plugin.cc:251
Definition: field.h:577
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:36
Definition: table.h:2900
Writable cursor that allows reading and updating of rows in a persistent table.
Definition: service_rules_table.h:64
int m_normalized_pattern_column
Definition: service_rules_table.h:166
bool table_is_malformed()
True if the table does not contain columns named 'pattern', 'replacement', 'enabled' and 'message'.
Definition: service_rules_table.h:98
int write()
Writes the row in the write buffer to the table at the current row.
Definition: rules_table_service.cc:177
column_id pattern_digest_column() const
Definition: service_rules_table.h:88
Cursor()
Creates a past-the-end cursor.
Definition: service_rules_table.h:77
column_id normalized_pattern_column() const
Definition: service_rules_table.h:89
column_id message_column() const
Definition: service_rules_table.h:87
Cursor & operator++()
Advances this Cursor.
Definition: service_rules_table.h:131
int m_pattern_column
Definition: service_rules_table.h:160
column_id enabled_column() const
Definition: service_rules_table.h:86
int m_pattern_database_column
Definition: service_rules_table.h:161
void set(int colno, const char *str, size_t length)
Sets the value of column colno to a string value.
Definition: rules_table_service.cc:164
int m_enabled_column
Definition: service_rules_table.h:163
bool operator==(const Cursor &other) const
Equality operator.
Definition: service_rules_table.h:117
static const column_id ILLEGAL_COLUMN_ID
Definition: service_rules_table.h:68
int m_replacement_column
Definition: service_rules_table.h:162
const char * fetch_string(int fieldno)
Fetches the value of the column with the given number as a C string.
Definition: rules_table_service.cc:139
column_id pattern_column() const
Definition: service_rules_table.h:81
bool m_table_is_malformed
Definition: service_rules_table.h:172
int m_last_read_status
Definition: service_rules_table.h:173
bool operator!=(const Cursor &other)
Inequality operator.
Definition: service_rules_table.h:125
void make_writeable()
Prepares the write buffer for updating the current row.
Definition: rules_table_service.cc:159
column_id pattern_database_column() const
Definition: service_rules_table.h:82
bool m_is_finished
Definition: service_rules_table.h:171
int read()
Definition: rules_table_service.cc:58
THD * m_thd
Definition: service_rules_table.h:168
~Cursor()
Closes the table scan if initiated and commits the transaction.
Definition: rules_table_service.cc:186
int m_pattern_digest_column
Definition: service_rules_table.h:165
bool had_serious_read_error() const
True if there was an unexpected error while reading, e.g. other than EOF.
Definition: rules_table_service.cc:182
Table_ref * m_table_list
Definition: service_rules_table.h:169
Cursor(const Cursor &)=default
int m_message_column
Definition: service_rules_table.h:164
int field_index(const char *field_name)
Definition: rules_table_service.cc:152
column_id replacement_column() const
Definition: service_rules_table.h:85
int column_id
Definition: service_rules_table.h:66
std::string str(const mysqlrouter::ConfigGenerator::Options::Endpoint &ep)
Definition: config_generator.cc:1105
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
Definition: service_rules_table.h:46
void free_string(const char *str)
Frees a const char pointer allocated in the server's dynamic library using new[].
Definition: rules_table_service.cc:68
Cursor end()
A past-the-end Cursor.
Definition: rules_table_service.cc:192
int dummy_function_to_ensure_we_are_linked_into_the_server()
There must be one function of this kind in order for the symbols in the server's dynamic library to b...
Definition: rules_table_service.cc:51