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 "List.h"
|
|
|
|
#include "Table.h"
|
|
|
|
|
|
|
|
namespace hsql {
|
|
|
|
|
|
|
|
|
2014-12-15 18:32:46 +01:00
|
|
|
|
2014-11-07 01:09:06 +01:00
|
|
|
/**
|
|
|
|
* @struct OrderDescription
|
2014-12-15 18:32:46 +01:00
|
|
|
* @brief Description of the order by clause within a select statement
|
|
|
|
*
|
2014-11-07 01:09:06 +01:00
|
|
|
* TODO: hold multiple expressions to be sorted by
|
|
|
|
*/
|
|
|
|
typedef enum {
|
|
|
|
kOrderAsc,
|
|
|
|
kOrderDesc
|
|
|
|
} OrderType;
|
|
|
|
|
|
|
|
struct OrderDescription {
|
2014-11-13 01:27:47 +01:00
|
|
|
OrderDescription(OrderType type, Expr* expr) :
|
|
|
|
type(type),
|
|
|
|
expr(expr) {}
|
|
|
|
|
2014-12-15 18:32:46 +01:00
|
|
|
virtual ~OrderDescription() {
|
|
|
|
delete expr;
|
|
|
|
}
|
2014-11-07 15:21:54 +01:00
|
|
|
|
2014-11-07 01:09:06 +01:00
|
|
|
OrderType type;
|
|
|
|
Expr* expr;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @struct LimitDescription
|
2014-12-15 18:32:46 +01:00
|
|
|
* @brief Description of the limit clause within a select statement
|
2014-11-07 01:09:06 +01:00
|
|
|
*/
|
|
|
|
const int64_t kNoLimit = -1;
|
|
|
|
const int64_t kNoOffset = -1;
|
|
|
|
struct LimitDescription {
|
2014-11-13 01:27:47 +01:00
|
|
|
LimitDescription(int64_t limit, int64_t offset) :
|
|
|
|
limit(limit),
|
|
|
|
offset(offset) {}
|
|
|
|
|
2014-11-07 01:09:06 +01:00
|
|
|
int64_t limit;
|
|
|
|
int64_t offset;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @struct SelectStatement
|
2014-12-15 18:32:46 +01:00
|
|
|
* @brief Representation of a full select statement.
|
|
|
|
*
|
2014-11-13 17:54:24 +01:00
|
|
|
* TODO: add union_order and union_limit
|
2014-11-07 01:09:06 +01:00
|
|
|
*/
|
2014-12-03 17:43:02 +01:00
|
|
|
struct SelectStatement : SQLStatement {
|
2014-11-13 01:27:47 +01:00
|
|
|
SelectStatement() :
|
2014-12-03 17:43:02 +01:00
|
|
|
SQLStatement(kStmtSelect),
|
2014-11-13 01:27:47 +01:00
|
|
|
from_table(NULL),
|
|
|
|
select_list(NULL),
|
|
|
|
where_clause(NULL),
|
|
|
|
group_by(NULL),
|
2014-11-13 02:40:43 +01:00
|
|
|
union_select(NULL),
|
2014-11-13 01:27:47 +01:00
|
|
|
order(NULL),
|
2014-11-13 02:40:43 +01:00
|
|
|
limit(NULL) {};
|
2014-11-13 01:27:47 +01:00
|
|
|
|
2014-12-15 18:32:46 +01:00
|
|
|
virtual ~SelectStatement() {
|
|
|
|
delete from_table;
|
|
|
|
delete select_list;
|
|
|
|
delete where_clause;
|
|
|
|
delete group_by;
|
|
|
|
delete order;
|
|
|
|
delete limit;
|
|
|
|
}
|
2014-11-07 01:09:06 +01:00
|
|
|
|
|
|
|
TableRef* from_table;
|
|
|
|
List<Expr*>* select_list;
|
2014-11-13 01:27:47 +01:00
|
|
|
Expr* where_clause;
|
2014-11-07 01:09:06 +01:00
|
|
|
List<Expr*>* group_by;
|
|
|
|
|
2014-11-13 01:27:47 +01:00
|
|
|
SelectStatement* union_select;
|
2014-11-07 01:09:06 +01:00
|
|
|
OrderDescription* order;
|
|
|
|
LimitDescription* limit;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace hsql
|
|
|
|
|
|
|
|
#endif
|