1 | #include "duckdb/function/table/system_functions.hpp" |
2 | #include "duckdb/main/database.hpp" |
3 | |
4 | #include <cstdint> |
5 | |
6 | namespace duckdb { |
7 | |
8 | struct PragmaVersionData : public GlobalTableFunctionState { |
9 | PragmaVersionData() : finished(false) { |
10 | } |
11 | |
12 | bool finished; |
13 | }; |
14 | |
15 | static unique_ptr<FunctionData> PragmaVersionBind(ClientContext &context, TableFunctionBindInput &input, |
16 | vector<LogicalType> &return_types, vector<string> &names) { |
17 | names.emplace_back(args: "library_version" ); |
18 | return_types.emplace_back(args: LogicalType::VARCHAR); |
19 | names.emplace_back(args: "source_id" ); |
20 | return_types.emplace_back(args: LogicalType::VARCHAR); |
21 | return nullptr; |
22 | } |
23 | |
24 | static unique_ptr<GlobalTableFunctionState> PragmaVersionInit(ClientContext &context, TableFunctionInitInput &input) { |
25 | return make_uniq<PragmaVersionData>(); |
26 | } |
27 | |
28 | static void PragmaVersionFunction(ClientContext &context, TableFunctionInput &data_p, DataChunk &output) { |
29 | auto &data = data_p.global_state->Cast<PragmaVersionData>(); |
30 | if (data.finished) { |
31 | // finished returning values |
32 | return; |
33 | } |
34 | output.SetCardinality(1); |
35 | output.SetValue(col_idx: 0, index: 0, val: DuckDB::LibraryVersion()); |
36 | output.SetValue(col_idx: 1, index: 0, val: DuckDB::SourceID()); |
37 | data.finished = true; |
38 | } |
39 | |
40 | void PragmaVersion::RegisterFunction(BuiltinFunctions &set) { |
41 | TableFunction pragma_version("pragma_version" , {}, PragmaVersionFunction); |
42 | pragma_version.bind = PragmaVersionBind; |
43 | pragma_version.init_global = PragmaVersionInit; |
44 | set.AddFunction(function: pragma_version); |
45 | } |
46 | |
47 | idx_t DuckDB::StandardVectorSize() { |
48 | return STANDARD_VECTOR_SIZE; |
49 | } |
50 | |
51 | const char *DuckDB::SourceID() { |
52 | return DUCKDB_SOURCE_ID; |
53 | } |
54 | |
55 | const char *DuckDB::LibraryVersion() { |
56 | return DUCKDB_VERSION; |
57 | } |
58 | |
59 | string DuckDB::Platform() { |
60 | string os = "linux" ; |
61 | #if INTPTR_MAX == INT64_MAX |
62 | string arch = "amd64" ; |
63 | #elif INTPTR_MAX == INT32_MAX |
64 | string arch = "i686" ; |
65 | #else |
66 | #error Unknown pointer size or missing size macros! |
67 | #endif |
68 | string postfix = "" ; |
69 | |
70 | #ifdef _WIN32 |
71 | os = "windows" ; |
72 | #elif defined(__APPLE__) |
73 | os = "osx" ; |
74 | #endif |
75 | #if defined(__aarch64__) || defined(__ARM_ARCH_ISA_A64) |
76 | arch = "arm64" ; |
77 | #endif |
78 | |
79 | #if !defined(_GLIBCXX_USE_CXX11_ABI) || _GLIBCXX_USE_CXX11_ABI == 0 |
80 | if (os == "linux" ) { |
81 | postfix = "_gcc4" ; |
82 | } |
83 | #endif |
84 | #ifdef __MINGW32__ |
85 | postfix = "_mingw" ; |
86 | #endif |
87 | // this is used for the windows R builds which use a separate build environment |
88 | #ifdef DUCKDB_PLATFORM_RTOOLS |
89 | postfix = "_rtools" ; |
90 | #endif |
91 | return os + "_" + arch + postfix; |
92 | } |
93 | |
94 | } // namespace duckdb |
95 | |