1#include "duckdb/parser/transformer.hpp"
2#include "duckdb/parser/statement/attach_statement.hpp"
3#include "duckdb/parser/expression/constant_expression.hpp"
4#include "duckdb/common/string_util.hpp"
5
6namespace duckdb {
7
8unique_ptr<AttachStatement> Transformer::TransformAttach(duckdb_libpgquery::PGAttachStmt &stmt) {
9 auto result = make_uniq<AttachStatement>();
10 auto info = make_uniq<AttachInfo>();
11 info->name = stmt.name ? stmt.name : string();
12 info->path = stmt.path;
13
14 if (stmt.options) {
15 duckdb_libpgquery::PGListCell *cell;
16 for_each_cell(cell, stmt.options->head) {
17 auto def_elem = PGPointerCast<duckdb_libpgquery::PGDefElem>(ptr: cell->data.ptr_value);
18 Value val;
19 if (def_elem->arg) {
20 val = TransformValue(val: *PGPointerCast<duckdb_libpgquery::PGValue>(ptr: def_elem->arg))->value;
21 } else {
22 val = Value::BOOLEAN(value: true);
23 }
24 info->options[StringUtil::Lower(str: def_elem->defname)] = std::move(val);
25 }
26 }
27 result->info = std::move(info);
28 return result;
29}
30
31} // namespace duckdb
32