MySQL
9.6.0
Source Code Documentation
column_datatype_converter.h
Go to the documentation of this file.
1
/*
2
Copyright (c) 2024, 2025, Oracle and/or its affiliates.
3
4
This program is free software; you can redistribute it and/or modify
5
it under the terms of the GNU General Public License, version 2.0,
6
as published by the Free Software Foundation.
7
8
This program is designed to work with certain software (including
9
but not limited to OpenSSL) that is licensed under separate terms,
10
as designated in a particular file or component or in included license
11
documentation. The authors of MySQL hereby grant you an additional
12
permission to link the program and your derivative works with the
13
separately licensed software that they have either included with
14
the program or referenced in the documentation.
15
16
This program is distributed in the hope that it will be useful,
17
but WITHOUT ANY WARRANTY; without even the implied warranty of
18
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
GNU General Public License for more details.
20
21
You should have received a copy of the GNU General Public License
22
along with this program; if not, write to the Free Software
23
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24
*/
25
26
#ifndef ROUTER_SRC_MYSQL_REST_SERVICE_SRC_MRS_DATABASE_CONVERTERS_COLUMN_DATATYPE_CONVERTER_H_
27
#define ROUTER_SRC_MYSQL_REST_SERVICE_SRC_MRS_DATABASE_CONVERTERS_COLUMN_DATATYPE_CONVERTER_H_
28
29
#include <map>
30
#include <string>
31
32
#include "
mrs/database/entry/object.h
"
33
#include "
mysql/harness/string_utils.h
"
34
35
namespace
mrs
{
36
namespace
database {
37
38
class
ColumnDatatypeConverter
{
39
public
:
40
ColumnDatatypeConverter
() {}
41
42
const
std::map<std::string, entry::ColumnType> &
get_map
()
const
{
43
const
static
std::map<std::string, entry::ColumnType> k_datatype_map{
44
{
"TINYINT"
,
entry::ColumnType::INTEGER
},
45
{
"SMALLINT"
,
entry::ColumnType::INTEGER
},
46
{
"MEDIUMINT"
,
entry::ColumnType::INTEGER
},
47
{
"INT"
,
entry::ColumnType::INTEGER
},
48
{
"BIGINT"
,
entry::ColumnType::INTEGER
},
49
{
"FLOAT"
,
entry::ColumnType::DOUBLE
},
50
{
"REAL"
,
entry::ColumnType::DOUBLE
},
51
{
"DOUBLE"
,
entry::ColumnType::DOUBLE
},
52
{
"DECIMAL"
,
entry::ColumnType::DOUBLE
},
53
{
"CHAR"
,
entry::ColumnType::STRING
},
54
{
"NCHAR"
,
entry::ColumnType::STRING
},
55
{
"VARCHAR"
,
entry::ColumnType::STRING
},
56
{
"NVARCHAR"
,
entry::ColumnType::STRING
},
57
{
"BINARY"
,
entry::ColumnType::BINARY
},
58
{
"VARBINARY"
,
entry::ColumnType::BINARY
},
59
{
"TINYTEXT"
,
entry::ColumnType::STRING
},
60
{
"TEXT"
,
entry::ColumnType::STRING
},
61
{
"MEDIUMTEXT"
,
entry::ColumnType::STRING
},
62
{
"LONGTEXT"
,
entry::ColumnType::STRING
},
63
{
"TINYBLOB"
,
entry::ColumnType::BINARY
},
64
{
"BLOB"
,
entry::ColumnType::BINARY
},
65
{
"MEDIUMBLOB"
,
entry::ColumnType::BINARY
},
66
{
"LONGBLOB"
,
entry::ColumnType::BINARY
},
67
{
"JSON"
,
entry::ColumnType::JSON
},
68
{
"DATETIME"
,
entry::ColumnType::STRING
},
69
{
"DATE"
,
entry::ColumnType::STRING
},
70
{
"TIME"
,
entry::ColumnType::STRING
},
71
{
"YEAR"
,
entry::ColumnType::INTEGER
},
72
{
"TIMESTAMP"
,
entry::ColumnType::STRING
},
73
{
"GEOMETRY"
,
entry::ColumnType::GEOMETRY
},
74
{
"POINT"
,
entry::ColumnType::GEOMETRY
},
75
{
"LINESTRING"
,
entry::ColumnType::GEOMETRY
},
76
{
"POLYGON"
,
entry::ColumnType::GEOMETRY
},
77
{
"GEOMCOLLECTION"
,
entry::ColumnType::GEOMETRY
},
78
{
"GEOMETRYCOLLECTION"
,
entry::ColumnType::GEOMETRY
},
79
{
"MULTIPOINT"
,
entry::ColumnType::GEOMETRY
},
80
{
"MULTILINESTRING"
,
entry::ColumnType::GEOMETRY
},
81
{
"MULTIPOLYGON"
,
entry::ColumnType::GEOMETRY
},
82
{
"BIT"
,
entry::ColumnType::BINARY
},
83
{
"BOOLEAN"
,
entry::ColumnType::BOOLEAN
},
84
{
"ENUM"
,
entry::ColumnType::STRING
},
85
{
"SET"
,
entry::ColumnType::STRING
},
86
{
"VECTOR"
,
entry::ColumnType::VECTOR
}};
87
88
return
k_datatype_map;
89
}
90
91
void
operator()
(
entry::ColumnType
*out,
const
std::string &datatype)
const
{
92
const
auto
&k_datatype_map =
get_map
();
93
auto
spc = datatype.find(
' '
);
94
auto
p
= datatype.find(
'('
);
95
96
p
= std::min(spc,
p
);
97
if
(
p
!= std::string::npos) {
98
if
(
auto
it = k_datatype_map.find(
99
mysql_harness::make_upper
(datatype.substr(0,
p
)));
100
it != k_datatype_map.end()) {
101
if
(it->second ==
entry::ColumnType::BINARY
) {
102
if
(
mysql_harness::make_upper
(datatype) ==
"BIT(1)"
) {
103
*out =
entry::ColumnType::BOOLEAN
;
104
return
;
105
}
106
}
107
*out = it->second;
108
return
;
109
}
110
}
else
{
111
if
(
auto
it = k_datatype_map.find(
mysql_harness::make_upper
(datatype));
112
it != k_datatype_map.end()) {
113
*out = it->second;
114
return
;
115
}
116
}
117
throw
std::runtime_error(
"Unknown datatype "
+ datatype);
118
}
119
};
120
121
}
// namespace database
122
}
// namespace mrs
123
124
#endif
/* ROUTER_SRC_MYSQL_REST_SERVICE_SRC_MRS_DATABASE_CONVERTERS_COLUMN_DATATYPE_CONVERTER_H_ \
125
*/
mrs::database::ColumnDatatypeConverter
Definition:
column_datatype_converter.h:38
mrs::database::ColumnDatatypeConverter::operator()
void operator()(entry::ColumnType *out, const std::string &datatype) const
Definition:
column_datatype_converter.h:91
mrs::database::ColumnDatatypeConverter::get_map
const std::map< std::string, entry::ColumnType > & get_map() const
Definition:
column_datatype_converter.h:42
mrs::database::ColumnDatatypeConverter::ColumnDatatypeConverter
ColumnDatatypeConverter()
Definition:
column_datatype_converter.h:40
p
const char * p
Definition:
ctype-mb.cc:1227
mrs::database::entry::ColumnType
ColumnType
Definition:
column_type.h:48
mrs::database::entry::ColumnType::JSON
@ JSON
mrs::database::entry::ColumnType::INTEGER
@ INTEGER
mrs::database::entry::ColumnType::STRING
@ STRING
mrs::database::entry::ColumnType::VECTOR
@ VECTOR
mrs::database::entry::ColumnType::BINARY
@ BINARY
mrs::database::entry::ColumnType::GEOMETRY
@ GEOMETRY
mrs::database::entry::ColumnType::BOOLEAN
@ BOOLEAN
mrs::database::entry::ColumnType::DOUBLE
@ DOUBLE
mrs
Definition:
authorize_manager.h:48
mysql_harness::make_upper
HARNESS_EXPORT std::string make_upper(std::string s)
upper-case a string.
Definition:
string_utils.cc:89
object.h
string_utils.h
router
src
mysql_rest_service
src
mrs
database
converters
column_datatype_converter.h
Generated by
1.9.2