2016-02-22 05:21:15 +08:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include "database/db.hpp"
|
2016-08-11 11:47:30 +08:00
|
|
|
#include "query_engine/exceptions/exceptions.hpp"
|
2016-07-18 01:32:35 +08:00
|
|
|
#include "query_engine/util.hpp"
|
2016-06-06 17:29:52 +08:00
|
|
|
#include "query_program.hpp"
|
2016-02-22 05:21:15 +08:00
|
|
|
|
|
|
|
// preparations before execution
|
|
|
|
// execution
|
|
|
|
// postprocess the results
|
|
|
|
|
2016-08-29 08:01:42 +08:00
|
|
|
// BARRIER!
|
2016-08-30 12:34:08 +08:00
|
|
|
#ifdef BARRIER
|
2016-08-29 08:01:42 +08:00
|
|
|
namespace barrier
|
|
|
|
{
|
2016-08-30 12:34:08 +08:00
|
|
|
Db &trans(::Db &ref);
|
2016-08-29 08:01:42 +08:00
|
|
|
}
|
2016-08-30 12:34:08 +08:00
|
|
|
#endif
|
2016-08-29 08:01:42 +08:00
|
|
|
|
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 {
|
|
|
|
// TODO: return result of query/code exection
|
2016-08-30 12:34:08 +08:00
|
|
|
#ifdef BARRIER
|
|
|
|
return program.code->run(barrier::trans(db),
|
|
|
|
program.stripped.arguments, stream);
|
|
|
|
#else
|
2016-08-11 11:47:30 +08:00
|
|
|
return program.code->run(db, program.stripped.arguments, stream);
|
2016-08-30 12:34:08 +08:00
|
|
|
#endif
|
2016-07-18 01:32:35 +08:00
|
|
|
} catch (...) {
|
|
|
|
// TODO: return more information about the error
|
|
|
|
throw QueryEngineException("code execution error");
|
|
|
|
}
|
2016-02-22 05:21:15 +08:00
|
|
|
}
|
|
|
|
};
|