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