Repository navigation
Expand file tree
/
Copy pathCreateStatement.h
More file actions
86 lines (67 loc) · 2.58 KB
/
Copy pathCreateStatement.h
File metadata and controls
86 lines (67 loc) · 2.58 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
#ifndef SQLPARSER_CREATE_STATEMENT_H
#define SQLPARSER_CREATE_STATEMENT_H
#include "ColumnType.h"
#include "SQLStatement.h"
#include <ostream>
#include <set>
// Note: Implementations of constructors and destructors can be found in statements.cpp.
namespace hsql {
struct SelectStatement;
enum struct ConstraintType { None, NotNull, Null, PrimaryKey, Unique };
// Superclass for both TableConstraint and Column Definition
struct TableElement {
virtual ~TableElement() {}
};
// Represents definition of a table constraint
struct TableConstraint : TableElement {
TableConstraint(ConstraintType keyType, std::vector<char*>* columnNames);
~TableConstraint() override;
ConstraintType type;
std::vector<char*>* columnNames;
};
// Represents definition of a table column
struct ColumnDefinition : TableElement {
ColumnDefinition(char* name, ColumnType type, std::set<ConstraintType>* column_constraints);
~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() {
if (column_constraints->count(ConstraintType::NotNull) || column_constraints->count(ConstraintType::PrimaryKey)) {
if (column_constraints->count(ConstraintType::Null)) {
return false;
}
nullable = false;
}
return true;
}
std::set<ConstraintType>* column_constraints;
char* name;
ColumnType type;
bool nullable;
};
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