00001
#ifndef SQL_SELECT_H
00002
#define SQL_SELECT_H
00003
00004
#include "Expression.h"
00005
#include "TupleDescription.h"
00006
#include "SQLUtil.h"
00007
00008
BOREALIS_NAMESPACE_BEGIN
00009
00010
00011 class SQLSelect
00012 {
00013
public:
00014 typedef pair<string, ptr<Expression> >
SelectEntry;
00015
00018 SQLSelect(string table,
00019
const vector<SelectEntry>& select_list,
00020 ptr<SQLWhereClause> where_clause) :
00021 _table_name(table),
00022 _select_star(select_list.empty()),
00023 _select_list(select_list),
00024 _where_clause(where_clause)
00025 {
00026 vector<SelectEntry>::const_iterator i;
00027
for (i = _select_list.begin(); i != _select_list.end(); ++i)
00028 _select_expressions.push_back(i->second);
00029 }
00030
00031 ~SQLSelect() {}
00032
00033
00034
00035
void setup(
const ExprContext& ctxt)
throw (
AuroraException);
00036
00037 string
getTableName()
const {
return _table_name; }
00038
00039 TupleDescription
getResultTupleDescription()
const {
00040
return _result_schema;
00041 }
00042
00044 ptr<SQLWhereClause>
getWhereClause() {
00045
return _where_clause;
00046 }
00047
00049 void evalInto(
char *buf,
const EvalContext& ctxt)
throw (EvalException) {
00050
if (_select_star)
00051
00052
memcpy(buf, ctxt.getTuple(1), _result_schema.getSizeInBytes());
00053
else
00054
Expression::evalVectorInto(_select_expressions, buf, ctxt);
00055 }
00056
00057 const string
as_string()
const {
00058 string selection;
00059
if (_select_star)
00060 selection =
"*";
00061
else
00062 selection =
to_string(_select_list);
00063
00064
return "SQLSelect(" + selection +
" from " + _table_name +
00065
" where " + _where_clause +
")";
00066 }
00067
00068
public:
00069
static ptr<SQLSelect>
parse(string expr,
const ExprContext& ctxt,
00070 string table_name)
00071
throw (ExprException);
00072
00073
private:
00074 string _table_name;
00075
bool _select_star;
00076 vector<SelectEntry> _select_list;
00077 vector<ptr<Expression> > _select_expressions;
00078 ptr<SQLWhereClause> _where_clause;
00079
00080 TupleDescription _result_schema;
00081 };
00082
00083
BOREALIS_NAMESPACE_END
00084
00085
#endif // SQL_SELECT_H