1//===----------------------------------------------------------------------===//
2// DuckDB
3//
4// duckdb/function/pragma_function.hpp
5//
6//
7//===----------------------------------------------------------------------===//
8
9#pragma once
10
11#include "duckdb/function/function.hpp"
12#include "duckdb/parser/parsed_data/pragma_info.hpp"
13#include "duckdb/common/unordered_map.hpp"
14
15namespace duckdb {
16class ClientContext;
17
18//! Return a substitute query to execute instead of this pragma statement
19typedef string (*pragma_query_t)(ClientContext &context, const FunctionParameters &parameters);
20//! Execute the main pragma function
21typedef void (*pragma_function_t)(ClientContext &context, const FunctionParameters &parameters);
22
23//! Pragma functions are invoked by calling PRAGMA x
24//! Pragma functions come in three types:
25//! * Call: function call, e.g. PRAGMA table_info('tbl')
26//! -> call statements can take multiple parameters
27//! * Statement: statement without parameters, e.g. PRAGMA show_tables
28//! -> this is similar to a call pragma but without parameters
29//! Pragma functions can either return a new query to execute (pragma_query_t)
30//! or they can
31class PragmaFunction : public SimpleNamedParameterFunction {
32public:
33 // Call
34 DUCKDB_API static PragmaFunction PragmaCall(const string &name, pragma_query_t query, vector<LogicalType> arguments,
35 LogicalType varargs = LogicalType::INVALID);
36 DUCKDB_API static PragmaFunction PragmaCall(const string &name, pragma_function_t function,
37 vector<LogicalType> arguments,
38 LogicalType varargs = LogicalType::INVALID);
39 // Statement
40 DUCKDB_API static PragmaFunction PragmaStatement(const string &name, pragma_query_t query);
41 DUCKDB_API static PragmaFunction PragmaStatement(const string &name, pragma_function_t function);
42
43 DUCKDB_API string ToString() const override;
44
45public:
46 PragmaType type;
47
48 pragma_query_t query;
49 pragma_function_t function;
50 named_parameter_type_map_t named_parameters;
51
52private:
53 PragmaFunction(string name, PragmaType pragma_type, pragma_query_t query, pragma_function_t function,
54 vector<LogicalType> arguments, LogicalType varargs);
55};
56
57} // namespace duckdb
58