Query is now executed using std::async
This commit is contained in:
parent
3a8cc3d7f0
commit
0d30dc9080
4 changed files with 58 additions and 12 deletions
|
|
@ -5,13 +5,21 @@
|
|||
#include "sqlhighlighter.h"
|
||||
|
||||
#include <windows.h>
|
||||
//#include <thread>
|
||||
|
||||
namespace pg = Pgsql;
|
||||
|
||||
const char * test_query =
|
||||
"SELECT id, program, version, lic_bedrijf, lic_plaats, "
|
||||
"lic_number, callstack_crc_1, callstack_crc_2, callstack_crc_3, exception_class, "
|
||||
"exception_message \nFROM foutrapport";
|
||||
|
||||
//"SELECT id, program, version, lic_bedrijf, lic_plaats, "
|
||||
//"lic_number, callstack_crc_1, callstack_crc_2, callstack_crc_3, exception_class, "
|
||||
//"exception_message \nFROM foutrapport"
|
||||
|
||||
"SELECT f1.id, f1.program, f1.version, f1.lic_number, f1.callstack_crc_1, f1.callstack_crc_2, array_agg(f2.id) \n"
|
||||
"FROM foutrapport f1 JOIN foutrapport f2 USING (callstack_crc_2) \n"
|
||||
"WHERE f1.actief \n"
|
||||
"GROUP BY f1.id"
|
||||
;
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent) :
|
||||
QMainWindow(parent),
|
||||
|
|
@ -29,8 +37,6 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||
|
||||
ui->connectionStringEdit->setText("user=postgres dbname=foutrapport password=admin");
|
||||
|
||||
//performQuery();
|
||||
|
||||
QAction *action;
|
||||
action = ui->mainToolBar->addAction("connect");
|
||||
connect(action, &QAction::triggered, this, &MainWindow::startConnect);
|
||||
|
|
@ -97,9 +103,24 @@ void MainWindow::performQuery()
|
|||
ui->ResultView->setModel(nullptr);
|
||||
resultModel.reset();
|
||||
|
||||
if (connection->status() == CONNECTION_OK) {
|
||||
pg::Result dbres = connection->query(ui->queryEdit->toPlainText());
|
||||
resultModel.reset(new QueryResultModel(this , std::move(dbres)));
|
||||
QString command = ui->queryEdit->toPlainText();
|
||||
queryFuture = std::async(std::launch::async, [this,command]()-> Pgsql::Result
|
||||
{
|
||||
auto res = connection->query(command);
|
||||
QMetaObject::invokeMethod(this, "query_ready", Qt::QueuedConnection); // queues on main thread
|
||||
return res;
|
||||
});
|
||||
}
|
||||
|
||||
void MainWindow::query_ready()
|
||||
{
|
||||
pg::Result dbres(std::move(queryFuture.get()));
|
||||
if (dbres.resultStatus() == PGRES_TUPLES_OK) {
|
||||
resultModel.reset(new QueryResultModel(nullptr , std::move(dbres)));
|
||||
ui->ResultView->setModel(resultModel.get());
|
||||
}
|
||||
else {
|
||||
statusBar()->showMessage(tr("No tuples returned, possibly an error..."));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue