MySQL  8.0.18
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, 2019, Oracle and/or its affiliates. All rights reserved.
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 
41 class THD;
42 struct TABLE_LIST;
43 class 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 */
57 void free_string(const char *str);
58 
59 /**
60  Writable cursor that allows reading and updating of rows in a persistent
61  table.
62 */
63 class 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 */
181 Cursor end();
182 
183 } // namespace rules_table_service
184 
185 #endif // SERVICE_RULES_TABLE_INCLUDED
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&#39;s dynamic library to b...
Definition: rules_table_service.cc:50
column_id pattern_digest_column() const
Definition: service_rules_table.h:87
bool operator==(const Cursor &other)
Equality operator.
Definition: service_rules_table.h:116
column_id pattern_column() const
Definition: service_rules_table.h:80
int m_pattern_column
Definition: service_rules_table.h:159
~Cursor()
Closes the table scan if initiated and commits the transaction.
Definition: rules_table_service.cc:182
int m_pattern_database_column
Definition: service_rules_table.h:160
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:178
Definition: field.h:700
int column_id
Definition: service_rules_table.h:65
Cursor()
Creates a past-the-end cursor.
Definition: service_rules_table.h:76
bool m_table_is_malformed
Definition: service_rules_table.h:171
bool table_is_malformed()
True if the table does not contain columns named &#39;pattern&#39;, &#39;replacement&#39;, &#39;enabled&#39; and &#39;message&#39;...
Definition: service_rules_table.h:97
int field_index(const char *field_name)
Definition: rules_table_service.cc:148
int m_last_read_status
Definition: service_rules_table.h:172
int read()
Definition: rules_table_service.cc:57
Definition: service_rules_table.h:45
Cursor end()
A past-the-end Cursor.
Definition: rules_table_service.cc:188
int write()
Writes the row in the write buffer to the table at the current row.
Definition: rules_table_service.cc:173
TABLE_LIST * m_table_list
Definition: service_rules_table.h:168
column_id message_column() const
Definition: service_rules_table.h:86
#define true
Definition: config_static.h:44
void free_string(const char *str)
Frees a const char pointer allocated in the server&#39;s dynamic library using new[]. ...
Definition: rules_table_service.cc:64
Cursor & operator++()
Advances this Cursor.
Definition: service_rules_table.h:130
Writable cursor that allows reading and updating of rows in a persistent table.
Definition: service_rules_table.h:63
int m_pattern_digest_column
Definition: service_rules_table.h:164
int m_replacement_column
Definition: service_rules_table.h:161
int m_normalized_pattern_column
Definition: service_rules_table.h:165
static const column_id ILLEGAL_COLUMN_ID
Definition: service_rules_table.h:67
#define NULL
Definition: types.h:55
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:135
THD * m_thd
Definition: service_rules_table.h:167
column_id pattern_database_column() const
Definition: service_rules_table.h:81
Definition: table.h:2468
int m_enabled_column
Definition: service_rules_table.h:162
void make_writeable()
Prepares the write buffer for updating the current row.
Definition: rules_table_service.cc:155
bool m_is_finished
Definition: service_rules_table.h:170
column_id replacement_column() const
Definition: service_rules_table.h:84
column_id enabled_column() const
Definition: service_rules_table.h:85
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
column_id normalized_pattern_column() const
Definition: service_rules_table.h:88
int m_message_column
Definition: service_rules_table.h:163
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_class.h:778
bool operator!=(const Cursor &other)
Inequality operator.
Definition: service_rules_table.h:124