Hyper API for C++ 0.0.21408
Hyper client library for C++ applications
Loading...
Searching...
No Matches
SqlType.hpp
Go to the documentation of this file.
1
5#ifndef TABLEAU_HYPER_SQLTYPE_HPP
6#define TABLEAU_HYPER_SQLTYPE_HPP
7
8#include <hyperapi/impl/infra.hpp>
9#include <string>
10#include <hyperapi/hyperapi.h>
11
12namespace hyperapi {
13
15static CONSTEXPR_OPTIONAL optional<internal::AnyType> null = {};
16
18enum class TypeTag : int {
19 Unsupported = HYPER_UNSUPPORTED,
20 Bool = HYPER_BOOL,
21 BigInt = HYPER_BIG_INT,
22 SmallInt = HYPER_SMALL_INT,
23 Int = HYPER_INT,
24 Numeric = HYPER_NUMERIC,
25 Float = HYPER_FLOAT,
26 Double = HYPER_DOUBLE,
27 Oid = HYPER_OID,
28 Bytes = HYPER_BYTE_A,
29 Text = HYPER_TEXT,
30 Varchar = HYPER_VARCHAR,
31 Char = HYPER_CHAR,
32 Json = HYPER_JSON,
33 Date = HYPER_DATE,
34 Interval = HYPER_INTERVAL,
35 Time = HYPER_TIME,
36 Timestamp = HYPER_TIMESTAMP,
37 TimestampTZ = HYPER_TIMESTAMP_TZ,
38 TabGeography = HYPER_TABGEOGRAPHY,
39 // Deprecated alias for `TabGeography`. Will be removed as part of W-17701666.
40 Geography = HYPER_GEOGRAPHY
41};
42
46class SqlType final {
47 public:
49 SqlType(TypeTag tag, uint32_t oid, hyper_type_modifier_t modifier = HYPER_UNUSED_MODIFIER) noexcept
50 : tag_(tag), internalOid_(oid), modifier_(modifier) {
51 }
52
56 TypeTag getTag() const noexcept { return tag_; }
57
63 uint32_t getInternalOid() const noexcept { return internalOid_; }
64
70 uint32_t getInternalTypeModifier() const noexcept { return modifier_; }
71
75 uint32_t getPrecision() const noexcept;
76
80 uint32_t getScale() const noexcept;
81
85 uint32_t getMaxLength() const noexcept;
86
92 std::string toString() const;
93
98 static SqlType boolean() noexcept { return {TypeTag::Bool, HYPER_OID_BOOL}; }
103 static SqlType bigInt() noexcept { return {TypeTag::BigInt, HYPER_OID_BIG_INT}; }
108 static SqlType smallInt() noexcept { return {TypeTag::SmallInt, HYPER_OID_SMALL_INT}; }
113 static SqlType integer() noexcept { return {TypeTag::Int, HYPER_OID_INT}; }
120 static SqlType numeric(uint16_t precision, uint16_t scale) noexcept { return {TypeTag::Numeric, HYPER_OID_NUMERIC, hyper_encode_numeric_modifier(precision, scale)}; }
125 static SqlType real() noexcept { return {TypeTag::Float, HYPER_OID_FLOAT}; }
130 static SqlType doublePrecision() noexcept { return {TypeTag::Double, HYPER_OID_DOUBLE}; }
135 static SqlType oid() noexcept { return {TypeTag::Oid, HYPER_OID_OID}; }
140 static SqlType bytes() noexcept { return {TypeTag::Bytes, HYPER_OID_BYTE_A}; }
145 static SqlType text() noexcept { return {TypeTag::Text, HYPER_OID_TEXT}; }
151 static SqlType varchar(uint32_t maxLength) noexcept { return {TypeTag::Varchar, HYPER_OID_VARCHAR, hyper_encode_string_modifier(maxLength)}; }
157 static SqlType character(uint32_t maxLength) noexcept { return {TypeTag::Char, static_cast<uint32_t>((maxLength == 1) ? HYPER_OID_CHAR1 : HYPER_OID_CHAR), hyper_encode_string_modifier(maxLength)}; }
162 static SqlType json() noexcept { return {TypeTag::Json, HYPER_OID_JSON}; }
167 static SqlType date() noexcept { return {TypeTag::Date, HYPER_OID_DATE}; }
172 static SqlType interval() noexcept { return {TypeTag::Interval, HYPER_OID_INTERVAL}; }
177 static SqlType time() noexcept { return {TypeTag::Time, HYPER_OID_TIME}; }
182 static SqlType timestamp() noexcept { return {TypeTag::Timestamp, HYPER_OID_TIMESTAMP}; }
187 static SqlType timestampTZ() noexcept { return {TypeTag::TimestampTZ, HYPER_OID_TIMESTAMP_TZ}; }
192 static SqlType tabgeography() noexcept { return {TypeTag::TabGeography, HYPER_OID_TABGEOGRAPHY}; }
197 static SqlType geography() noexcept { return {TypeTag::Geography, HYPER_OID_GEOGRAPHY}; }
198
202 friend bool operator==(const SqlType& a, const SqlType& b) noexcept;
206 friend bool operator>(const SqlType& a, const SqlType& b) noexcept;
210 friend bool operator!=(const SqlType& a, const SqlType& b) noexcept;
214 friend bool operator<(const SqlType& a, const SqlType& b) noexcept;
218 friend bool operator<=(const SqlType& a, const SqlType& b) noexcept;
222 friend bool operator>=(const SqlType& a, const SqlType& b) noexcept;
226 friend std::ostream& operator<<(std::ostream& os, const SqlType& obj);
227
228 private:
230 TypeTag tag_;
232 uint32_t internalOid_;
234 hyper_type_modifier_t modifier_;
235
236 friend class internal::HyperTableDefinition;
237 friend struct std::hash<hyperapi::SqlType>;
238};
239}
240
241namespace std {
242
244template <>
245struct hash<hyperapi::SqlType> {
247 size_t operator()(const hyperapi::SqlType& type) const noexcept { return (static_cast<size_t>(type.tag_) << 32) | type.modifier_; }
248};
249}
250
251#include <hyperapi/impl/SqlType.impl.hpp>
252
253#endif
A date data value.
Definition Date.hpp:18
An interval data value.
Definition Interval.hpp:18
A fixed-point numeric data value with scale fraction digits and precision digits overall.
Definition Numeric.hpp:47
A Hyper SQL type.
Definition SqlType.hpp:46
static SqlType tabgeography() noexcept
Returns the TABGEOGRAPHY SQL type.
Definition SqlType.hpp:192
uint32_t getInternalOid() const noexcept
Returns the internal oid.
Definition SqlType.hpp:63
static SqlType smallInt() noexcept
Returns the SMALL INTEGER SQL type.
Definition SqlType.hpp:108
static SqlType geography() noexcept
Returns the GEOGRAPHY SQL type.
Definition SqlType.hpp:197
static SqlType character(uint32_t maxLength) noexcept
Returns the CHARACTER SQL type.
Definition SqlType.hpp:157
static SqlType real() noexcept
Returns the REAL SQL type.
Definition SqlType.hpp:125
static SqlType numeric(uint16_t precision, uint16_t scale) noexcept
Returns the NUMERIC SQL type.
Definition SqlType.hpp:120
friend bool operator==(const SqlType &a, const SqlType &b) noexcept
Equality operator.
friend std::ostream & operator<<(std::ostream &os, const SqlType &obj)
Stream output operator.
SqlType(TypeTag tag, uint32_t oid, hyper_type_modifier_t modifier=HYPER_UNUSED_MODIFIER) noexcept
Constructor.
Definition SqlType.hpp:49
TypeTag getTag() const noexcept
Returns the type tag.
Definition SqlType.hpp:56
static SqlType timestampTZ() noexcept
Returns the TIMESTAMPTZ SQL type.
Definition SqlType.hpp:187
uint32_t getScale() const noexcept
Returns the scale parameter of the type if the type supports it, HYPER_UNUSED_MODIFIER otherwise.
uint32_t getMaxLength() const noexcept
Returns the maximum length parameter of the type if the type supports it, HYPER_UNUSED_MODIFIER other...
uint32_t getInternalTypeModifier() const noexcept
Returns the internal type modifier.
Definition SqlType.hpp:70
static SqlType json() noexcept
Returns the JSON SQL type.
Definition SqlType.hpp:162
static SqlType bytes() noexcept
Returns the BYTEA SQL type.
Definition SqlType.hpp:140
static SqlType oid() noexcept
Returns the OID SQL type.
Definition SqlType.hpp:135
static SqlType bigInt() noexcept
Returns the BIG INTEGER SQL type.
Definition SqlType.hpp:103
friend bool operator<=(const SqlType &a, const SqlType &b) noexcept
Smaller or equal operator.
static SqlType text() noexcept
Returns the TEXT SQL type.
Definition SqlType.hpp:145
static SqlType interval() noexcept
Returns the INTERVAL SQL type.
Definition SqlType.hpp:172
friend bool operator>=(const SqlType &a, const SqlType &b) noexcept
Greater or equal operator.
static SqlType date() noexcept
Returns the DATE SQL type.
Definition SqlType.hpp:167
static SqlType integer() noexcept
Returns the INTEGER SQL type.
Definition SqlType.hpp:113
static SqlType varchar(uint32_t maxLength) noexcept
Returns the VARCHAR SQL type.
Definition SqlType.hpp:151
static SqlType time() noexcept
Returns the TIME SQL type.
Definition SqlType.hpp:177
friend bool operator>(const SqlType &a, const SqlType &b) noexcept
Greater operator.
uint32_t getPrecision() const noexcept
Returns the maximum precision parameter of the type if the type supports it, HYPER_UNUSED_MODIFIER ot...
static SqlType doublePrecision() noexcept
Returns the DOUBLE PRECISION SQL type.
Definition SqlType.hpp:130
friend bool operator<(const SqlType &a, const SqlType &b) noexcept
Smaller operator.
std::string toString() const
Returns a string representation for debugging.
static SqlType timestamp() noexcept
Returns the TIMESTAMP SQL type.
Definition SqlType.hpp:182
friend bool operator!=(const SqlType &a, const SqlType &b) noexcept
Not equal operator.
A time data value.
Definition Time.hpp:18
A timestamp data value.
Definition Timestamp.hpp:16
The primary namespace of the Hyper API for C++.
Definition ByteSpan.hpp:15
TypeTag
A type tag.
Definition SqlType.hpp:18
size_t operator()(const hyperapi::SqlType &type) const noexcept
Calculates the hash value of the given SQL type.
Definition SqlType.hpp:247