MySQL 8.1.0
Source Code Documentation
field_common_properties.h
Go to the documentation of this file.
1/* Copyright (c) 2020, 2023, 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:
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:
69 case MYSQL_TYPE_LONG:
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) {
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:
119 case MYSQL_TYPE_DATE:
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:
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 // A type which is_temporal_type() but not is_temporal_type_with_date() ?
157 assert(type != MYSQL_TYPE_NEWDATE);
158 switch (type) {
159 case MYSQL_TYPE_DATE:
162 return true;
163 default:
164 return false;
165 }
166}
167
168/**
169 Tests if field type is temporal and has date and time parts,
170 i.e. represents DATETIME or TIMESTAMP types in SQL.
171
172 @param type Field type, as returned by field->type().
173 @retval true If field type is temporal type with date and time parts.
174 @retval false If field type is not temporal type with date and time parts.
175*/
177 switch (type) {
180 return true;
181 default:
182 return false;
183 }
184}
185
186/**
187 Recognizer for concrete data type (called real_type for some reason),
188 returning true if it is one of the TIMESTAMP types.
189*/
192}
193
194/**
195 Test if the field type contains information on being signed/unsigned.
196 This includes numeric but also YEAR that still contains sign modifiers
197 even if ignored.
198
199 @param type Field type, as returned by field->type()
200
201 @returns true if the type contains info on being signed/unsigned
202*/
204 switch (type) {
205 case MYSQL_TYPE_TINY:
206 case MYSQL_TYPE_SHORT:
207 case MYSQL_TYPE_INT24:
208 case MYSQL_TYPE_LONG:
210 case MYSQL_TYPE_YEAR:
211 case MYSQL_TYPE_FLOAT:
215 return true;
216 default:
217 return false;
218 }
219}
220
221#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:190
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:203
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:176
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:54
@ MYSQL_TYPE_VARCHAR
Definition: field_types.h:70
@ MYSQL_TYPE_LONGLONG
Definition: field_types.h:63
@ MYSQL_TYPE_LONG_BLOB
Definition: field_types.h:84
@ MYSQL_TYPE_VAR_STRING
Definition: field_types.h:86
@ MYSQL_TYPE_BLOB
Definition: field_types.h:85
@ MYSQL_TYPE_TINY
Definition: field_types.h:56
@ MYSQL_TYPE_TIME
Definition: field_types.h:66
@ MYSQL_TYPE_SET
Definition: field_types.h:81
@ MYSQL_TYPE_NEWDATE
Internal to MySQL.
Definition: field_types.h:69
@ MYSQL_TYPE_JSON
Definition: field_types.h:78
@ MYSQL_TYPE_STRING
Definition: field_types.h:87
@ MYSQL_TYPE_ENUM
Definition: field_types.h:80
@ MYSQL_TYPE_TINY_BLOB
Definition: field_types.h:82
@ MYSQL_TYPE_LONG
Definition: field_types.h:58
@ MYSQL_TYPE_NEWDECIMAL
Definition: field_types.h:79
@ MYSQL_TYPE_DECIMAL
Definition: field_types.h:55
@ MYSQL_TYPE_DOUBLE
Definition: field_types.h:60
@ MYSQL_TYPE_MEDIUM_BLOB
Definition: field_types.h:83
@ MYSQL_TYPE_SHORT
Definition: field_types.h:57
@ MYSQL_TYPE_DATE
Definition: field_types.h:65
@ MYSQL_TYPE_FLOAT
Definition: field_types.h:59
@ MYSQL_TYPE_TIMESTAMP
Definition: field_types.h:62
@ MYSQL_TYPE_INT24
Definition: field_types.h:64
@ MYSQL_TYPE_DATETIME
Definition: field_types.h:67
@ MYSQL_TYPE_TIMESTAMP2
Definition: field_types.h:72
@ MYSQL_TYPE_YEAR
Definition: field_types.h:68
required string type
Definition: replication_group_member_actions.proto:33