Repository navigation
Expand file tree
/
Copy pathSQLParserResult.cpp
More file actions
118 lines (90 loc) · 2.54 KB
/
Copy pathSQLParserResult.cpp
File metadata and controls
118 lines (90 loc) · 2.54 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#include "SQLParserResult.h"
#include <algorithm>
namespace hsql {
SQLParserResult::SQLParserResult() :
isValid_(false),
errorMsg_(nullptr) {};
SQLParserResult::SQLParserResult(SQLStatement* stmt) :
isValid_(false),
errorMsg_(nullptr) {
addStatement(stmt);
};
// Move constructor.
SQLParserResult::SQLParserResult(SQLParserResult&& moved) {
*this = std::forward<SQLParserResult>(moved);
}
SQLParserResult &SQLParserResult::operator=(SQLParserResult&& moved)
{
isValid_ = moved.isValid_;
errorMsg_ = moved.errorMsg_;
statements_ = std::move(moved.statements_);
moved.errorMsg_ = nullptr;
moved.reset();
return *this;
}
SQLParserResult::~SQLParserResult() {
reset();
}
void SQLParserResult::addStatement(SQLStatement* stmt) {
statements_.push_back(stmt);
}
const SQLStatement* SQLParserResult::getStatement(size_t index) const {
return statements_[index];
}
SQLStatement* SQLParserResult::getMutableStatement(size_t index) {
return statements_[index];
}
size_t SQLParserResult::size() const {
return statements_.size();
}
bool SQLParserResult::isValid() const {
return isValid_;
}
const char* SQLParserResult::errorMsg() const {
return errorMsg_;
}
int SQLParserResult::errorLine() const {
return errorLine_;
}
int SQLParserResult::errorColumn() const {
return errorColumn_;
}
void SQLParserResult::setIsValid(bool isValid) {
isValid_ = isValid;
}
void SQLParserResult::setErrorDetails(char* errorMsg, int errorLine, int errorColumn) {
errorMsg_ = errorMsg;
errorLine_ = errorLine;
errorColumn_ = errorColumn;
}
const std::vector<SQLStatement*>& SQLParserResult::getStatements() const {
return statements_;
}
std::vector<SQLStatement*> SQLParserResult::releaseStatements() {
std::vector<SQLStatement*> copy = statements_;
statements_.clear();
return copy;
}
void SQLParserResult::reset() {
for (SQLStatement* statement : statements_) {
delete statement;
}
statements_.clear();
isValid_ = false;
free(errorMsg_);
errorMsg_ = nullptr;
errorLine_ = -1;
errorColumn_ = -1;
}
// Does NOT take ownership.
void SQLParserResult::addParameter(Expr* parameter) {
parameters_.push_back(parameter);
std::sort(parameters_.begin(), parameters_.end(),
[](const Expr * a, const Expr * b) {
return a->ival < b->ival;
});
}
const std::vector<Expr*>& SQLParserResult::parameters() {
return parameters_;
}
} // namespace hsql