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