1//===----------------------------------------------------------------------===//
2// DuckDB
3//
4// duckdb/common/exception_format_value.hpp
5//
6//
7//===----------------------------------------------------------------------===//
8
9#pragma once
10
11#include "duckdb/common/string.hpp"
12#include "duckdb/common/hugeint.hpp"
13
14#include <vector>
15
16namespace duckdb {
17
18// Helper class to support custom overloading
19// Escaping " and quoting the value with "
20class SQLIdentifier {
21public:
22 SQLIdentifier(const string &raw_string) : raw_string(raw_string) {
23 }
24
25public:
26 string raw_string;
27};
28
29// Helper class to support custom overloading
30// Escaping ' and quoting the value with '
31class SQLString {
32public:
33 SQLString(const string &raw_string) : raw_string(raw_string) {
34 }
35
36public:
37 string raw_string;
38};
39
40enum class PhysicalType : uint8_t;
41struct LogicalType;
42
43enum class ExceptionFormatValueType : uint8_t {
44 FORMAT_VALUE_TYPE_DOUBLE,
45 FORMAT_VALUE_TYPE_INTEGER,
46 FORMAT_VALUE_TYPE_STRING
47};
48
49struct ExceptionFormatValue {
50 DUCKDB_API ExceptionFormatValue(double dbl_val); // NOLINT
51 DUCKDB_API ExceptionFormatValue(int64_t int_val); // NOLINT
52 DUCKDB_API ExceptionFormatValue(string str_val); // NOLINT
53 DUCKDB_API ExceptionFormatValue(hugeint_t hg_val); // NOLINT
54
55 ExceptionFormatValueType type;
56
57 double dbl_val = 0;
58 int64_t int_val = 0;
59 string str_val;
60
61public:
62 template <class T>
63 static ExceptionFormatValue CreateFormatValue(T value) {
64 return int64_t(value);
65 }
66 static string Format(const string &msg, std::vector<ExceptionFormatValue> &values);
67};
68
69template <>
70DUCKDB_API ExceptionFormatValue ExceptionFormatValue::CreateFormatValue(PhysicalType value);
71template <>
72DUCKDB_API ExceptionFormatValue ExceptionFormatValue::CreateFormatValue(SQLString value);
73template <>
74DUCKDB_API ExceptionFormatValue ExceptionFormatValue::CreateFormatValue(SQLIdentifier value);
75template <>
76DUCKDB_API ExceptionFormatValue ExceptionFormatValue::CreateFormatValue(LogicalType value);
77template <>
78DUCKDB_API ExceptionFormatValue ExceptionFormatValue::CreateFormatValue(float value);
79template <>
80DUCKDB_API ExceptionFormatValue ExceptionFormatValue::CreateFormatValue(double value);
81template <>
82DUCKDB_API ExceptionFormatValue ExceptionFormatValue::CreateFormatValue(string value);
83template <>
84DUCKDB_API ExceptionFormatValue ExceptionFormatValue::CreateFormatValue(const char *value);
85template <>
86DUCKDB_API ExceptionFormatValue ExceptionFormatValue::CreateFormatValue(char *value);
87template <>
88DUCKDB_API ExceptionFormatValue ExceptionFormatValue::CreateFormatValue(hugeint_t value);
89
90} // namespace duckdb
91