1 | #include "duckdb/execution/operator/helper/physical_reset.hpp" |
2 | |
3 | #include "duckdb/common/string_util.hpp" |
4 | #include "duckdb/main/database.hpp" |
5 | #include "duckdb/main/client_context.hpp" |
6 | |
7 | namespace duckdb { |
8 | |
9 | void PhysicalReset::ResetExtensionVariable(ExecutionContext &context, DBConfig &config, |
10 | ExtensionOption &extension_option) const { |
11 | if (extension_option.set_function) { |
12 | extension_option.set_function(context.client, scope, extension_option.default_value); |
13 | } |
14 | if (scope == SetScope::GLOBAL) { |
15 | config.ResetOption(name); |
16 | } else { |
17 | auto &client_config = ClientConfig::GetConfig(context&: context.client); |
18 | client_config.set_variables[name] = extension_option.default_value; |
19 | } |
20 | } |
21 | |
22 | SourceResultType PhysicalReset::GetData(ExecutionContext &context, DataChunk &chunk, OperatorSourceInput &input) const { |
23 | auto &config = DBConfig::GetConfig(context&: context.client); |
24 | if (config.options.lock_configuration) { |
25 | throw InvalidInputException("Cannot reset configuration option \"%s\" - the configuration has been locked" , |
26 | name); |
27 | } |
28 | auto option = DBConfig::GetOptionByName(name); |
29 | if (!option) { |
30 | // check if this is an extra extension variable |
31 | auto entry = config.extension_parameters.find(x: name); |
32 | if (entry == config.extension_parameters.end()) { |
33 | throw Catalog::UnrecognizedConfigurationError(context&: context.client, name); |
34 | } |
35 | ResetExtensionVariable(context, config, extension_option&: entry->second); |
36 | return SourceResultType::FINISHED; |
37 | } |
38 | |
39 | // Transform scope |
40 | SetScope variable_scope = scope; |
41 | if (variable_scope == SetScope::AUTOMATIC) { |
42 | if (option->set_local) { |
43 | variable_scope = SetScope::SESSION; |
44 | } else { |
45 | D_ASSERT(option->set_global); |
46 | variable_scope = SetScope::GLOBAL; |
47 | } |
48 | } |
49 | |
50 | switch (variable_scope) { |
51 | case SetScope::GLOBAL: { |
52 | if (!option->set_global) { |
53 | throw CatalogException("option \"%s\" cannot be reset globally" , name); |
54 | } |
55 | auto &db = DatabaseInstance::GetDatabase(context&: context.client); |
56 | config.ResetOption(db: &db, option: *option); |
57 | break; |
58 | } |
59 | case SetScope::SESSION: |
60 | if (!option->reset_local) { |
61 | throw CatalogException("option \"%s\" cannot be reset locally" , name); |
62 | } |
63 | option->reset_local(context.client); |
64 | break; |
65 | default: |
66 | throw InternalException("Unsupported SetScope for variable" ); |
67 | } |
68 | |
69 | return SourceResultType::FINISHED; |
70 | } |
71 | |
72 | } // namespace duckdb |
73 | |