Repository navigation
Expand file tree
/
Copy pathCreateStatement.cpp
More file actions
70 lines (60 loc) · 1.56 KB
/
Copy pathCreateStatement.cpp
File metadata and controls
70 lines (60 loc) · 1.56 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
#include "CreateStatement.h"
#include "SelectStatement.h"
namespace hsql {
// CreateStatemnet
CreateStatement::CreateStatement(CreateType type)
: SQLStatement(kStmtCreate),
type(type),
ifNotExists(false),
filePath(nullptr),
schema(nullptr),
tableName(nullptr),
indexName(nullptr),
indexColumns(nullptr),
columns(nullptr),
tableConstraints(nullptr),
viewColumns(nullptr),
select(nullptr) {}
CreateStatement::~CreateStatement() {
free(filePath);
free(schema);
free(tableName);
free(indexName);
delete select;
if (columns) {
for (ColumnDefinition* def : *columns) {
delete def;
}
delete columns;
}
if (tableConstraints) {
for (TableConstraint* def : *tableConstraints) {
delete def;
}
delete tableConstraints;
}
if (indexColumns) {
for (char* column : *indexColumns) {
free(column);
}
delete indexColumns;
}
if (viewColumns) {
for (char* column : *viewColumns) {
free(column);
}
delete viewColumns;
}
}
void CreateStatement::setColumnDefsAndConstraints(std::vector<TableElement*>* tableElements) {
columns = new std::vector<ColumnDefinition*>();
tableConstraints = new std::vector<TableConstraint*>();
for (auto tableElem : *tableElements) {
if (auto* colDef = dynamic_cast<ColumnDefinition*>(tableElem)) {
columns->emplace_back(colDef);
} else if (auto* tableConstraint = dynamic_cast<TableConstraint*>(tableElem)) {
tableConstraints->emplace_back(tableConstraint);
}
}
}
} // namespace hsql