2017-04-06 18:27:47 +02:00
|
|
|
#ifndef __SQLPARSER__SQLPARSER_RESULT_H__
|
|
|
|
#define __SQLPARSER__SQLPARSER_RESULT_H__
|
2016-02-27 14:24:23 +01:00
|
|
|
|
|
|
|
#include "sql/SQLStatement.h"
|
|
|
|
|
|
|
|
namespace hsql {
|
2017-02-08 02:33:42 +01:00
|
|
|
// Represents the result of the SQLParser.
|
|
|
|
// If parsing was successful it contains a list of SQLStatement.
|
2017-02-08 02:06:15 +01:00
|
|
|
class SQLParserResult {
|
|
|
|
public:
|
2017-02-08 02:33:42 +01:00
|
|
|
// Initialize with empty statement list.
|
2017-02-08 02:06:15 +01:00
|
|
|
SQLParserResult();
|
2017-02-08 02:33:42 +01:00
|
|
|
|
|
|
|
// Initialize with a single statement.
|
2017-02-08 02:59:07 +01:00
|
|
|
// Takes ownership of the statement.
|
2017-02-08 02:06:15 +01:00
|
|
|
SQLParserResult(SQLStatement* stmt);
|
2017-02-08 02:33:42 +01:00
|
|
|
|
2017-04-21 16:15:07 +02:00
|
|
|
// Move constructor.
|
|
|
|
SQLParserResult(SQLParserResult&& moved);
|
|
|
|
|
2017-04-06 17:42:46 +02:00
|
|
|
// Deletes all statements in the result.
|
2017-02-08 02:06:15 +01:00
|
|
|
virtual ~SQLParserResult();
|
2016-02-27 15:01:06 +01:00
|
|
|
|
2017-04-08 02:37:30 +02:00
|
|
|
// Set whether parsing was successful.
|
|
|
|
void setIsValid(bool isValid);
|
|
|
|
|
2017-02-08 02:59:07 +01:00
|
|
|
// Returns true if parsing was successful.
|
|
|
|
bool isValid() const;
|
|
|
|
|
2017-02-08 02:33:42 +01:00
|
|
|
// Returns the number of statements in the result.
|
2017-02-08 02:59:07 +01:00
|
|
|
size_t size() const;
|
|
|
|
|
2017-04-08 02:37:30 +02:00
|
|
|
// Set the details of the error, if available.
|
|
|
|
// Takes ownership of errorMsg.
|
|
|
|
void setErrorDetails(char* errorMsg, int errorLine, int errorColumn);
|
|
|
|
|
2017-02-08 02:59:07 +01:00
|
|
|
// Returns the error message, if an error occurred.
|
|
|
|
const char* errorMsg() const;
|
|
|
|
|
|
|
|
// Returns the line number of the occurrance of the error in the query.
|
|
|
|
int errorLine() const;
|
|
|
|
|
|
|
|
// Returns the column number of the occurrance of the error in the query.
|
|
|
|
int errorColumn() const;
|
2016-02-27 15:01:06 +01:00
|
|
|
|
2017-04-08 02:37:30 +02:00
|
|
|
// Adds a statement to the result list of statements.
|
|
|
|
// SQLParserResult takes ownership of the statement.
|
|
|
|
void addStatement(SQLStatement* stmt);
|
|
|
|
|
2017-02-08 02:33:42 +01:00
|
|
|
// Gets the SQL statement with the given index.
|
2017-02-08 02:59:07 +01:00
|
|
|
const SQLStatement* getStatement(int index) const;
|
|
|
|
|
|
|
|
// Gets the non const SQL statement with the given index.
|
|
|
|
SQLStatement* getMutableStatement(int index);
|
2016-02-27 15:01:06 +01:00
|
|
|
|
2017-04-08 02:37:30 +02:00
|
|
|
// Get the list of all statements.
|
|
|
|
const std::vector<SQLStatement*>& getStatements() const;
|
2017-02-08 03:07:51 +01:00
|
|
|
|
2017-04-08 02:37:30 +02:00
|
|
|
// Returns a copy of the list of all statements in this result.
|
|
|
|
// Removes them from this result.
|
|
|
|
std::vector<SQLStatement*> releaseStatements();
|
2017-02-08 03:07:51 +01:00
|
|
|
|
2017-04-08 02:37:30 +02:00
|
|
|
// Deletes all statements and other data within the result.
|
|
|
|
void reset();
|
2017-02-08 03:07:51 +01:00
|
|
|
|
2017-05-29 16:22:13 +02:00
|
|
|
// Does NOT take ownership.
|
|
|
|
void addParameter(Expr* parameter);
|
|
|
|
|
|
|
|
const std::vector<Expr*>& parameters();
|
|
|
|
|
2017-02-08 02:59:07 +01:00
|
|
|
private:
|
2017-02-08 02:33:42 +01:00
|
|
|
// List of statements within the result.
|
2017-02-08 02:59:07 +01:00
|
|
|
std::vector<SQLStatement*> statements_;
|
2017-02-08 02:33:42 +01:00
|
|
|
|
|
|
|
// Flag indicating the parsing was successful.
|
2017-02-08 02:59:07 +01:00
|
|
|
bool isValid_;
|
2016-02-27 15:01:06 +01:00
|
|
|
|
2017-02-08 02:33:42 +01:00
|
|
|
// Error message, if an error occurred.
|
2017-02-08 04:56:07 +01:00
|
|
|
char* errorMsg_;
|
2017-02-08 02:33:42 +01:00
|
|
|
|
|
|
|
// Line number of the occurrance of the error in the query.
|
2017-02-08 02:59:07 +01:00
|
|
|
int errorLine_;
|
2017-02-08 02:33:42 +01:00
|
|
|
|
|
|
|
// Column number of the occurrance of the error in the query.
|
2017-02-08 02:59:07 +01:00
|
|
|
int errorColumn_;
|
2017-05-29 16:22:13 +02:00
|
|
|
|
|
|
|
// Does NOT have ownership.
|
|
|
|
std::vector<Expr*> parameters_;
|
2017-02-08 02:06:15 +01:00
|
|
|
};
|
2016-02-27 14:24:23 +01:00
|
|
|
|
2016-02-27 14:45:59 +01:00
|
|
|
} // namespace hsql
|
2016-02-27 14:24:23 +01:00
|
|
|
|
2017-04-06 18:27:47 +02:00
|
|
|
#endif // __SQLPARSER__SQLPARSER_RESULT_H__
|