Repository navigation
Expand file tree
/
Copy pathCreateStatement.h
More file actions
103 lines (80 loc) · 3.23 KB
/
Copy pathCreateStatement.h
File metadata and controls
103 lines (80 loc) · 3.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#ifndef SQLPARSER_CREATE_STATEMENT_H
#define SQLPARSER_CREATE_STATEMENT_H
#include "ColumnType.h"
#include "SQLStatement.h"
#include <ostream>
#include <unordered_set>
namespace hsql {
struct SelectStatement;
enum struct ConstraintType { ForeignKey, NotNull, Null, PrimaryKey, Unique };
std::ostream& operator<<(std::ostream& os, const ConstraintType constraint_type);
// Superclass for both TableConstraint and ColumnDefinition.
struct TableElement {
virtual ~TableElement() = default;
};
// Represents definition of a table constraint.
struct TableConstraint : TableElement {
TableConstraint(ConstraintType keyType, std::vector<char*>* columnNames);
~TableConstraint() override;
ConstraintType type;
std::vector<char*>* columnNames;
};
// Table and columns referenced by foreign key constraint on table or column level.
struct ReferencesSpecification {
ReferencesSpecification(char* schema, char* table, std::vector<char*>* columns);
~ReferencesSpecification();
char* schema;
char* table;
std::vector<char*>* columns;
};
// Foreign key constraint on table level (when specified as table element).
struct ForeignKeyConstraint : TableConstraint {
ForeignKeyConstraint(std::vector<char*>* columnNames, ReferencesSpecification* references);
~ForeignKeyConstraint() override;
ReferencesSpecification* references;
};
// Represents definition of a table column
struct ColumnDefinition : TableElement {
ColumnDefinition(char* name, ColumnType type, std::unordered_set<ConstraintType>* column_constraints,
std::vector<ReferencesSpecification*>* references);
~ColumnDefinition() override;
// By default, columns are nullable. However, we track if a column is explicitly requested to be nullable to
// notice conflicts with PRIMARY KEY table constraints.
bool trySetNullableExplicit();
std::unordered_set<ConstraintType>* column_constraints;
char* name;
ColumnType type;
bool nullable;
std::vector<ReferencesSpecification*>* references;
};
struct ColumnConstraints {
explicit ColumnConstraints();
std::unordered_set<ConstraintType>* constraints;
std::vector<ReferencesSpecification*>* references;
};
enum CreateType {
kCreateTable,
kCreateTableFromTbl, // Hyrise file format
kCreateView,
kCreateIndex
};
// Represents SQL Create statements.
// Example: "CREATE TABLE students (name TEXT, student_number INTEGER, city TEXT, grade DOUBLE)"
struct CreateStatement : SQLStatement {
CreateStatement(CreateType type);
~CreateStatement() override;
void setColumnDefsAndConstraints(std::vector<TableElement*>* tableElements);
CreateType type;
bool ifNotExists; // default: false
char* filePath; // default: nullptr
char* schema; // default: nullptr
char* tableName; // default: nullptr
char* indexName; // default: nullptr
std::vector<char*>* indexColumns; // default: nullptr
std::vector<ColumnDefinition*>* columns; // default: nullptr
std::vector<TableConstraint*>* tableConstraints; // default: nullptr
std::vector<char*>* viewColumns;
SelectStatement* select;
};
} // namespace hsql
#endif