2014-11-07 01:09:06 +01:00
|
|
|
#ifndef __SELECT_STATEMENT_H__
|
|
|
|
#define __SELECT_STATEMENT_H__
|
|
|
|
|
2014-12-03 17:43:02 +01:00
|
|
|
#include "SQLStatement.h"
|
2014-11-07 01:09:06 +01:00
|
|
|
#include "Expr.h"
|
|
|
|
#include "Table.h"
|
|
|
|
|
|
|
|
namespace hsql {
|
2016-02-27 15:01:06 +01:00
|
|
|
typedef enum {
|
|
|
|
kOrderAsc,
|
|
|
|
kOrderDesc
|
|
|
|
} OrderType;
|
|
|
|
|
2016-02-27 15:22:22 +01:00
|
|
|
/**
|
|
|
|
* Description of the order by clause within a select statement
|
|
|
|
* TODO: hold multiple expressions to be sorted by
|
|
|
|
*/
|
2016-02-27 15:01:06 +01:00
|
|
|
struct OrderDescription {
|
|
|
|
OrderDescription(OrderType type, Expr* expr) :
|
|
|
|
type(type),
|
|
|
|
expr(expr) {}
|
|
|
|
|
|
|
|
virtual ~OrderDescription() {
|
|
|
|
delete expr;
|
|
|
|
}
|
|
|
|
|
|
|
|
OrderType type;
|
|
|
|
Expr* expr;
|
|
|
|
};
|
|
|
|
|
|
|
|
const int64_t kNoLimit = -1;
|
|
|
|
const int64_t kNoOffset = -1;
|
2016-02-27 15:22:22 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Description of the limit clause within a select statement
|
|
|
|
*/
|
2016-02-27 15:01:06 +01:00
|
|
|
struct LimitDescription {
|
|
|
|
LimitDescription(int64_t limit, int64_t offset) :
|
|
|
|
limit(limit),
|
|
|
|
offset(offset) {}
|
|
|
|
|
|
|
|
int64_t limit;
|
|
|
|
int64_t offset;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2016-02-27 15:22:22 +01:00
|
|
|
* Description of the group-by clause within a select statement
|
2016-02-27 15:01:06 +01:00
|
|
|
*/
|
|
|
|
struct GroupByDescription {
|
|
|
|
GroupByDescription() :
|
|
|
|
columns(NULL),
|
|
|
|
having(NULL) {}
|
|
|
|
|
|
|
|
~GroupByDescription() {
|
|
|
|
delete columns;
|
|
|
|
delete having;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<Expr*>* columns;
|
|
|
|
Expr* having;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2016-02-27 15:22:22 +01:00
|
|
|
* Representation of a full SQL select statement.
|
2016-02-27 15:01:06 +01:00
|
|
|
* TODO: add union_order and union_limit
|
|
|
|
*/
|
|
|
|
struct SelectStatement : SQLStatement {
|
|
|
|
SelectStatement() :
|
|
|
|
SQLStatement(kStmtSelect),
|
2016-02-27 15:22:22 +01:00
|
|
|
fromTable(NULL),
|
|
|
|
selectDistinct(false),
|
|
|
|
selectList(NULL),
|
|
|
|
whereClause(NULL),
|
|
|
|
groupBy(NULL),
|
|
|
|
unionSelect(NULL),
|
2016-02-27 15:01:06 +01:00
|
|
|
order(NULL),
|
|
|
|
limit(NULL) {};
|
|
|
|
|
|
|
|
virtual ~SelectStatement() {
|
2016-02-27 15:22:22 +01:00
|
|
|
delete fromTable;
|
|
|
|
delete selectList;
|
|
|
|
delete whereClause;
|
|
|
|
delete groupBy;
|
2016-02-27 15:01:06 +01:00
|
|
|
delete order;
|
|
|
|
delete limit;
|
|
|
|
}
|
|
|
|
|
2016-02-27 15:22:22 +01:00
|
|
|
TableRef* fromTable;
|
|
|
|
bool selectDistinct;
|
|
|
|
std::vector<Expr*>* selectList;
|
|
|
|
Expr* whereClause;
|
|
|
|
GroupByDescription* groupBy;
|
2016-02-27 15:01:06 +01:00
|
|
|
|
2016-02-27 15:22:22 +01:00
|
|
|
SelectStatement* unionSelect;
|
2016-02-27 15:01:06 +01:00
|
|
|
OrderDescription* order;
|
|
|
|
LimitDescription* limit;
|
|
|
|
};
|
2014-11-07 01:09:06 +01:00
|
|
|
|
|
|
|
} // namespace hsql
|
|
|
|
#endif
|