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
34
35namespace mrs {
36namespace database {
37
39 public:
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},
51 {"DOUBLE", entry::ColumnType::DOUBLE},
52 {"DECIMAL", entry::ColumnType::DOUBLE},
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},
61 {"MEDIUMTEXT", entry::ColumnType::STRING},
62 {"LONGTEXT", entry::ColumnType::STRING},
63 {"TINYBLOB", entry::ColumnType::BINARY},
65 {"MEDIUMBLOB", entry::ColumnType::BINARY},
66 {"LONGBLOB", entry::ColumnType::BINARY},
68 {"DATETIME", entry::ColumnType::STRING},
72 {"TIMESTAMP", entry::ColumnType::STRING},
73 {"GEOMETRY", 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},
83 {"BOOLEAN", entry::ColumnType::BOOLEAN},
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)") {
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 */
Definition: column_datatype_converter.h:38
void operator()(entry::ColumnType *out, const std::string &datatype) const
Definition: column_datatype_converter.h:91
const std::map< std::string, entry::ColumnType > & get_map() const
Definition: column_datatype_converter.h:42
ColumnDatatypeConverter()
Definition: column_datatype_converter.h:40
const char * p
Definition: ctype-mb.cc:1227
ColumnType
Definition: column_type.h:48
Definition: authorize_manager.h:48
HARNESS_EXPORT std::string make_upper(std::string s)
upper-case a string.
Definition: string_utils.cc:89