| 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 | |
| 16 | namespace duckdb { |
| 17 | |
| 18 | // Helper class to support custom overloading |
| 19 | // Escaping " and quoting the value with " |
| 20 | class SQLIdentifier { |
| 21 | public: |
| 22 | SQLIdentifier(const string &raw_string) : raw_string(raw_string) { |
| 23 | } |
| 24 | |
| 25 | public: |
| 26 | string raw_string; |
| 27 | }; |
| 28 | |
| 29 | // Helper class to support custom overloading |
| 30 | // Escaping ' and quoting the value with ' |
| 31 | class SQLString { |
| 32 | public: |
| 33 | SQLString(const string &raw_string) : raw_string(raw_string) { |
| 34 | } |
| 35 | |
| 36 | public: |
| 37 | string raw_string; |
| 38 | }; |
| 39 | |
| 40 | enum class PhysicalType : uint8_t; |
| 41 | struct LogicalType; |
| 42 | |
| 43 | enum class ExceptionFormatValueType : uint8_t { |
| 44 | FORMAT_VALUE_TYPE_DOUBLE, |
| 45 | FORMAT_VALUE_TYPE_INTEGER, |
| 46 | FORMAT_VALUE_TYPE_STRING |
| 47 | }; |
| 48 | |
| 49 | struct 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 | |
| 61 | public: |
| 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 | |
| 69 | template <> |
| 70 | DUCKDB_API ExceptionFormatValue ExceptionFormatValue::CreateFormatValue(PhysicalType value); |
| 71 | template <> |
| 72 | DUCKDB_API ExceptionFormatValue ExceptionFormatValue::CreateFormatValue(SQLString value); |
| 73 | template <> |
| 74 | DUCKDB_API ExceptionFormatValue ExceptionFormatValue::CreateFormatValue(SQLIdentifier value); |
| 75 | template <> |
| 76 | DUCKDB_API ExceptionFormatValue ExceptionFormatValue::CreateFormatValue(LogicalType value); |
| 77 | template <> |
| 78 | DUCKDB_API ExceptionFormatValue ExceptionFormatValue::CreateFormatValue(float value); |
| 79 | template <> |
| 80 | DUCKDB_API ExceptionFormatValue ExceptionFormatValue::CreateFormatValue(double value); |
| 81 | template <> |
| 82 | DUCKDB_API ExceptionFormatValue ExceptionFormatValue::CreateFormatValue(string value); |
| 83 | template <> |
| 84 | DUCKDB_API ExceptionFormatValue ExceptionFormatValue::CreateFormatValue(const char *value); |
| 85 | template <> |
| 86 | DUCKDB_API ExceptionFormatValue ExceptionFormatValue::CreateFormatValue(char *value); |
| 87 | template <> |
| 88 | DUCKDB_API ExceptionFormatValue ExceptionFormatValue::CreateFormatValue(hugeint_t value); |
| 89 | |
| 90 | } // namespace duckdb |
| 91 |