/src/duckdb/src/function/table/version/pragma_version.cpp
Line | Count | Source |
1 | | #include "duckdb/function/table/system_functions.hpp" |
2 | | #include "duckdb/main/database.hpp" |
3 | | #include "duckdb/common/string_util.hpp" |
4 | | #include "duckdb/common/platform.hpp" |
5 | | |
6 | | #include <cstdint> |
7 | | |
8 | | namespace duckdb { |
9 | | |
10 | | struct PragmaVersionData : public GlobalTableFunctionState { |
11 | 0 | PragmaVersionData() : finished(false) { |
12 | 0 | } |
13 | | |
14 | | bool finished; |
15 | | }; |
16 | | |
17 | | static unique_ptr<FunctionData> PragmaVersionBind(ClientContext &context, TableFunctionBindInput &input, |
18 | 0 | vector<LogicalType> &return_types, vector<string> &names) { |
19 | 0 | names.emplace_back("library_version"); |
20 | 0 | return_types.emplace_back(LogicalType::VARCHAR); |
21 | 0 | names.emplace_back("source_id"); |
22 | 0 | return_types.emplace_back(LogicalType::VARCHAR); |
23 | 0 | names.emplace_back("codename"); |
24 | 0 | return_types.emplace_back(LogicalType::VARCHAR); |
25 | 0 | return nullptr; |
26 | 0 | } |
27 | | |
28 | 0 | static unique_ptr<GlobalTableFunctionState> PragmaVersionInit(ClientContext &context, TableFunctionInitInput &input) { |
29 | 0 | return make_uniq<PragmaVersionData>(); |
30 | 0 | } |
31 | | |
32 | 0 | static void PragmaVersionFunction(ClientContext &context, TableFunctionInput &data_p, DataChunk &output) { |
33 | 0 | auto &data = data_p.global_state->Cast<PragmaVersionData>(); |
34 | 0 | if (data.finished) { |
35 | | // finished returning values |
36 | 0 | return; |
37 | 0 | } |
38 | 0 | output.SetCardinality(1); |
39 | 0 | output.SetValue(0, 0, DuckDB::LibraryVersion()); |
40 | 0 | output.SetValue(1, 0, DuckDB::SourceID()); |
41 | 0 | output.SetValue(2, 0, DuckDB::ReleaseCodename()); |
42 | |
|
43 | 0 | data.finished = true; |
44 | 0 | } |
45 | | |
46 | 7.90k | void PragmaVersion::RegisterFunction(BuiltinFunctions &set) { |
47 | 7.90k | TableFunction pragma_version("pragma_version", {}, PragmaVersionFunction); |
48 | 7.90k | pragma_version.bind = PragmaVersionBind; |
49 | 7.90k | pragma_version.init_global = PragmaVersionInit; |
50 | 7.90k | set.AddFunction(pragma_version); |
51 | 7.90k | } |
52 | | |
53 | 0 | idx_t DuckDB::StandardVectorSize() { |
54 | 0 | return STANDARD_VECTOR_SIZE; |
55 | 0 | } |
56 | | |
57 | 29 | const char *DuckDB::SourceID() { |
58 | 29 | return DUCKDB_SOURCE_ID; |
59 | 29 | } |
60 | | |
61 | 303 | const char *DuckDB::LibraryVersion() { |
62 | 303 | return DUCKDB_VERSION; |
63 | 303 | } |
64 | | |
65 | 0 | const char *DuckDB::ReleaseCodename() { |
66 | | // dev releases have no name |
67 | 0 | if (StringUtil::Contains(DUCKDB_VERSION, "-dev")) { |
68 | 0 | return "Development Version"; |
69 | 0 | } |
70 | 0 | if (StringUtil::StartsWith(DUCKDB_VERSION, "v1.2.")) { |
71 | 0 | return "Histrionicus"; |
72 | 0 | } |
73 | 0 | if (StringUtil::StartsWith(DUCKDB_VERSION, "v1.3.")) { |
74 | 0 | return "Ossivalis"; |
75 | 0 | } |
76 | 0 | if (StringUtil::StartsWith(DUCKDB_VERSION, "v1.4.")) { |
77 | 0 | return "Andium"; |
78 | 0 | } |
79 | 0 | if (StringUtil::StartsWith(DUCKDB_VERSION, "v1.5.")) { |
80 | 0 | return "Variegata"; |
81 | 0 | } |
82 | | // add new version names here |
83 | | |
84 | | // we should not get here, but let's not fail because of it because tags on forks can be whatever |
85 | 0 | return "Unknown Version"; |
86 | 0 | } |
87 | | |
88 | 166 | string DuckDB::Platform() { |
89 | 166 | return DuckDBPlatform(); |
90 | 166 | } |
91 | | |
92 | | struct PragmaPlatformData : public GlobalTableFunctionState { |
93 | 0 | PragmaPlatformData() : finished(false) { |
94 | 0 | } |
95 | | |
96 | | bool finished; |
97 | | }; |
98 | | |
99 | | static unique_ptr<FunctionData> PragmaPlatformBind(ClientContext &context, TableFunctionBindInput &input, |
100 | 0 | vector<LogicalType> &return_types, vector<string> &names) { |
101 | 0 | names.emplace_back("platform"); |
102 | 0 | return_types.emplace_back(LogicalType::VARCHAR); |
103 | 0 | return nullptr; |
104 | 0 | } |
105 | | |
106 | 0 | static unique_ptr<GlobalTableFunctionState> PragmaPlatformInit(ClientContext &context, TableFunctionInitInput &input) { |
107 | 0 | return make_uniq<PragmaPlatformData>(); |
108 | 0 | } |
109 | | |
110 | 0 | static void PragmaPlatformFunction(ClientContext &context, TableFunctionInput &data_p, DataChunk &output) { |
111 | 0 | auto &data = data_p.global_state->Cast<PragmaPlatformData>(); |
112 | 0 | if (data.finished) { |
113 | | // finished returning values |
114 | 0 | return; |
115 | 0 | } |
116 | 0 | output.SetCardinality(1); |
117 | 0 | output.SetValue(0, 0, DuckDB::Platform()); |
118 | 0 | data.finished = true; |
119 | 0 | } |
120 | | |
121 | 7.90k | void PragmaPlatform::RegisterFunction(BuiltinFunctions &set) { |
122 | 7.90k | TableFunction pragma_platform("pragma_platform", {}, PragmaPlatformFunction); |
123 | 7.90k | pragma_platform.bind = PragmaPlatformBind; |
124 | 7.90k | pragma_platform.init_global = PragmaPlatformInit; |
125 | 7.90k | set.AddFunction(pragma_platform); |
126 | 7.90k | } |
127 | | |
128 | | } // namespace duckdb |