MySQL 9.1.0
Source Code Documentation
check_constraint_impl.h
Go to the documentation of this file.
1/* Copyright (c) 2019, 2024, 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 designed to work 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 either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#ifndef DD__CHECK_CONSTRAINT_IMPL_INCLUDED
25#define DD__CHECK_CONSTRAINT_IMPL_INCLUDED
26
27#include <new>
28
29#include "mysql/strings/m_ctype.h" // my_strcasecmp
30#include "sql/dd/impl/types/entity_object_impl.h" // dd::Entity_object_impl
31#include "sql/dd/sdi_fwd.h"
32#include "sql/dd/string_type.h"
33#include "sql/dd/types/check_constraint.h" // dd::Check_constraint
34#include "sql/mysqld_cs.h"
35
36namespace dd {
37
38///////////////////////////////////////////////////////////////////////////
39
40class Object_table;
41class Open_dictionary_tables_ctx;
42class Raw_record;
43class Sdi_rcontext;
44class Sdi_wcontext;
45class Table;
46class Table_impl;
47
48///////////////////////////////////////////////////////////////////////////
49
51 public Check_constraint {
52 public:
54
56
58
59 public:
61
62 const Object_table &object_table() const override;
63
64 bool validate() const override;
65
66 bool store(Open_dictionary_tables_ctx *otx) override;
67
68 bool store_attributes(Raw_record *r) override;
69
70 bool restore_attributes(const Raw_record &r) override;
71
72 void serialize(Sdi_wcontext *wctx, Sdi_writer *w) const override;
73
74 bool deserialize(Sdi_rcontext *rctx, const RJ_Value &val) override;
75
76 void debug_print(String_type &outb) const override;
77
79
80 virtual uint ordinal_position() const { return -1; }
81
82 public:
83 /////////////////////////////////////////////////////////////////////////
84 // State.
85 /////////////////////////////////////////////////////////////////////////
86
88 return m_constraint_state;
89 }
90
91 void set_constraint_state(bool is_enabled) override {
93 }
94
95 /////////////////////////////////////////////////////////////////////////
96 // Check clause/utf8.
97 /////////////////////////////////////////////////////////////////////////
98
99 const String_type &check_clause() const override { return m_check_clause; }
100
103 }
104
105 const String_type &check_clause_utf8() const override {
106 return m_check_clause_utf8;
107 }
108
111 }
112
113 /////////////////////////////////////////////////////////////////////////
114 // Alter mode ( true / false).
115 // Set during ALTER TABLE operation. In alter mode, alias_name is stored
116 // in data-dictionary to avoid name conflicts.
117 /////////////////////////////////////////////////////////////////////////
118
119 bool is_alter_mode() const override { return m_alter_mode; }
120
121 void set_alter_mode(bool alter_mode) override { m_alter_mode = alter_mode; }
122
123 /////////////////////////////////////////////////////////////////////////
124 // Alias check constriaint name.
125 /////////////////////////////////////////////////////////////////////////
126
127 const String_type &alias_name() const override { return m_alias_name; }
128
129 void set_alias_name(const String_type &alias_name) override {
131 }
132
133 /////////////////////////////////////////////////////////////////////////
134 // Table.
135 /////////////////////////////////////////////////////////////////////////
136
137 const Table &table() const override;
138
139 Table &table() override;
140
141 public:
143 return new (std::nothrow) Check_constraint_impl(table);
144 }
145
147 Table_impl *table) {
148 return new (std::nothrow) Check_constraint_impl(other, table);
149 }
150
151 // Fix "inherits ... via dominance" warnings
153 const Entity_object_impl *impl() const override {
155 }
156 Object_id id() const override { return Entity_object_impl::id(); }
157 bool is_persistent() const override {
159 }
160 const String_type &name() const override {
162 }
163 void set_name(const String_type &name) override {
165 }
166
167 private:
171 bool m_alter_mode{false};
174
175 // References to the Table object.
177};
178
179///////////////////////////////////////////////////////////////////////////
180
181/** Class used to sort check constraints by name for the same table. */
184 const dd::Check_constraint *cc2) const {
185 return (my_strcasecmp(system_charset_info, cc1->name().c_str(),
186 cc2->name().c_str()) < 0);
187 }
188};
189
190///////////////////////////////////////////////////////////////////////////
191} // namespace dd
192
193#endif // DD__CHECK_CONSTRAINT_IMPL_INCLUDED
Definition: check_constraint_impl.h:51
const String_type & check_clause_utf8() const override
Definition: check_constraint_impl.h:105
const String_type & check_clause() const override
Definition: check_constraint_impl.h:99
Object_id m_schema_id
Definition: check_constraint_impl.h:173
bool m_alter_mode
Definition: check_constraint_impl.h:171
void serialize(Sdi_wcontext *wctx, Sdi_writer *w) const override
Converts *this into json.
Definition: check_constraint_impl.cc:144
void set_name(const String_type &name) override
Definition: check_constraint_impl.h:163
static Check_constraint_impl * restore_item(Table_impl *table)
Definition: check_constraint_impl.h:142
void set_alias_name(const String_type &alias_name) override
Definition: check_constraint_impl.h:129
virtual uint ordinal_position() const
Definition: check_constraint_impl.h:80
bool is_persistent() const override
Is dictionary object persistent in dictionary tables ?
Definition: check_constraint_impl.h:157
const String_type & alias_name() const override
Definition: check_constraint_impl.h:127
const Object_table & object_table() const override
Definition: check_constraint_impl.cc:202
String_type m_alias_name
Definition: check_constraint_impl.h:172
const String_type & name() const override
Definition: check_constraint_impl.h:160
void set_ordinal_position(uint)
Definition: check_constraint_impl.h:78
static void register_tables(Open_dictionary_tables_ctx *otx)
Definition: check_constraint_impl.cc:208
bool is_alter_mode() const override
Definition: check_constraint_impl.h:119
void set_alter_mode(bool alter_mode) override
Definition: check_constraint_impl.h:121
enum_constraint_state constraint_state() const override
Definition: check_constraint_impl.h:87
Entity_object_impl * impl() override
Definition: check_constraint_impl.h:152
String_type m_check_clause
Definition: check_constraint_impl.h:169
bool restore_attributes(const Raw_record &r) override
Definition: check_constraint_impl.cc:108
bool deserialize(Sdi_rcontext *rctx, const RJ_Value &val) override
Re-establishes the state of *this by reading sdi information from the rapidjson DOM subobject provide...
Definition: check_constraint_impl.cc:157
bool store(Open_dictionary_tables_ctx *otx) override
Store the DD object into DD table.
Definition: check_constraint_impl.cc:94
const Table & table() const override
Definition: check_constraint_impl.cc:54
bool store_attributes(Raw_record *r) override
Definition: check_constraint_impl.cc:126
bool validate() const override
Definition: check_constraint_impl.cc:60
Table_impl * m_table
Definition: check_constraint_impl.h:176
Object_id id() const override
The unique dictionary object id.
Definition: check_constraint_impl.h:156
String_type m_check_clause_utf8
Definition: check_constraint_impl.h:170
void set_check_clause(const String_type &check_clause) override
Definition: check_constraint_impl.h:101
const Entity_object_impl * impl() const override
Definition: check_constraint_impl.h:153
static Check_constraint_impl * clone(const Check_constraint_impl &other, Table_impl *table)
Definition: check_constraint_impl.h:146
void set_constraint_state(bool is_enabled) override
Definition: check_constraint_impl.h:91
void debug_print(String_type &outb) const override
Definition: check_constraint_impl.cc:169
enum_constraint_state m_constraint_state
Definition: check_constraint_impl.h:168
void set_check_clause_utf8(const String_type &check_clause_utf8) override
Definition: check_constraint_impl.h:109
Definition: check_constraint.h:42
enum_constraint_state
Definition: check_constraint.h:48
@ CS_ENFORCED
Definition: check_constraint.h:48
@ CS_NOT_ENFORCED
Definition: check_constraint.h:48
Definition: entity_object_impl.h:44
void set_name(const String_type &name) override
Definition: entity_object_impl.h:62
Object_id id() const override
The unique dictionary object id.
Definition: entity_object_impl.h:49
const String_type & name() const override
Definition: entity_object_impl.h:60
Entity_object_impl * impl() override
Definition: entity_object_impl.h:68
bool is_persistent() const override
Is dictionary object persistent in dictionary tables ?
Definition: entity_object_impl.h:57
virtual const String_type & name() const =0
This class represents all data dictionary table like mysql.tables, mysql.columns and more.
Definition: object_table.h:72
Auxiliary class for opening dictionary tables.
Definition: transaction_impl.h:76
Definition: raw_record.h:46
Opaque context which keeps reusable resoureces needed during deserialization.
Definition: sdi.cc:231
Opaque context which keeps reusable resources needed during serialization.
Definition: sdi.cc:129
Definition: table_impl.h:68
Definition: table.h:47
A better implementation of the UNIX ctype(3) library.
int my_strcasecmp(const CHARSET_INFO *cs, const char *s1, const char *s2)
Definition: m_ctype.h:651
MYSQL_PLUGIN_IMPORT CHARSET_INFO * system_charset_info
Definition: mysqld.cc:1554
bool is_enabled()
Check if doublewrite is enabled.
Definition: buf0dblwr.h:390
The version of the current data dictionary table definitions.
Definition: dictionary_client.h:43
RJ_Writer Sdi_writer
Alias for the rapidjson Writer type to use in serialization.
Definition: sdi_fwd.h:64
unsigned long long Object_id
Definition: object_id.h:31
rapidjson::GenericValue< RJ_Encoding, RJ_Allocator > RJ_Value
Definition: sdi_fwd.h:49
Char_string_template< String_type_allocator > String_type
Definition: string_type.h:51
const mysql_service_registry_t * r
Definition: pfs_example_plugin_employee.cc:86
This header provides Rapidjson Type Aliases.
Class used to sort check constraints by name for the same table.
Definition: check_constraint_impl.h:182
bool operator()(const dd::Check_constraint *cc1, const dd::Check_constraint *cc2) const
Definition: check_constraint_impl.h:183