#include "SQLParserResult.h" #include namespace hsql { SQLParserResult::SQLParserResult() : isValid_(false), errorMsg_(NULL) {}; SQLParserResult::SQLParserResult(SQLStatement* stmt) : isValid_(false), errorMsg_(NULL) { addStatement(stmt); }; // Move constructor. SQLParserResult::SQLParserResult(SQLParserResult&& moved) { isValid_ = moved.isValid_; errorMsg_ = moved.errorMsg_; statements_ = std::move(moved.statements_); moved.errorMsg_ = NULL; moved.reset(); } SQLParserResult::~SQLParserResult() { reset(); } void SQLParserResult::addStatement(SQLStatement* stmt) { statements_.push_back(stmt); } const SQLStatement* SQLParserResult::getStatement(int index) const { return statements_[index]; } 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_; } 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& SQLParserResult::getStatements() const { return statements_; } std::vector SQLParserResult::releaseStatements() { std::vector copy = statements_; statements_.clear(); return copy; } void SQLParserResult::reset() { for (SQLStatement* statement : statements_) { delete statement; } statements_.clear(); isValid_ = false; free(errorMsg_); errorMsg_ = NULL; 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& SQLParserResult::parameters() { return parameters_; } } // namespace hsql