2016-02-22 05:21:15 +08:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include "database/db.hpp"
|
2016-11-02 23:05:02 +08:00
|
|
|
#include "query/exception/query_engine.hpp"
|
|
|
|
#include "query/exception/plan_execution.hpp"
|
|
|
|
#include "query/plan/program.hpp"
|
|
|
|
#include "query/util.hpp"
|
2016-02-22 05:21:15 +08:00
|
|
|
|
|
|
|
// preparations before execution
|
|
|
|
// execution
|
|
|
|
// postprocess the results
|
|
|
|
|
2016-08-29 01:50:54 +08:00
|
|
|
template <typename Stream>
|
2016-02-22 05:21:15 +08:00
|
|
|
class ProgramExecutor
|
|
|
|
{
|
|
|
|
public:
|
2016-08-29 01:50:54 +08:00
|
|
|
// QueryProgram has to know about the Stream
|
|
|
|
// Stream has to be passed in this function for every execution
|
2016-08-30 12:34:08 +08:00
|
|
|
auto execute(QueryProgram<Stream> &program, Db &db, Stream &stream)
|
2016-02-22 05:21:15 +08:00
|
|
|
{
|
2016-07-18 01:32:35 +08:00
|
|
|
try {
|
2016-11-02 23:05:02 +08:00
|
|
|
return program.plan->run(db, program.stripped.arguments, stream);
|
|
|
|
// TODO: catch more exceptions
|
2016-07-18 01:32:35 +08:00
|
|
|
} catch (...) {
|
2016-11-02 23:05:02 +08:00
|
|
|
throw PlanExecutionException("");
|
2016-07-18 01:32:35 +08:00
|
|
|
}
|
2016-02-22 05:21:15 +08:00
|
|
|
}
|
|
|
|
};
|