1 | #include "duckdb/main/capi/capi_internal.hpp" |
---|---|
2 | #include "duckdb/main/config.hpp" |
3 | #include "duckdb/common/types/value.hpp" |
4 | |
5 | using duckdb::DBConfig; |
6 | using duckdb::Value; |
7 | |
8 | // config |
9 | duckdb_state duckdb_create_config(duckdb_config *out_config) { |
10 | if (!out_config) { |
11 | return DuckDBError; |
12 | } |
13 | DBConfig *config; |
14 | try { |
15 | config = new DBConfig(); |
16 | } catch (...) { // LCOV_EXCL_START |
17 | return DuckDBError; |
18 | } // LCOV_EXCL_STOP |
19 | *out_config = reinterpret_cast<duckdb_config>(config); |
20 | return DuckDBSuccess; |
21 | } |
22 | |
23 | size_t duckdb_config_count() { |
24 | return DBConfig::GetOptionCount(); |
25 | } |
26 | |
27 | duckdb_state duckdb_get_config_flag(size_t index, const char **out_name, const char **out_description) { |
28 | auto option = DBConfig::GetOptionByIndex(index); |
29 | if (!option) { |
30 | return DuckDBError; |
31 | } |
32 | if (out_name) { |
33 | *out_name = option->name; |
34 | } |
35 | if (out_description) { |
36 | *out_description = option->description; |
37 | } |
38 | return DuckDBSuccess; |
39 | } |
40 | |
41 | duckdb_state duckdb_set_config(duckdb_config config, const char *name, const char *option) { |
42 | if (!config || !name || !option) { |
43 | return DuckDBError; |
44 | } |
45 | |
46 | try { |
47 | auto db_config = (DBConfig *)config; |
48 | db_config->SetOptionByName(name, value: Value(option)); |
49 | } catch (...) { |
50 | return DuckDBError; |
51 | } |
52 | return DuckDBSuccess; |
53 | } |
54 | |
55 | void duckdb_destroy_config(duckdb_config *config) { |
56 | if (!config) { |
57 | return; |
58 | } |
59 | if (*config) { |
60 | auto db_config = (DBConfig *)*config; |
61 | delete db_config; |
62 | *config = nullptr; |
63 | } |
64 | } |
65 |