MySQL 9.7.0
Source Code Documentation
field_common_properties.h
Go to the documentation of this file.
1/* Copyright (c) 2020, 2026, 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 Is this a simple string type? CHAR/VARCHAR/BINARY/VARBINARY and variants of
109 TEXT and BLOB are considered simple string types. Not string-like types with
110 special semantics, such as JSON, GEOMETRY and temporal types.
111
112 @param type Field type, as returned by field->type()
113
114 @returns true if simple string type, false otherwise
115*/
117 switch (type) {
122 case MYSQL_TYPE_BLOB:
125 return true;
126 default:
127 return false;
128 }
129}
130
131/**
132 Tests if field type is temporal, i.e. represents
133 DATE, TIME, DATETIME, TIMESTAMP or YEAR types in SQL.
134
135 @param type Field type, as returned by field->type().
136 @retval true If field type is temporal
137 @retval false If field type is not temporal
138*/
140 switch (type) {
141 case MYSQL_TYPE_TIME:
144 case MYSQL_TYPE_DATE:
146 case MYSQL_TYPE_YEAR:
147 return true;
148 default:
149 return false;
150 }
151}
152
153/**
154 Tests if field type is temporal and has time part,
155 i.e. represents TIME, DATETIME or TIMESTAMP types in SQL.
156
157 @param type Field type, as returned by field->type().
158 @retval true If field type is temporal type with time part.
159 @retval false If field type is not temporal type with time part.
160*/
162 switch (type) {
163 case MYSQL_TYPE_TIME:
166 return true;
167 default:
168 return false;
169 }
170}
171
172/**
173 Tests if field type is temporal and has date part,
174 i.e. represents DATE, DATETIME or TIMESTAMP types in SQL.
175
176 @param type Field type, as returned by field->type().
177 @retval true If field type is temporal type with date part.
178 @retval false If field type is not temporal type with date part.
179*/
181 // A type which is_temporal_type() but not is_temporal_type_with_date() ?
182 assert(type != MYSQL_TYPE_NEWDATE);
183 switch (type) {
184 case MYSQL_TYPE_DATE:
187 return true;
188 default:
189 return false;
190 }
191}
192
193/**
194 Tests if field type is temporal and has date and time parts,
195 i.e. represents DATETIME or TIMESTAMP types in SQL.
196
197 @param type Field type, as returned by field->type().
198 @retval true If field type is temporal type with date and time parts.
199 @retval false If field type is not temporal type with date and time parts.
200*/
202 switch (type) {
205 return true;
206 default:
207 return false;
208 }
209}
210
211/**
212 Recognizer for concrete data type (called real_type for some reason),
213 returning true if it is one of the TIMESTAMP types.
214*/
217}
218
219/**
220 Test if the field type contains information on being signed/unsigned.
221 This includes numeric but also YEAR that still contains sign modifiers
222 even if ignored.
223
224 @param type Field type, as returned by field->type()
225
226 @returns true if the type contains info on being signed/unsigned
227*/
229 switch (type) {
230 case MYSQL_TYPE_TINY:
231 case MYSQL_TYPE_SHORT:
232 case MYSQL_TYPE_INT24:
233 case MYSQL_TYPE_LONG:
235 case MYSQL_TYPE_YEAR:
236 case MYSQL_TYPE_FLOAT:
240 return true;
241 default:
242 return false;
243 }
244}
245
246#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:161
bool is_simple_string_type(enum_field_types type)
Is this a simple string type? CHAR/VARCHAR/BINARY/VARBINARY and variants of TEXT and BLOB are conside...
Definition: field_common_properties.h:116
bool is_temporal_type(enum_field_types type)
Tests if field type is temporal, i.e.
Definition: field_common_properties.h:139
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:215
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:180
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:228
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:201
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: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:57
@ MYSQL_TYPE_TIME
Definition: field_types.h:67
@ MYSQL_TYPE_SET
Definition: field_types.h:83
@ MYSQL_TYPE_NEWDATE
Internal to MySQL.
Definition: field_types.h:70
@ 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:59
@ MYSQL_TYPE_NEWDECIMAL
Definition: field_types.h:81
@ MYSQL_TYPE_DECIMAL
Definition: field_types.h:56
@ MYSQL_TYPE_DOUBLE
Definition: field_types.h:61
@ MYSQL_TYPE_MEDIUM_BLOB
Definition: field_types.h:85
@ 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