MySQL 9.0.0
Source Code Documentation
column.h
Go to the documentation of this file.
1/* Copyright (c) 2014, 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__COLUMN_INCLUDED
25#define DD__COLUMN_INCLUDED
26
27#include <optional>
28
29#include "lex_string.h" // LEX_CSTRING
30#include "my_inttypes.h"
31#include "sql/dd/collection.h" // dd::Collection
32#include "sql/dd/sdi_fwd.h" // RJ_Document
33#include "sql/dd/types/entity_object.h" // dd::Entity_object
34
35#include "sql/gis/srid.h"
36
37namespace dd {
38
39///////////////////////////////////////////////////////////////////////////
40
41class Abstract_table;
42class Column_impl;
43class Column_type_element;
44class Properties;
45
46namespace tables {
47class Columns;
48}
49
50///////////////////////////////////////////////////////////////////////////
51
52// Redefined enum_field_types here. We can remove some old types ?
54 DECIMAL = 1, // This is 1 > than MYSQL_TYPE_DECIMAL
55 TINY,
56 SHORT,
57 LONG,
58 FLOAT,
59 DOUBLE,
63 INT24,
64 DATE,
65 TIME,
67 YEAR,
68 NEWDATE,
69 VARCHAR,
70 BIT,
73 TIME2,
75 ENUM,
76 SET,
80 BLOB,
82 STRING,
84 JSON,
85 VECTOR
86};
87
88class Column : virtual public Entity_object {
89 public:
93
95
96 enum class enum_hidden_type {
97 /// The column is visible (a normal column)
98 HT_VISIBLE = 1,
99 /// The column is completely invisible to the server
100 HT_HIDDEN_SE = 2,
101 /// The column is visible to the server, but hidden from the user.
102 /// This is used for i.e. implementing functional indexes.
103 HT_HIDDEN_SQL = 3,
104 /// User table column marked as INVISIBLE by using the column visibility
105 /// attribute. Column is hidden from the user unless it is explicitly
106 /// referenced in the statement. Column is visible to the server.
108 };
109
110 ~Column() override = default;
111
112 /////////////////////////////////////////////////////////////////////////
113 // Table.
114 /////////////////////////////////////////////////////////////////////////
115
116 virtual const Abstract_table &table() const = 0;
117
118 virtual Abstract_table &table() = 0;
119
120 /////////////////////////////////////////////////////////////////////////
121 // collation.
122 /////////////////////////////////////////////////////////////////////////
123
124 virtual Object_id collation_id() const = 0;
126
128 virtual bool is_explicit_collation() const = 0;
129
130 /////////////////////////////////////////////////////////////////////////
131 // type.
132 /////////////////////////////////////////////////////////////////////////
133
134 virtual enum_column_types type() const = 0;
135 virtual void set_type(enum_column_types type) = 0;
136
137 /////////////////////////////////////////////////////////////////////////
138 // nullable.
139 /////////////////////////////////////////////////////////////////////////
140
141 virtual bool is_nullable() const = 0;
142 virtual void set_nullable(bool nullable) = 0;
143
144 /////////////////////////////////////////////////////////////////////////
145 // is_zerofill.
146 /////////////////////////////////////////////////////////////////////////
147
148 virtual bool is_zerofill() const = 0;
149 virtual void set_zerofill(bool zerofill) = 0;
150
151 /////////////////////////////////////////////////////////////////////////
152 // is_unsigned.
153 /////////////////////////////////////////////////////////////////////////
154
155 virtual bool is_unsigned() const = 0;
156 virtual void set_unsigned(bool unsigned_flag) = 0;
157
158 /////////////////////////////////////////////////////////////////////////
159 // auto increment.
160 /////////////////////////////////////////////////////////////////////////
161
162 virtual bool is_auto_increment() const = 0;
163 virtual void set_auto_increment(bool auto_increment) = 0;
164
165 /////////////////////////////////////////////////////////////////////////
166 // ordinal_position
167 /////////////////////////////////////////////////////////////////////////
168
169 virtual uint ordinal_position() const = 0;
170
171 /////////////////////////////////////////////////////////////////////////
172 // char_length.
173 /////////////////////////////////////////////////////////////////////////
174
175 virtual size_t char_length() const = 0;
176 virtual void set_char_length(size_t char_length) = 0;
177
178 /////////////////////////////////////////////////////////////////////////
179 // numeric_precision.
180 /////////////////////////////////////////////////////////////////////////
181
182 virtual uint numeric_precision() const = 0;
184
185 /////////////////////////////////////////////////////////////////////////
186 // srid
187 /////////////////////////////////////////////////////////////////////////
188
189 virtual void set_srs_id(std::optional<gis::srid_t> srs_id) = 0;
190 virtual std::optional<gis::srid_t> srs_id() const = 0;
191
192 /////////////////////////////////////////////////////////////////////////
193 // numeric_scale.
194 /////////////////////////////////////////////////////////////////////////
195
196 virtual uint numeric_scale() const = 0;
197 virtual void set_numeric_scale(uint numeric_scale) = 0;
198 virtual void set_numeric_scale_null(bool is_null) = 0;
199 virtual bool is_numeric_scale_null() const = 0;
200
201 /////////////////////////////////////////////////////////////////////////
202 // datetime_precision.
203 /////////////////////////////////////////////////////////////////////////
204
205 virtual uint datetime_precision() const = 0;
207 virtual void set_datetime_precision_null(bool is_null) = 0;
208 virtual bool is_datetime_precision_null() const = 0;
209
210 /////////////////////////////////////////////////////////////////////////
211 // has_no_default.
212 /////////////////////////////////////////////////////////////////////////
213
214 virtual bool has_no_default() const = 0;
215 virtual void set_has_no_default(bool has_explicit_default) = 0;
216
217 /////////////////////////////////////////////////////////////////////////
218 // default_value (binary).
219 /////////////////////////////////////////////////////////////////////////
220
221 virtual const String_type &default_value() const = 0;
223 virtual void set_default_value_null(bool is_null) = 0;
224 virtual bool is_default_value_null() const = 0;
225
226 /////////////////////////////////////////////////////////////////////////
227 // default_value_utf8
228 /////////////////////////////////////////////////////////////////////////
229
230 virtual const String_type &default_value_utf8() const = 0;
233 virtual void set_default_value_utf8_null(bool is_null) = 0;
234 virtual bool is_default_value_utf8_null() const = 0;
235
236 /////////////////////////////////////////////////////////////////////////
237 // is virtual ?
238 /////////////////////////////////////////////////////////////////////////
239
240 virtual bool is_virtual() const = 0;
241
242 virtual void set_virtual(bool is_virtual) = 0;
243
244 /////////////////////////////////////////////////////////////////////////
245 // generation_expression (binary).
246 /////////////////////////////////////////////////////////////////////////
247
248 virtual const String_type &generation_expression() const = 0;
249
252
253 virtual bool is_generation_expression_null() const = 0;
254
255 /////////////////////////////////////////////////////////////////////////
256 // generation_expression_utf8
257 /////////////////////////////////////////////////////////////////////////
258
259 virtual const String_type &generation_expression_utf8() const = 0;
260
263
264 virtual bool is_generation_expression_utf8_null() const = 0;
265
266 /////////////////////////////////////////////////////////////////////////
267 // default_option.
268 /////////////////////////////////////////////////////////////////////////
269
270 virtual const String_type &default_option() const = 0;
272
273 /////////////////////////////////////////////////////////////////////////
274 // update_option.
275 /////////////////////////////////////////////////////////////////////////
276
277 virtual const String_type &update_option() const = 0;
279
280 /////////////////////////////////////////////////////////////////////////
281 // Comment.
282 /////////////////////////////////////////////////////////////////////////
283
284 virtual const String_type &comment() const = 0;
285 virtual void set_comment(const String_type &comment) = 0;
286
287 /////////////////////////////////////////////////////////////////////////
288 // hidden.
289 /////////////////////////////////////////////////////////////////////////
290
291 virtual enum_hidden_type hidden() const = 0;
293 bool is_se_hidden() const {
295 }
296
297 /////////////////////////////////////////////////////////////////////////
298 // Options.
299 /////////////////////////////////////////////////////////////////////////
300
301 virtual const Properties &options() const = 0;
302
303 virtual Properties &options() = 0;
304 virtual bool set_options(const String_type &options_raw) = 0;
305
306 /////////////////////////////////////////////////////////////////////////
307 // se_private_data.
308 /////////////////////////////////////////////////////////////////////////
309
310 virtual const Properties &se_private_data() const = 0;
311
314 virtual bool set_se_private_data(const String_type &se_private_data_raw) = 0;
315
316 /////////////////////////////////////////////////////////////////////////
317 // SE-specific json attributes
318 /////////////////////////////////////////////////////////////////////////
319
320 virtual LEX_CSTRING engine_attribute() const = 0;
321 virtual void set_engine_attribute(LEX_CSTRING attrs) = 0;
322
325
326 /////////////////////////////////////////////////////////////////////////
327 // Column key type.
328 /////////////////////////////////////////////////////////////////////////
329
331
332 virtual enum_column_key column_key() const = 0;
333
334 /////////////////////////////////////////////////////////////////////////
335 // Column display type.
336 /////////////////////////////////////////////////////////////////////////
337
338 virtual const String_type &column_type_utf8() const = 0;
339
341
342 /////////////////////////////////////////////////////////////////////////
343 // Elements.
344 /////////////////////////////////////////////////////////////////////////
345
347
348 virtual const Column_type_element_collection &elements() const = 0;
349
350 virtual size_t elements_count() const = 0;
351
352 /**
353 Converts *this into json.
354
355 Converts all member variables that are to be included in the sdi
356 into json by transforming them appropriately and passing them to
357 the rapidjson writer provided.
358
359 @param wctx opaque context for data needed by serialization
360 @param w rapidjson writer which will perform conversion to json
361
362 */
363
364 virtual void serialize(Sdi_wcontext *wctx, Sdi_writer *w) const = 0;
365
366 /**
367 Re-establishes the state of *this by reading sdi information from
368 the rapidjson DOM subobject provided.
369
370 Cross-references encountered within this object are tracked in
371 sdictx, so that they can be updated when the entire object graph
372 has been established.
373
374 @param rctx stores book-keeping information for the
375 deserialization process
376 @param val subobject of rapidjson DOM containing json
377 representation of this object
378 */
379
380 virtual bool deserialize(Sdi_rcontext *rctx, const RJ_Value &val) = 0;
381
382 virtual bool is_array() const = 0;
383};
384
385///////////////////////////////////////////////////////////////////////////
386
387} // namespace dd
388
389#endif // DD__COLUMN_INCLUDED
Abstract base class for tables and views.
Definition: abstract_table.h:69
Definition: collection.h:44
Definition: column_impl.h:62
Definition: column_type_element.h:44
Definition: column.h:88
virtual void set_datetime_precision_null(bool is_null)=0
virtual void set_generation_expression_utf8(const String_type &generation_expression_utf8)=0
virtual void set_default_value_utf8_null(bool is_null)=0
virtual void set_zerofill(bool zerofill)=0
virtual bool is_default_value_null() const =0
virtual const Properties & options() const =0
virtual enum_column_key column_key() const =0
virtual void set_column_type_utf8(const String_type &column_type_utf8)=0
virtual void set_auto_increment(bool auto_increment)=0
virtual Abstract_table & table()=0
virtual LEX_CSTRING engine_attribute() const =0
virtual void set_engine_attribute(LEX_CSTRING attrs)=0
virtual bool set_options(const String_type &options_raw)=0
virtual void set_char_length(size_t char_length)=0
virtual void set_numeric_scale(uint numeric_scale)=0
virtual void set_srs_id(std::optional< gis::srid_t > srs_id)=0
enum_hidden_type
Definition: column.h:96
@ HT_HIDDEN_SQL
The column is visible to the server, but hidden from the user.
@ HT_HIDDEN_SE
The column is completely invisible to the server.
@ HT_VISIBLE
The column is visible (a normal column)
@ HT_HIDDEN_USER
User table column marked as INVISIBLE by using the column visibility attribute.
virtual void set_numeric_scale_null(bool is_null)=0
virtual void set_has_no_default(bool has_explicit_default)=0
virtual void set_is_explicit_collation(bool is_explicit_collation)=0
virtual void set_default_value(const String_type &default_value)=0
virtual void set_default_option(const String_type &default_option)=0
virtual bool is_nullable() const =0
virtual void set_datetime_precision(uint datetime_precision)=0
virtual void set_update_option(const String_type &update_option)=0
virtual Object_id collation_id() const =0
Collection< Column_type_element * > Column_type_element_collection
Definition: column.h:90
virtual void set_secondary_engine_attribute(LEX_CSTRING attrs)=0
virtual const String_type & default_option() const =0
virtual size_t char_length() const =0
virtual bool is_numeric_scale_null() const =0
virtual void set_comment(const String_type &comment)=0
virtual void set_virtual(bool is_virtual)=0
enum_column_key
Definition: column.h:94
@ CK_MULTIPLE
Definition: column.h:94
@ CK_UNIQUE
Definition: column.h:94
@ CK_PRIMARY
Definition: column.h:94
@ CK_NONE
Definition: column.h:94
virtual void set_generation_expression(const String_type &generation_expression)=0
virtual std::optional< gis::srid_t > srs_id() const =0
tables::Columns DD_table
Definition: column.h:92
virtual const String_type & update_option() const =0
virtual const String_type & default_value() const =0
virtual void set_collation_id(Object_id collation_id)=0
~Column() override=default
virtual bool is_explicit_collation() const =0
virtual const String_type & generation_expression() const =0
virtual bool set_se_private_data(const String_type &se_private_data_raw)=0
virtual const Abstract_table & table() const =0
virtual uint datetime_precision() const =0
virtual void set_column_key(enum_column_key column_key)=0
virtual void serialize(Sdi_wcontext *wctx, Sdi_writer *w) const =0
Converts *this into json.
virtual bool is_generation_expression_null() const =0
virtual uint numeric_precision() const =0
virtual Properties & options()=0
virtual const String_type & default_value_utf8() const =0
virtual Properties & se_private_data()=0
virtual const String_type & generation_expression_utf8() const =0
virtual void set_numeric_precision(uint numeric_precision)=0
virtual const Column_type_element_collection & elements() const =0
virtual const Properties & se_private_data() const =0
virtual enum_column_types type() const =0
virtual void set_default_value_null(bool is_null)=0
virtual bool is_array() const =0
virtual void set_type(enum_column_types type)=0
virtual LEX_CSTRING secondary_engine_attribute() const =0
virtual uint numeric_scale() const =0
virtual void set_default_value_utf8(const String_type &default_value_utf8)=0
Column_impl Impl
Definition: column.h:91
virtual uint ordinal_position() const =0
virtual const String_type & column_type_utf8() const =0
virtual bool is_virtual() const =0
virtual void set_unsigned(bool unsigned_flag)=0
virtual void set_nullable(bool nullable)=0
virtual bool has_no_default() const =0
virtual bool is_default_value_utf8_null() const =0
virtual bool is_zerofill() const =0
virtual bool is_auto_increment() const =0
virtual bool is_unsigned() const =0
virtual const String_type & comment() const =0
virtual bool is_generation_expression_utf8_null() const =0
virtual enum_hidden_type hidden() const =0
virtual size_t elements_count() const =0
virtual Column_type_element * add_element()=0
virtual bool is_datetime_precision_null() const =0
virtual void set_hidden(enum_hidden_type hidden)=0
bool is_se_hidden() const
Definition: column.h:293
virtual bool deserialize(Sdi_rcontext *rctx, const RJ_Value &val)=0
Re-establishes the state of *this by reading sdi information from the rapidjson DOM subobject provide...
virtual bool set_se_private_data(const Properties &se_private_data)=0
Base class for dictionary objects which has single column integer primary key.
Definition: entity_object.h:48
The Properties class defines an interface for storing key=value pairs, where both key and value may b...
Definition: properties.h:74
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: columns.h:40
std::vector< Field * > Columns
Definition: dict0dd.h:787
Some integer typedefs for easier portability.
constexpr value_type zerofill
Definition: classic_protocol_constants.h:274
constexpr value_type auto_increment
Definition: classic_protocol_constants.h:277
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
enum_column_types
Definition: column.h:53
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
This header provides Rapidjson Type Aliases.
Definition: mysql_lex_string.h:40