MySQL 9.3.0
Source Code Documentation
column.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2017, 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, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
19 * the GNU General Public License, version 2.0, 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 Foundation, Inc.,
23 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 */
25
26// MySQL DB access module, for use by plugins and others
27// For the module that implements interactive DB functionality see mod_db
28
29#ifndef _CORELIBS_DB_COLUMN_H_
30#define _CORELIBS_DB_COLUMN_H_
31#include <cstdint>
32#include <string>
33
35
36namespace shcore {
37namespace polyglot {
38namespace database {
39/*
40 * We require a common representation of the MySQL data MySQL data types
41 * So it can be used no matter the source of the metadata information
42 * (MySQL protocol or XProtocol)
43 */
45
46std::string to_string(Type type);
47Type string_to_type(const std::string &type);
48
49inline bool is_string_type(Type type) {
50 return (type == Type::Bytes || type == Type::Geometry || type == Type::Json ||
53 type == Type::Vector);
54}
55
56inline bool is_binary_type(Type type) {
57 return (type == Type::Bytes || type == Type::Geometry ||
58 type == Type::Vector);
59}
60
61std::string type_to_dbstring(Type type, uint32_t length = 0);
62
63Type dbstring_to_type(const std::string &data_type,
64 const std::string &column_type);
65
66/**
67 * These class represents a protocol independent Column
68 * The Resultset implementation for each protocol should
69 * make sure the metadata is represented on instances of this
70 * class.
71 *
72 * This class aligns with the Column API as specified
73 * on the DevAPI.
74 */
76 public:
77 Column(const std::string &catalog, const std::string &schema,
78 const std::string &table_name, const std::string &table_label,
79 const std::string &column_name, const std::string &column_label,
80 uint32_t length, int frac_digits, Type type, uint32_t collation_id,
81 bool unsigned_, bool zerofill, bool binary,
82 const std::string &flags = "", const std::string &db_type = "");
83
84 bool operator==(const Column &o) const {
85 return _schema == o._schema && _table_name == o._table_name &&
89 _fractional == o._fractional && _type == o._type &&
91 _binary == o._binary;
92 }
93
94 const std::string &get_catalog() const override { return _catalog; }
95 const std::string &get_schema() const override { return _schema; }
96 const std::string &get_table_name() const override { return _table_name; }
97 const std::string &get_table_label() const override { return _table_label; }
98 const std::string &get_column_name() const override { return _column_name; }
99 const std::string &get_column_label() const override { return _column_label; }
100 uint32_t get_length() const override { return _length; }
101 int get_fractional() const override { return _fractional; }
102 Type get_type() const override { return _type; }
103 std::string get_dbtype() const override;
104 // std::string get_collation_name() const;
105 // std::string get_charset_name() const;
106 uint32_t get_collation() const override { return _collation_id; }
107 const std::string &get_flags() const override { return _flags; }
108
109 bool is_unsigned() const override { return _unsigned; }
110 bool is_zerofill() const override { return _zerofill; }
111 bool is_binary() const override { return _binary; }
112 bool is_numeric() const override;
113
114 friend std::string to_string(const Column &c);
115
116 private:
117 std::string _catalog;
118 std::string _schema;
119 std::string _table_name;
120 std::string _table_label;
121 std::string _column_name;
122 std::string _column_label;
124 uint32_t _length;
127 std::string _db_type;
128
129 // Flags
133 std::string _flags;
134};
135} // namespace database
136} // namespace polyglot
137} // namespace shcore
138#endif
std::string String
Definition: bootstrap_configurator.h:43
Definition: jit_executor_db_interface.h:57
These class represents a protocol independent Column The Resultset implementation for each protocol s...
Definition: column.h:75
bool operator==(const Column &o) const
Definition: column.h:84
const std::string & get_table_name() const override
Definition: column.h:96
friend std::string to_string(const Column &c)
Definition: column.cc:295
bool _binary
Definition: column.h:132
bool is_unsigned() const override
Definition: column.h:109
Type get_type() const override
Definition: column.h:102
const std::string & get_table_label() const override
Definition: column.h:97
std::string _db_type
Definition: column.h:127
uint32_t _collation_id
Definition: column.h:123
std::string _table_name
Definition: column.h:119
const std::string & get_column_label() const override
Definition: column.h:99
Type _type
Definition: column.h:126
uint32_t get_collation() const override
Definition: column.h:106
bool _unsigned
Definition: column.h:130
std::string _flags
Definition: column.h:133
std::string _schema
Definition: column.h:118
std::string get_dbtype() const override
Definition: column.cc:212
const std::string & get_column_name() const override
Definition: column.h:98
int get_fractional() const override
Definition: column.h:101
const std::string & get_schema() const override
Definition: column.h:95
bool is_numeric() const override
Definition: column.cc:282
Column(const std::string &catalog, const std::string &schema, const std::string &table_name, const std::string &table_label, const std::string &column_name, const std::string &column_label, uint32_t length, int frac_digits, Type type, uint32_t collation_id, bool unsigned_, bool zerofill, bool binary, const std::string &flags="", const std::string &db_type="")
Definition: column.cc:189
uint32_t _length
Definition: column.h:124
bool _zerofill
Definition: column.h:131
const std::string & get_catalog() const override
Definition: column.h:94
uint32_t get_length() const override
Definition: column.h:100
std::string _table_label
Definition: column.h:120
int _fractional
Definition: column.h:125
std::string _column_label
Definition: column.h:122
bool is_zerofill() const override
Definition: column.h:110
const std::string & get_flags() const override
Definition: column.h:107
bool is_binary() const override
Definition: column.h:111
std::string _column_name
Definition: column.h:121
std::string _catalog
Definition: column.h:117
mrs::interface::RestHandler::HttpResult::Type Type
Definition: handler_content_file.cc:42
static int flags[50]
Definition: hp_test1.cc:40
borrowable::binary::Json< true > Json
Definition: classic_protocol_binary.h:334
borrowable::binary::Date Date
Definition: classic_protocol_binary.h:320
borrowable::binary::Time Time
Definition: classic_protocol_binary.h:319
borrowable::binary::Set< true > Set
Definition: classic_protocol_binary.h:331
borrowable::binary::Geometry< true > Geometry
Definition: classic_protocol_binary.h:335
borrowable::binary::DateTime DateTime
Definition: classic_protocol_binary.h:321
borrowable::binary::Enum< true > Enum
Definition: classic_protocol_binary.h:330
constexpr value_type zerofill
Definition: classic_protocol_constants.h:274
constexpr value_type binary
Definition: classic_protocol_constants.h:275
bool length(const dd::Spatial_reference_system *srs, const Geometry *g1, double *length, bool *null) noexcept
Computes the length of linestrings and multilinestrings.
Definition: length.cc:76
MediaType
Definition: media_type.h:33
Type
Definition: jit_executor_db_interface.h:37
const char * table_name
Definition: rules_table_service.cc:56
std::string type_to_dbstring(Type type, uint32_t length)
Definition: column.cc:118
Type dbstring_to_type(const std::string &data_type, const std::string &column_type)
Definition: column.cc:141
bool is_binary_type(Type type)
Definition: column.h:56
bool is_string_type(Type type)
Definition: column.h:49
std::string to_string(Type type)
Definition: column.cc:39
Type string_to_type(const std::string &type)
Definition: column.cc:79
Definition: file_system_exceptions.h:34
required string type
Definition: replication_group_member_actions.proto:34