Coverage Report

Created: 2024-07-23 06:37

/src/sql-parser/src/sql/CreateStatement.cpp
Line
Count
Source
1
#include "CreateStatement.h"
2
#include "SelectStatement.h"
3
4
namespace hsql {
5
6
// CreateStatemnet
7
CreateStatement::CreateStatement(CreateType type)
8
    : SQLStatement(kStmtCreate),
9
      type(type),
10
      ifNotExists(false),
11
      filePath(nullptr),
12
      schema(nullptr),
13
      tableName(nullptr),
14
      indexName(nullptr),
15
      indexColumns(nullptr),
16
      columns(nullptr),
17
      tableConstraints(nullptr),
18
      viewColumns(nullptr),
19
3.04k
      select(nullptr) {}
20
21
3.04k
CreateStatement::~CreateStatement() {
22
3.04k
  free(filePath);
23
3.04k
  free(schema);
24
3.04k
  free(tableName);
25
3.04k
  free(indexName);
26
3.04k
  delete select;
27
28
3.04k
  if (columns) {
29
20.3k
    for (ColumnDefinition* def : *columns) {
30
20.3k
      delete def;
31
20.3k
    }
32
1.26k
    delete columns;
33
1.26k
  }
34
35
3.04k
  if (tableConstraints) {
36
10.3k
    for (TableConstraint* def : *tableConstraints) {
37
10.3k
      delete def;
38
10.3k
    }
39
1.26k
    delete tableConstraints;
40
1.26k
  }
41
42
3.04k
  if (indexColumns) {
43
1.34k
    for (char* column : *indexColumns) {
44
1.34k
      free(column);
45
1.34k
    }
46
1.15k
    delete indexColumns;
47
1.15k
  }
48
49
3.04k
  if (viewColumns) {
50
424
    for (char* column : *viewColumns) {
51
424
      free(column);
52
424
    }
53
230
    delete viewColumns;
54
230
  }
55
3.04k
}
56
57
1.26k
void CreateStatement::setColumnDefsAndConstraints(std::vector<TableElement*>* tableElements) {
58
1.26k
  columns = new std::vector<ColumnDefinition*>();
59
1.26k
  tableConstraints = new std::vector<TableConstraint*>();
60
61
30.7k
  for (auto tableElem : *tableElements) {
62
30.7k
    if (auto* colDef = dynamic_cast<ColumnDefinition*>(tableElem)) {
63
20.3k
      columns->emplace_back(colDef);
64
20.3k
    } else if (auto* tableConstraint = dynamic_cast<TableConstraint*>(tableElem)) {
65
10.3k
      tableConstraints->emplace_back(tableConstraint);
66
10.3k
    }
67
30.7k
  }
68
1.26k
}
69
70
}  // namespace hsql