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