1 | #include "duckdb/parser/parsed_data/create_table_info.hpp" |
2 | #include "duckdb/catalog/catalog_entry/schema_catalog_entry.hpp" |
3 | #include "duckdb/catalog/catalog_entry/table_catalog_entry.hpp" |
4 | #include "duckdb/catalog/catalog.hpp" |
5 | |
6 | namespace duckdb { |
7 | |
8 | CreateTableInfo::CreateTableInfo() : CreateInfo(CatalogType::TABLE_ENTRY, INVALID_SCHEMA) { |
9 | } |
10 | |
11 | CreateTableInfo::CreateTableInfo(string catalog_p, string schema_p, string name_p) |
12 | : CreateInfo(CatalogType::TABLE_ENTRY, std::move(schema_p), std::move(catalog_p)), table(std::move(name_p)) { |
13 | } |
14 | |
15 | CreateTableInfo::CreateTableInfo(SchemaCatalogEntry &schema, string name_p) |
16 | : CreateTableInfo(schema.catalog.GetName(), schema.name, std::move(name_p)) { |
17 | } |
18 | |
19 | void CreateTableInfo::SerializeInternal(Serializer &serializer) const { |
20 | FieldWriter writer(serializer); |
21 | writer.WriteString(val: table); |
22 | columns.Serialize(writer); |
23 | writer.WriteSerializableList(elements: constraints); |
24 | writer.WriteOptional(element: query); |
25 | writer.Finalize(); |
26 | } |
27 | |
28 | unique_ptr<CreateTableInfo> CreateTableInfo::Deserialize(Deserializer &deserializer) { |
29 | auto result = make_uniq<CreateTableInfo>(); |
30 | result->DeserializeBase(deserializer); |
31 | |
32 | FieldReader reader(deserializer); |
33 | result->table = reader.ReadRequired<string>(); |
34 | result->columns = ColumnList::Deserialize(reader); |
35 | result->constraints = reader.ReadRequiredSerializableList<Constraint>(); |
36 | result->query = reader.ReadOptional<SelectStatement>(default_value: nullptr); |
37 | reader.Finalize(); |
38 | |
39 | return result; |
40 | } |
41 | |
42 | unique_ptr<CreateInfo> CreateTableInfo::Copy() const { |
43 | auto result = make_uniq<CreateTableInfo>(args: catalog, args: schema, args: table); |
44 | CopyProperties(other&: *result); |
45 | result->columns = columns.Copy(); |
46 | for (auto &constraint : constraints) { |
47 | result->constraints.push_back(x: constraint->Copy()); |
48 | } |
49 | if (query) { |
50 | result->query = unique_ptr_cast<SQLStatement, SelectStatement>(src: query->Copy()); |
51 | } |
52 | return std::move(result); |
53 | } |
54 | |
55 | } // namespace duckdb |
56 | |