From 397138eef191a8370b24ad665f094e0e446a9893 Mon Sep 17 00:00:00 2001 From: eelke Date: Tue, 12 Dec 2017 20:15:07 +0100 Subject: [PATCH] Explain works with parameters to now. Also de deduplicated the callback lambda in the normal query execution. --- pglab/QueryTab.cpp | 67 +++++++++++++++++++++++----------------------- 1 file changed, 34 insertions(+), 33 deletions(-) diff --git a/pglab/QueryTab.cpp b/pglab/QueryTab.cpp index 537c8cd..05e7d0b 100644 --- a/pglab/QueryTab.cpp +++ b/pglab/QueryTab.cpp @@ -160,19 +160,15 @@ void QueryTab::execute() std::string cmd = getCommandUtf8(); m_stopwatch.start(); + auto cb = [this](Expected> res, qint64 elapsedms) + { + m_win->QueueTask([this, res, elapsedms]() { query_ready(res, elapsedms); }); + }; + if (m_queryParamListController->empty()) - m_dbConnection.send(cmd, - [this](Expected> 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> 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> 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 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> 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 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()