Explain works with parameters to now.

Also de deduplicated the callback lambda in the normal query execution.
This commit is contained in:
eelke 2017-12-12 20:15:07 +01:00
parent e9d72d391d
commit 397138eef1

View file

@ -160,19 +160,15 @@ void QueryTab::execute()
std::string cmd = getCommandUtf8();
m_stopwatch.start();
auto cb = [this](Expected<std::shared_ptr<Pgsql::Result>> res, qint64 elapsedms)
{
m_win->QueueTask([this, res, elapsedms]() { query_ready(res, elapsedms); });
};
if (m_queryParamListController->empty())
m_dbConnection.send(cmd,
[this](Expected<std::shared_ptr<Pgsql::Result>> res, qint64 elapsedms)
{
m_win->QueueTask([this, res, elapsedms]() { query_ready(res, elapsedms); });
});
m_dbConnection.send(cmd, cb);
else
m_dbConnection.send(cmd,
m_queryParamListController->params(),
[this](Expected<std::shared_ptr<Pgsql::Result>> res, qint64 elapsedms)
{
m_win->QueueTask([this, res, elapsedms]() { query_ready(res, elapsedms); });
});
m_dbConnection.send(cmd, m_queryParamListController->params(), cb);
}
}
@ -190,30 +186,35 @@ void QueryTab::explain(bool analyze)
}
m_stopwatch.start();
std::string cmd = "EXPLAIN (" + analyze_str + "VERBOSE, FORMAT JSON) " + getCommandUtf8();
m_dbConnection.send(cmd,
[this](Expected<std::shared_ptr<Pgsql::Result>> exp_res, qint64 )
{
if (exp_res.valid()) {
// Process explain data seperately
auto res = exp_res.get();
if (res) {
std::thread([this,res]()
{
std::shared_ptr<ExplainRoot> explain;
if (res->cols() == 1 && res->rows() == 1) {
std::string s = res->val(0, 0);
Json::Value root; // will contains the root value after parsing.
Json::Reader reader;
bool parsingSuccessful = reader.parse(s, root);
if (parsingSuccessful) {
explain = ExplainRoot::createFromJson(root);
}
auto cb = [this](Expected<std::shared_ptr<Pgsql::Result>> exp_res, qint64 )
{
if (exp_res.valid()) {
// Process explain data seperately
auto res = exp_res.get();
if (res) {
std::thread([this,res]()
{
std::shared_ptr<ExplainRoot> explain;
if (res->cols() == 1 && res->rows() == 1) {
std::string s = res->val(0, 0);
Json::Value root; // will contains the root value after parsing.
Json::Reader reader;
bool parsingSuccessful = reader.parse(s, root);
if (parsingSuccessful) {
explain = ExplainRoot::createFromJson(root);
}
m_win->QueueTask([this, explain]() { explain_ready(explain); });
}).detach();
}
}
m_win->QueueTask([this, explain]() { explain_ready(explain); });
}).detach();
}
});
}
};
if (m_queryParamListController->empty())
m_dbConnection.send(cmd, cb);
else
m_dbConnection.send(cmd, m_queryParamListController->params(), cb);
}
void QueryTab::cancel()