| 1 | #include "duckdb/planner/binder.hpp" |
| 2 | #include "duckdb/parser/statement/pragma_statement.hpp" |
| 3 | #include "duckdb/planner/operator/logical_pragma.hpp" |
| 4 | #include "duckdb/catalog/catalog_entry/pragma_function_catalog_entry.hpp" |
| 5 | #include "duckdb/catalog/catalog.hpp" |
| 6 | #include "duckdb/function/function_binder.hpp" |
| 7 | |
| 8 | namespace duckdb { |
| 9 | |
| 10 | BoundStatement Binder::Bind(PragmaStatement &stmt) { |
| 11 | // bind the pragma function |
| 12 | auto &entry = |
| 13 | Catalog::GetEntry<PragmaFunctionCatalogEntry>(context, INVALID_CATALOG, DEFAULT_SCHEMA, name: stmt.info->name); |
| 14 | string error; |
| 15 | FunctionBinder function_binder(context); |
| 16 | idx_t bound_idx = function_binder.BindFunction(name: entry.name, functions&: entry.functions, info&: *stmt.info, error); |
| 17 | if (bound_idx == DConstants::INVALID_INDEX) { |
| 18 | throw BinderException(FormatError(query_location: stmt.stmt_location, msg: error)); |
| 19 | } |
| 20 | auto bound_function = entry.functions.GetFunctionByOffset(offset: bound_idx); |
| 21 | if (!bound_function.function) { |
| 22 | throw BinderException("PRAGMA function does not have a function specified" ); |
| 23 | } |
| 24 | |
| 25 | // bind and check named params |
| 26 | QueryErrorContext error_context(root_statement, stmt.stmt_location); |
| 27 | BindNamedParameters(types&: bound_function.named_parameters, values&: stmt.info->named_parameters, error_context, |
| 28 | func_name&: bound_function.name); |
| 29 | |
| 30 | BoundStatement result; |
| 31 | result.names = {"Success" }; |
| 32 | result.types = {LogicalType::BOOLEAN}; |
| 33 | result.plan = make_uniq<LogicalPragma>(args&: bound_function, args&: *stmt.info); |
| 34 | properties.return_type = StatementReturnType::QUERY_RESULT; |
| 35 | return result; |
| 36 | } |
| 37 | |
| 38 | } // namespace duckdb |
| 39 | |