HyriseSQLParser/src/SQLParserResult.cpp

111 lines
2.4 KiB
C++
Raw Normal View History

2016-02-27 14:45:59 +01:00
#include "SQLParserResult.h"
#include <algorithm>
2016-02-27 14:45:59 +01:00
namespace hsql {
SQLParserResult::SQLParserResult() :
isValid_(false),
2017-06-06 03:49:41 +02:00
errorMsg_(nullptr) {};
2016-02-27 14:45:59 +01:00
SQLParserResult::SQLParserResult(SQLStatement* stmt) :
isValid_(false),
2017-06-06 03:49:41 +02:00
errorMsg_(nullptr) {
addStatement(stmt);
};
2016-02-27 14:45:59 +01:00
// Move constructor.
SQLParserResult::SQLParserResult(SQLParserResult&& moved) {
isValid_ = moved.isValid_;
errorMsg_ = moved.errorMsg_;
statements_ = std::move(moved.statements_);
2017-06-06 03:49:41 +02:00
moved.errorMsg_ = nullptr;
moved.reset();
}
SQLParserResult::~SQLParserResult() {
reset();
}
2016-02-27 14:45:59 +01:00
void SQLParserResult::addStatement(SQLStatement* stmt) {
2017-02-08 02:59:07 +01:00
statements_.push_back(stmt);
}
2016-02-27 14:45:59 +01:00
2017-02-08 02:59:07 +01:00
const SQLStatement* SQLParserResult::getStatement(int index) const {
return statements_[index];
}
2016-02-27 14:45:59 +01:00
2017-02-08 02:59:07 +01:00
SQLStatement* SQLParserResult::getMutableStatement(int 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_;
}
2016-02-27 15:01:06 +01:00
void SQLParserResult::setIsValid(bool isValid) {
isValid_ = isValid;
}
2017-02-08 04:56:07 +01:00
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_);
2017-06-06 03:49:41 +02:00
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