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