MySQL 8.0.39
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 "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
35namespace dd {
36
37///////////////////////////////////////////////////////////////////////////
38
39class Object_table;
40class Open_dictionary_tables_ctx;
41class Raw_record;
42class Sdi_rcontext;
43class Sdi_wcontext;
44class Table;
45class Table_impl;
46
47///////////////////////////////////////////////////////////////////////////
48
50 public Check_constraint {
51 public:
53
55
57
58 public:
60
61 const Object_table &object_table() const override;
62
63 bool validate() const override;
64
65 bool store(Open_dictionary_tables_ctx *otx) override;
66
67 bool store_attributes(Raw_record *r) override;
68
69 bool restore_attributes(const Raw_record &r) override;
70
71 void serialize(Sdi_wcontext *wctx, Sdi_writer *w) const override;
72
73 bool deserialize(Sdi_rcontext *rctx, const RJ_Value &val) override;
74
75 void debug_print(String_type &outb) const override;
76
78
79 virtual uint ordinal_position() const { return -1; }
80
81 public:
82 /////////////////////////////////////////////////////////////////////////
83 // State.
84 /////////////////////////////////////////////////////////////////////////
85
87 return m_constraint_state;
88 }
89
90 void set_constraint_state(bool is_enabled) override {
92 }
93
94 /////////////////////////////////////////////////////////////////////////
95 // Check clause/utf8.
96 /////////////////////////////////////////////////////////////////////////
97
98 const String_type &check_clause() const override { return m_check_clause; }
99
102 }
103
104 const String_type &check_clause_utf8() const override {
105 return m_check_clause_utf8;
106 }
107
110 }
111
112 /////////////////////////////////////////////////////////////////////////
113 // Alter mode ( true / false).
114 // Set during ALTER TABLE operation. In alter mode, alias_name is stored
115 // in data-dictionary to avoid name conflicts.
116 /////////////////////////////////////////////////////////////////////////
117
118 bool is_alter_mode() const override { return m_alter_mode; }
119
120 void set_alter_mode(bool alter_mode) override { m_alter_mode = alter_mode; }
121
122 /////////////////////////////////////////////////////////////////////////
123 // Alias check constriaint name.
124 /////////////////////////////////////////////////////////////////////////
125
126 const String_type &alias_name() const override { return m_alias_name; }
127
128 void set_alias_name(const String_type &alias_name) override {
130 }
131
132 /////////////////////////////////////////////////////////////////////////
133 // Table.
134 /////////////////////////////////////////////////////////////////////////
135
136 const Table &table() const override;
137
138 Table &table() override;
139
140 public:
142 return new (std::nothrow) Check_constraint_impl(table);
143 }
144
146 Table_impl *table) {
147 return new (std::nothrow) Check_constraint_impl(other, table);
148 }
149
150 // Fix "inherits ... via dominance" warnings
152 const Entity_object_impl *impl() const override {
154 }
155 Object_id id() const override { return Entity_object_impl::id(); }
156 bool is_persistent() const override {
158 }
159 const String_type &name() const override {
161 }
162 void set_name(const String_type &name) override {
164 }
165
166 private:
170 bool m_alter_mode{false};
173
174 // References to the Table object.
176};
177
178///////////////////////////////////////////////////////////////////////////
179
180/** Class used to sort check constraints by name for the same table. */
183 const dd::Check_constraint *cc2) const {
184 return (my_strcasecmp(system_charset_info, cc1->name().c_str(),
185 cc2->name().c_str()) < 0);
186 }
187};
188
189///////////////////////////////////////////////////////////////////////////
190} // namespace dd
191
192#endif // DD__CHECK_CONSTRAINT_IMPL_INCLUDED
Definition: check_constraint_impl.h:50
const String_type & check_clause_utf8() const override
Definition: check_constraint_impl.h:104
const String_type & check_clause() const override
Definition: check_constraint_impl.h:98
Object_id m_schema_id
Definition: check_constraint_impl.h:172
bool m_alter_mode
Definition: check_constraint_impl.h:170
void serialize(Sdi_wcontext *wctx, Sdi_writer *w) const override
Converts *this into json.
Definition: check_constraint_impl.cc:143
void set_name(const String_type &name) override
Definition: check_constraint_impl.h:162
static Check_constraint_impl * restore_item(Table_impl *table)
Definition: check_constraint_impl.h:141
void set_alias_name(const String_type &alias_name) override
Definition: check_constraint_impl.h:128
virtual uint ordinal_position() const
Definition: check_constraint_impl.h:79
bool is_persistent() const override
Is dictionary object persistent in dictionary tables ?
Definition: check_constraint_impl.h:156
const String_type & alias_name() const override
Definition: check_constraint_impl.h:126
const Object_table & object_table() const override
Definition: check_constraint_impl.cc:201
String_type m_alias_name
Definition: check_constraint_impl.h:171
const String_type & name() const override
Definition: check_constraint_impl.h:159
void set_ordinal_position(uint)
Definition: check_constraint_impl.h:77
static void register_tables(Open_dictionary_tables_ctx *otx)
Definition: check_constraint_impl.cc:207
bool is_alter_mode() const override
Definition: check_constraint_impl.h:118
void set_alter_mode(bool alter_mode) override
Definition: check_constraint_impl.h:120
enum_constraint_state constraint_state() const override
Definition: check_constraint_impl.h:86
Entity_object_impl * impl() override
Definition: check_constraint_impl.h:151
String_type m_check_clause
Definition: check_constraint_impl.h:168
bool restore_attributes(const Raw_record &r) override
Definition: check_constraint_impl.cc:107
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:156
bool store(Open_dictionary_tables_ctx *otx) override
Store the DD object into DD table.
Definition: check_constraint_impl.cc:93
const Table & table() const override
Definition: check_constraint_impl.cc:53
bool store_attributes(Raw_record *r) override
Definition: check_constraint_impl.cc:125
bool validate() const override
Definition: check_constraint_impl.cc:59
Table_impl * m_table
Definition: check_constraint_impl.h:175
Object_id id() const override
The unique dictionary object id.
Definition: check_constraint_impl.h:155
String_type m_check_clause_utf8
Definition: check_constraint_impl.h:169
void set_check_clause(const String_type &check_clause) override
Definition: check_constraint_impl.h:100
const Entity_object_impl * impl() const override
Definition: check_constraint_impl.h:152
static Check_constraint_impl * clone(const Check_constraint_impl &other, Table_impl *table)
Definition: check_constraint_impl.h:145
void set_constraint_state(bool is_enabled) override
Definition: check_constraint_impl.h:90
void debug_print(String_type &outb) const override
Definition: check_constraint_impl.cc:168
enum_constraint_state m_constraint_state
Definition: check_constraint_impl.h:167
void set_check_clause_utf8(const String_type &check_clause_utf8) override
Definition: check_constraint_impl.h:108
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.
MYSQL_PLUGIN_IMPORT CHARSET_INFO * system_charset_info
Definition: mysqld.cc:1545
#define my_strcasecmp(s, a, b)
Definition: m_ctype.h:718
bool is_enabled()
Check if doublewrite is enabled.
Definition: buf0dblwr.h:388
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:181
bool operator()(const dd::Check_constraint *cc1, const dd::Check_constraint *cc2) const
Definition: check_constraint_impl.h:182
unsigned int uint
Definition: uca9-dump.cc:75