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 {
|
2017-02-08 02:06:15 +01:00
|
|
|
enum OrderType {
|
|
|
|
kOrderAsc,
|
|
|
|
kOrderDesc
|
|
|
|
};
|
2016-02-27 15:01:06 +01:00
|
|
|
|
2017-02-08 02:06:15 +01:00
|
|
|
/**
|
|
|
|
* Description of the order by clause within a select statement
|
|
|
|
* TODO: hold multiple expressions to be sorted by
|
|
|
|
*/
|
|
|
|
struct OrderDescription {
|
|
|
|
OrderDescription(OrderType type, Expr* expr);
|
|
|
|
virtual ~OrderDescription();
|
2016-02-27 15:01:06 +01:00
|
|
|
|
2017-02-08 02:06:15 +01:00
|
|
|
OrderType type;
|
|
|
|
Expr* expr;
|
|
|
|
};
|
2016-02-27 15:01:06 +01:00
|
|
|
|
2017-02-08 02:06:15 +01:00
|
|
|
const int64_t kNoLimit = -1;
|
|
|
|
const int64_t kNoOffset = -1;
|
2016-02-27 15:22:22 +01:00
|
|
|
|
2017-02-08 02:06:15 +01:00
|
|
|
/**
|
|
|
|
* Description of the limit clause within a select statement
|
|
|
|
*/
|
|
|
|
struct LimitDescription {
|
|
|
|
LimitDescription(int64_t limit, int64_t offset);
|
2016-02-27 15:01:06 +01:00
|
|
|
|
2017-02-08 02:06:15 +01:00
|
|
|
int64_t limit;
|
|
|
|
int64_t offset;
|
|
|
|
};
|
2016-02-27 15:01:06 +01:00
|
|
|
|
2017-02-08 02:06:15 +01:00
|
|
|
/**
|
|
|
|
* Description of the group-by clause within a select statement
|
|
|
|
*/
|
|
|
|
struct GroupByDescription {
|
|
|
|
GroupByDescription();
|
|
|
|
// TODO: make virtual
|
|
|
|
~GroupByDescription();
|
2016-02-27 15:01:06 +01:00
|
|
|
|
2017-02-08 02:06:15 +01:00
|
|
|
std::vector<Expr*>* columns;
|
|
|
|
Expr* having;
|
|
|
|
};
|
2016-02-27 15:01:06 +01:00
|
|
|
|
2017-02-08 02:06:15 +01:00
|
|
|
/**
|
|
|
|
* Representation of a full SQL select statement.
|
|
|
|
* TODO: add union_order and union_limit
|
|
|
|
*/
|
|
|
|
struct SelectStatement : SQLStatement {
|
|
|
|
SelectStatement();
|
|
|
|
virtual ~SelectStatement();
|
2016-02-27 15:01:06 +01:00
|
|
|
|
2017-02-08 02:06:15 +01:00
|
|
|
TableRef* fromTable;
|
|
|
|
bool selectDistinct;
|
|
|
|
std::vector<Expr*>* selectList;
|
|
|
|
Expr* whereClause;
|
|
|
|
GroupByDescription* groupBy;
|
2016-02-27 15:01:06 +01:00
|
|
|
|
2017-02-08 02:06:15 +01:00
|
|
|
SelectStatement* unionSelect;
|
|
|
|
OrderDescription* order;
|
|
|
|
LimitDescription* limit;
|
|
|
|
};
|
2014-11-07 01:09:06 +01:00
|
|
|
|
|
|
|
} // namespace hsql
|
|
|
|
#endif
|