MySQL  8.0.27
Source Code Documentation
field_common_properties.h
Go to the documentation of this file.
1 /* Copyright (c) 2020, 2021, 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 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 FIELD_COMMON_OPERATIONS_INCLUDED
24 #define FIELD_COMMON_OPERATIONS_INCLUDED
25 
26 #include "field_types.h"
27 
28 /**
29  @file field_common_properties.h
30 
31  @brief This file contains basic method for field types.
32 
33  @note This file can be imported from both the server and
34  tools like mysqlbinlog, hence its simplicity
35 */
36 
37 /**
38  Tests if field type is an integer
39 
40  @param type Field type, as returned by field->type()
41 
42  @returns true if integer type, false otherwise
43  */
45  switch (type) {
46  case MYSQL_TYPE_TINY:
47  case MYSQL_TYPE_SHORT:
48  case MYSQL_TYPE_INT24:
49  case MYSQL_TYPE_LONG:
51  return true;
52  default:
53  return false;
54  }
55 }
56 
57 /**
58  Tests if field type is a numeric type
59 
60  @param type Field type, as returned by field->type()
61 
62  @returns true if numeric type, false otherwise
63 */
65  switch (type) {
66  case MYSQL_TYPE_TINY:
67  case MYSQL_TYPE_SHORT:
68  case MYSQL_TYPE_INT24:
69  case MYSQL_TYPE_LONG:
71  case MYSQL_TYPE_FLOAT:
72  case MYSQL_TYPE_DOUBLE:
73  case MYSQL_TYPE_DECIMAL:
75  return true;
76  default:
77  return false;
78  }
79 }
80 
81 /**
82  Tests if field type is a string type
83 
84  @param type Field type, as returned by field->type()
85 
86  @returns true if string type, false otherwise
87 */
89  switch (type) {
90  case MYSQL_TYPE_VARCHAR:
92  case MYSQL_TYPE_STRING:
96  case MYSQL_TYPE_BLOB:
97  case MYSQL_TYPE_ENUM:
98  case MYSQL_TYPE_SET:
99  case MYSQL_TYPE_JSON:
100  return true;
101  default:
102  return false;
103  }
104 }
105 
106 /**
107  Tests if field type is temporal, i.e. represents
108  DATE, TIME, DATETIME, TIMESTAMP or YEAR types in SQL.
109 
110  @param type Field type, as returned by field->type().
111  @retval true If field type is temporal
112  @retval false If field type is not temporal
113 */
115  switch (type) {
116  case MYSQL_TYPE_TIME:
117  case MYSQL_TYPE_DATETIME:
119  case MYSQL_TYPE_DATE:
120  case MYSQL_TYPE_NEWDATE:
121  case MYSQL_TYPE_YEAR:
122  return true;
123  default:
124  return false;
125  }
126 }
127 
128 /**
129  Tests if field type is temporal and has time part,
130  i.e. represents TIME, DATETIME or TIMESTAMP types in SQL.
131 
132  @param type Field type, as returned by field->type().
133  @retval true If field type is temporal type with time part.
134  @retval false If field type is not temporal type with time part.
135 */
137  switch (type) {
138  case MYSQL_TYPE_TIME:
139  case MYSQL_TYPE_DATETIME:
141  return true;
142  default:
143  return false;
144  }
145 }
146 
147 /**
148  Tests if field type is temporal and has date part,
149  i.e. represents DATE, DATETIME or TIMESTAMP types in SQL.
150 
151  @param type Field type, as returned by field->type().
152  @retval true If field type is temporal type with date part.
153  @retval false If field type is not temporal type with date part.
154 */
156  switch (type) {
157  case MYSQL_TYPE_DATE:
158  case MYSQL_TYPE_DATETIME:
160  return true;
161  default:
162  return false;
163  }
164 }
165 
166 /**
167  Tests if field type is temporal and has date and time parts,
168  i.e. represents DATETIME or TIMESTAMP types in SQL.
169 
170  @param type Field type, as returned by field->type().
171  @retval true If field type is temporal type with date and time parts.
172  @retval false If field type is not temporal type with date and time parts.
173 */
175  switch (type) {
176  case MYSQL_TYPE_DATETIME:
178  return true;
179  default:
180  return false;
181  }
182 }
183 
184 /**
185  Recognizer for concrete data type (called real_type for some reason),
186  returning true if it is one of the TIMESTAMP types.
187 */
190 }
191 
192 /**
193  Test if the field type contains information on being signed/unsigned.
194  This includes numeric but also YEAR that still contains sign modifiers
195  even if ignored.
196 
197  @param type Field type, as returned by field->type()
198 
199  @returns true if the type contains info on being signed/unsigned
200 */
202  switch (type) {
203  case MYSQL_TYPE_TINY:
204  case MYSQL_TYPE_SHORT:
205  case MYSQL_TYPE_INT24:
206  case MYSQL_TYPE_LONG:
207  case MYSQL_TYPE_LONGLONG:
208  case MYSQL_TYPE_YEAR:
209  case MYSQL_TYPE_FLOAT:
210  case MYSQL_TYPE_DOUBLE:
211  case MYSQL_TYPE_DECIMAL:
213  return true;
214  default:
215  return false;
216  }
217 }
218 
219 #endif /* FIELD_COMMON_OPERATIONS_INCLUDED */
bool is_temporal_type_with_time(enum_field_types type)
Tests if field type is temporal and has time part, i.e.
Definition: field_common_properties.h:136
bool is_temporal_type(enum_field_types type)
Tests if field type is temporal, i.e.
Definition: field_common_properties.h:114
bool is_string_type(enum_field_types type)
Tests if field type is a string type.
Definition: field_common_properties.h:88
bool is_integer_type(enum_field_types type)
Tests if field type is an integer.
Definition: field_common_properties.h:44
bool is_timestamp_type(enum_field_types type)
Recognizer for concrete data type (called real_type for some reason), returning true if it is one of ...
Definition: field_common_properties.h:188
bool is_numeric_type(enum_field_types type)
Tests if field type is a numeric type.
Definition: field_common_properties.h:64
bool is_temporal_type_with_date(enum_field_types type)
Tests if field type is temporal and has date part, i.e.
Definition: field_common_properties.h:155
bool has_signedess_information_type(enum_field_types type)
Test if the field type contains information on being signed/unsigned.
Definition: field_common_properties.h:201
bool is_temporal_type_with_date_and_time(enum_field_types type)
Tests if field type is temporal and has date and time parts, i.e.
Definition: field_common_properties.h:174
This file contains the field type.
enum_field_types
Column types for MySQL.
Definition: field_types.h:57
@ MYSQL_TYPE_VARCHAR
Definition: field_types.h:72
@ MYSQL_TYPE_LONGLONG
Definition: field_types.h:65
@ MYSQL_TYPE_LONG_BLOB
Definition: field_types.h:86
@ MYSQL_TYPE_VAR_STRING
Definition: field_types.h:88
@ MYSQL_TYPE_BLOB
Definition: field_types.h:87
@ MYSQL_TYPE_TINY
Definition: field_types.h:58
@ MYSQL_TYPE_TIME
Definition: field_types.h:68
@ MYSQL_TYPE_SET
Definition: field_types.h:83
@ MYSQL_TYPE_NEWDATE
Internal to MySQL.
Definition: field_types.h:71
@ MYSQL_TYPE_JSON
Definition: field_types.h:80
@ MYSQL_TYPE_STRING
Definition: field_types.h:89
@ MYSQL_TYPE_ENUM
Definition: field_types.h:82
@ MYSQL_TYPE_TINY_BLOB
Definition: field_types.h:84
@ MYSQL_TYPE_LONG
Definition: field_types.h:60
@ MYSQL_TYPE_NEWDECIMAL
Definition: field_types.h:81
@ MYSQL_TYPE_DECIMAL
Definition: field_types.h:57
@ MYSQL_TYPE_DOUBLE
Definition: field_types.h:62
@ MYSQL_TYPE_MEDIUM_BLOB
Definition: field_types.h:85
@ MYSQL_TYPE_SHORT
Definition: field_types.h:59
@ MYSQL_TYPE_DATE
Definition: field_types.h:67
@ MYSQL_TYPE_FLOAT
Definition: field_types.h:61
@ MYSQL_TYPE_TIMESTAMP
Definition: field_types.h:64
@ MYSQL_TYPE_INT24
Definition: field_types.h:66
@ MYSQL_TYPE_DATETIME
Definition: field_types.h:69
@ MYSQL_TYPE_TIMESTAMP2
Definition: field_types.h:74
@ MYSQL_TYPE_YEAR
Definition: field_types.h:70
required string type
Definition: replication_group_member_actions.proto:33