| 1 | #include "duckdb/catalog/default/default_schemas.hpp" |
|---|---|
| 2 | #include "duckdb/catalog/catalog_entry/duck_schema_entry.hpp" |
| 3 | #include "duckdb/common/string_util.hpp" |
| 4 | |
| 5 | namespace duckdb { |
| 6 | |
| 7 | struct DefaultSchema { |
| 8 | const char *name; |
| 9 | }; |
| 10 | |
| 11 | static DefaultSchema internal_schemas[] = {{.name: "information_schema"}, {.name: "pg_catalog"}, {.name: nullptr}}; |
| 12 | |
| 13 | static bool GetDefaultSchema(const string &input_schema) { |
| 14 | auto schema = StringUtil::Lower(str: input_schema); |
| 15 | for (idx_t index = 0; internal_schemas[index].name != nullptr; index++) { |
| 16 | if (internal_schemas[index].name == schema) { |
| 17 | return true; |
| 18 | } |
| 19 | } |
| 20 | return false; |
| 21 | } |
| 22 | |
| 23 | DefaultSchemaGenerator::DefaultSchemaGenerator(Catalog &catalog) : DefaultGenerator(catalog) { |
| 24 | } |
| 25 | |
| 26 | unique_ptr<CatalogEntry> DefaultSchemaGenerator::CreateDefaultEntry(ClientContext &context, const string &entry_name) { |
| 27 | if (GetDefaultSchema(input_schema: entry_name)) { |
| 28 | return make_uniq_base<CatalogEntry, DuckSchemaEntry>(args&: catalog, args: StringUtil::Lower(str: entry_name), args: true); |
| 29 | } |
| 30 | return nullptr; |
| 31 | } |
| 32 | |
| 33 | vector<string> DefaultSchemaGenerator::GetDefaultEntries() { |
| 34 | vector<string> result; |
| 35 | for (idx_t index = 0; internal_schemas[index].name != nullptr; index++) { |
| 36 | result.emplace_back(args&: internal_schemas[index].name); |
| 37 | } |
| 38 | return result; |
| 39 | } |
| 40 | |
| 41 | } // namespace duckdb |
| 42 |