MySQL 8.3.0
Source Code Documentation
object_table_definition_impl.h
Go to the documentation of this file.
1/* Copyright (c) 2014, 2023, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is also distributed with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have included with MySQL.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License, version 2.0, for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22
23#ifndef DD__OBJECT_TABLE_DEFINITION_IMPL_INCLUDED
24#define DD__OBJECT_TABLE_DEFINITION_IMPL_INCLUDED
25
26#include <assert.h>
27#include <map>
28#include <memory>
29#include <vector>
30
31#include "m_string.h"
33#include "sql/dd/string_type.h" // dd::String_type
34#include "sql/dd/types/object_table_definition.h" // dd::Object_table_definition
35#include "sql/mysqld.h" // lower_case_table_names
36
37namespace dd {
38
39class Properties;
40
41///////////////////////////////////////////////////////////////////////////
42
44 public:
45 typedef std::map<String_type, int> Element_numbers;
46 typedef std::map<int, String_type> Element_definitions;
47
48 private:
49 enum class Label {
50 NAME,
51 FIELDS,
52 INDEXES,
54 OPTIONS,
55 LABEL,
59 };
60
61 static const char *key(Label label) {
62 switch (label) {
63 case Label::NAME:
64 return "name";
65 case Label::FIELDS:
66 return "fields";
67 case Label::INDEXES:
68 return "indexes";
70 return "foreign_keys";
71 case Label::OPTIONS:
72 return "options";
73 case Label::LABEL:
74 return "lbl";
75 case Label::POSITION:
76 return "pos";
78 return "def";
79 case Label::ELEMENT:
80 return "elem";
81 default:
82 assert(false);
83 return "";
84 }
85 }
86
88
91
93
96
99
102
105
106 std::vector<String_type> m_dml_statements;
107
108 void add_element(int element_number, const String_type &element_name,
109 const String_type &element_definition,
110 Element_numbers *element_numbers,
111 Element_definitions *element_definitions) {
112 assert(element_numbers != nullptr && element_definitions != nullptr &&
113 element_numbers->find(element_name) == element_numbers->end() &&
114 element_definitions->find(element_number) ==
115 element_definitions->end());
116
117 (*element_numbers)[element_name] = element_number;
118 (*element_definitions)[element_number] = element_definition;
119 }
120
121 int element_number(const String_type &element_name,
122 const Element_numbers &element_numbers) const {
123 assert(element_numbers.find(element_name) != element_numbers.end());
124 return element_numbers.find(element_name)->second;
125 }
126
127 void get_element_properties(dd::Properties *properties,
128 const Element_numbers &element_numbers,
129 const Element_definitions &element_defs) const;
130
131 bool set_element_properties(const String_type &prop_str,
132 Element_numbers *element_numbers,
133 Element_definitions *element_defs);
134
135 public:
137
139 const String_type &table_name,
140 const String_type &ddl_statement)
141 : m_schema_name(schema_name),
143 m_ddl_statement(ddl_statement) {}
144
145 ~Object_table_definition_impl() override = default;
146
149 }
150
152
153 /**
154 Get the collation which is used for names related to the file
155 system (e.g. a schema name or table name). This collation is
156 case sensitive or not, depending on the setting of lower_case-
157 table_names.
158
159 @return Pointer to CHARSET_INFO.
160 */
161
165 }
166
167 /**
168 Get the collation which is used for the name field in the table.
169 Table collation UTF8_BIN is used when collation for the name field
170 is not specified. Tables using different collation must override this
171 method.
172
173 TODO: Changing table collation is not supporting during upgrade as of now.
174 To support this, static definition of this method should be avoided
175 and should provide a possibility to have different collations for
176 actual and target table definition.
177
178 @return Pointer to CHARSET_INFO.
179 */
180 static const CHARSET_INFO *name_collation() {
182 }
183
184 /**
185 Convert to lowercase if lower_case_table_names == 2. This is needed
186 e.g when reconstructing name keys from a dictionary object in order
187 to remove the object.
188
189 @param src String to possibly convert to lowercase.
190 @param [in,out] buf Buffer for storing lowercase'd string. Supplied
191 by the caller.
192
193 @returns A pointer to the src string if l_c_t_n != 2
194 @returns A pointer to the buf supplied by the caller, into which
195 the src string has been copied and lowercase'd, if l_c_t_n == 2
196 */
197
198 static const char *fs_name_case(const String_type &src, char *buf) {
199 const char *tmp_name = src.c_str();
200 if (lower_case_table_names == 2) {
201 // Lower case table names == 2 is tested on OSX.
202 /* purecov: begin tested */
203 my_stpcpy(buf, tmp_name);
205 tmp_name = buf;
206 /* purecov: end */
207 }
208 return tmp_name;
209 }
210
211 const String_type &get_table_name() const { return m_table_name; }
212
213 void set_table_name(const String_type &name) override { m_table_name = name; }
214
216
217 void add_field(int field_number, const String_type &field_name,
218 const String_type field_definition) override {
219 add_element(field_number, field_name, field_definition, &m_field_numbers,
221 }
222
223 void add_sql_mode_field(int field_number, const String_type &field_name);
224
225 void add_index(int index_number, const String_type &index_name,
226 const String_type &index_definition) override {
227 add_element(index_number, index_name, index_definition, &m_index_numbers,
229 }
230
231 virtual void add_foreign_key(int foreign_key_number,
232 const String_type &foreign_key_name,
233 const String_type &foreign_key_definition) {
234 add_element(foreign_key_number, foreign_key_name, foreign_key_definition,
236 }
237
238 virtual void add_option(int option_number, const String_type &option_name,
239 const String_type &option_definition) {
240 add_element(option_number, option_name, option_definition,
242 }
243
245 m_dml_statements.push_back(statement);
246 }
247
248 virtual int field_number(const String_type &field_name) const {
249 return element_number(field_name, m_field_numbers);
250 }
251
252 virtual int index_number(const String_type &index_name) const {
253 return element_number(index_name, m_index_numbers);
254 }
255
256 virtual int option_number(const String_type &option_name) const {
257 return element_number(option_name, m_option_numbers);
258 }
259
260 String_type get_ddl() const override;
261
262 const std::vector<String_type> &get_dml() const override {
263 return m_dml_statements;
264 }
265
266 void store_into_properties(Properties *table_def_properties) const override;
267
268 virtual bool restore_from_string(const String_type &ddl_statement) {
269 m_ddl_statement = ddl_statement;
270 return false;
271 }
272
273 bool restore_from_properties(const Properties &table_def_properties) override;
274};
275
276///////////////////////////////////////////////////////////////////////////
277
278} // namespace dd
279
280#endif // DD__OBJECT_TABLE_DEFINITION_IMPL_INCLUDED
Definition: object_table_definition_impl.h:43
const String_type & get_table_name() const
Definition: object_table_definition_impl.h:211
std::map< String_type, int > Element_numbers
Definition: object_table_definition_impl.h:45
static bool is_dd_tablespace_encrypted()
Definition: object_table_definition_impl.h:151
void store_into_properties(Properties *table_def_properties) const override
Store the elements of the object table definition into a property object.
Definition: object_table_definition_impl.cc:140
virtual int index_number(const String_type &index_name) const
Definition: object_table_definition_impl.h:252
Element_definitions m_field_definitions
Definition: object_table_definition_impl.h:95
virtual bool restore_from_string(const String_type &ddl_statement)
Definition: object_table_definition_impl.h:268
Label
Definition: object_table_definition_impl.h:49
String_type get_ddl() const override
Get the SQL DDL statement for creating the dictionary table.
Definition: object_table_definition_impl.cc:99
void add_field(int field_number, const String_type &field_name, const String_type field_definition) override
Add a field to the object table definition.
Definition: object_table_definition_impl.h:217
static const char * key(Label label)
Definition: object_table_definition_impl.h:61
std::map< int, String_type > Element_definitions
Definition: object_table_definition_impl.h:46
Element_definitions m_foreign_key_definitions
Definition: object_table_definition_impl.h:101
int element_number(const String_type &element_name, const Element_numbers &element_numbers) const
Definition: object_table_definition_impl.h:121
Element_numbers m_option_numbers
Definition: object_table_definition_impl.h:103
bool set_element_properties(const String_type &prop_str, Element_numbers *element_numbers, Element_definitions *element_defs)
Definition: object_table_definition_impl.cc:58
Element_definitions m_option_definitions
Definition: object_table_definition_impl.h:104
virtual void add_option(int option_number, const String_type &option_name, const String_type &option_definition)
Definition: object_table_definition_impl.h:238
void set_table_name(const String_type &name) override
Set the name of the table.
Definition: object_table_definition_impl.h:213
virtual void add_populate_statement(const String_type &statement)
Definition: object_table_definition_impl.h:244
void set_schema_name(const String_type &name)
Definition: object_table_definition_impl.h:215
static const CHARSET_INFO * fs_name_collation()
Get the collation which is used for names related to the file system (e.g.
Definition: object_table_definition_impl.h:162
virtual int option_number(const String_type &option_name) const
Definition: object_table_definition_impl.h:256
void get_element_properties(dd::Properties *properties, const Element_numbers &element_numbers, const Element_definitions &element_defs) const
Definition: object_table_definition_impl.cc:37
void add_index(int index_number, const String_type &index_name, const String_type &index_definition) override
Add an index to the object table definition.
Definition: object_table_definition_impl.h:225
void add_sql_mode_field(int field_number, const String_type &field_name)
Definition: object_table_definition_impl.cc:87
String_type m_table_name
Definition: object_table_definition_impl.h:90
virtual void add_foreign_key(int foreign_key_number, const String_type &foreign_key_name, const String_type &foreign_key_definition)
Definition: object_table_definition_impl.h:231
static const char * fs_name_case(const String_type &src, char *buf)
Convert to lowercase if lower_case_table_names == 2.
Definition: object_table_definition_impl.h:198
Object_table_definition_impl(const String_type &schema_name, const String_type &table_name, const String_type &ddl_statement)
Definition: object_table_definition_impl.h:138
const std::vector< String_type > & get_dml() const override
Get the SQL DML statements for populating the table.
Definition: object_table_definition_impl.h:262
void add_element(int element_number, const String_type &element_name, const String_type &element_definition, Element_numbers *element_numbers, Element_definitions *element_definitions)
Definition: object_table_definition_impl.h:108
Element_numbers m_index_numbers
Definition: object_table_definition_impl.h:97
std::vector< String_type > m_dml_statements
Definition: object_table_definition_impl.h:106
~Object_table_definition_impl() override=default
static bool s_dd_tablespace_encrypted
Definition: object_table_definition_impl.h:87
bool restore_from_properties(const Properties &table_def_properties) override
Restore the elements of the object table definition from a property object.
Definition: object_table_definition_impl.cc:167
String_type m_ddl_statement
Definition: object_table_definition_impl.h:92
Element_definitions m_index_definitions
Definition: object_table_definition_impl.h:98
Element_numbers m_field_numbers
Definition: object_table_definition_impl.h:94
Element_numbers m_foreign_key_numbers
Definition: object_table_definition_impl.h:100
static const CHARSET_INFO * name_collation()
Get the collation which is used for the name field in the table.
Definition: object_table_definition_impl.h:180
virtual int field_number(const String_type &field_name) const
Definition: object_table_definition_impl.h:248
static void set_dd_tablespace_encrypted(bool is_encrypted)
Definition: object_table_definition_impl.h:147
String_type m_schema_name
Definition: object_table_definition_impl.h:89
The purpose of this interface is to enable retrieving the SQL statements necessary to create and popu...
Definition: object_table_definition.h:47
The Properties class defines an interface for storing key=value pairs, where both key and value may b...
Definition: properties.h:73
static char buf[MAX_BUF]
Definition: conf_to_src.cc:72
A better implementation of the UNIX ctype(3) library.
MYSQL_STRINGS_EXPORT CHARSET_INFO my_charset_utf8mb3_tolower_ci
Definition: ctype-utf8.cc:5829
size_t my_casedn_str(const CHARSET_INFO *cs, char *str)
Definition: m_ctype.h:733
MYSQL_STRINGS_EXPORT CHARSET_INFO my_charset_utf8mb3_bin
Definition: ctype-utf8.cc:5899
static char * my_stpcpy(char *dst, const char *src)
Copy a string from src to dst until (and including) terminating null byte.
Definition: m_string.h:141
uint lower_case_table_names
Definition: mysqld.cc:1340
Definition: buf0block_hint.cc:29
The version of the current data dictionary table definitions.
Definition: dictionary_client.h:42
bool is_encrypted(const String_type &type)
Definition: dd_table.h:421
Char_string_template< String_type_allocator > String_type
Definition: string_type.h:50
const char * table_name
Definition: rules_table_service.cc:55
case opt name
Definition: sslopt-case.h:32
Definition: m_ctype.h:422
Definition: mysqlslap.cc:218