Query, explain, cancel buttons are now enabled/disabled when the state of the connection changes.
This commit is contained in:
parent
d19741f111
commit
a32e2c83ca
3 changed files with 32 additions and 14 deletions
|
|
@ -1,5 +1,6 @@
|
|||
#include "asyncdbconnection.h"
|
||||
#include "waithandlelist.h"
|
||||
#include "scopeguard.h"
|
||||
#include <chrono>
|
||||
|
||||
ASyncDBConnection::ASyncDBConnection()
|
||||
|
|
@ -7,6 +8,11 @@ ASyncDBConnection::ASyncDBConnection()
|
|||
|
||||
}
|
||||
|
||||
ASyncDBConnection::State ASyncDBConnection::state() const
|
||||
{
|
||||
return m_threadData.m_state;
|
||||
}
|
||||
|
||||
//void ASyncDBConnection::setupConnection(const std::string &connstring)
|
||||
//{
|
||||
// if (m_thread.joinable()) {
|
||||
|
|
@ -69,6 +75,10 @@ ASyncDBConnection::Thread::Thread()
|
|||
void ASyncDBConnection::Thread::run()
|
||||
{
|
||||
m_terminated = false;
|
||||
SCOPE_EXIT {
|
||||
m_state = State::NotConnected;
|
||||
m_terminated = true;
|
||||
};
|
||||
while (!terminateRequested) {
|
||||
|
||||
// make or recover connection
|
||||
|
|
@ -94,7 +104,6 @@ void ASyncDBConnection::Thread::run()
|
|||
break;
|
||||
}
|
||||
}
|
||||
m_terminated = true;
|
||||
// close connection
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ public:
|
|||
|
||||
ASyncDBConnection();
|
||||
|
||||
State state() const;
|
||||
// void setupConnection(const std::string &connstring);
|
||||
void setupConnection(const ConnectionConfig &config);
|
||||
void closeConnection();
|
||||
|
|
@ -81,6 +82,7 @@ private:
|
|||
|
||||
// std::string m_initString;
|
||||
ConnectionConfig m_config;
|
||||
State m_state = State::NotConnected;
|
||||
|
||||
Thread();
|
||||
|
||||
|
|
@ -94,7 +96,6 @@ private:
|
|||
|
||||
private:
|
||||
|
||||
State m_state = State::NotConnected;
|
||||
|
||||
Win32Event m_stopEvent;
|
||||
Pgsql::Connection m_connection;
|
||||
|
|
|
|||
|
|
@ -177,6 +177,11 @@ void MainWindow::connectionStateChanged(ASyncDBConnection::State state)
|
|||
}
|
||||
addLog(status_str);
|
||||
statusBar()->showMessage(status_str);
|
||||
|
||||
bool connected = ASyncDBConnection::State::Connected == state;
|
||||
ui->actionExecute_SQL->setEnabled(connected);
|
||||
ui->actionExplain_Analyze->setEnabled(connected);
|
||||
ui->actionCancel->setEnabled(ASyncDBConnection::State::QuerySend == state);
|
||||
}
|
||||
|
||||
void MainWindow::startConnect()
|
||||
|
|
@ -188,20 +193,23 @@ void MainWindow::startConnect()
|
|||
|
||||
void MainWindow::performQuery()
|
||||
{
|
||||
addLog("Query clicked");
|
||||
if (m_dbConnection.state() == ASyncDBConnection::State::Connected) {
|
||||
addLog("Query clicked");
|
||||
|
||||
ui->ResultView->setModel(nullptr);
|
||||
resultModel.reset();
|
||||
ui->messagesEdit->clear();
|
||||
ui->ResultView->setModel(nullptr);
|
||||
resultModel.reset();
|
||||
ui->messagesEdit->clear();
|
||||
|
||||
QString command = ui->queryEdit->toPlainText();
|
||||
std::string cmd = command.toUtf8().data();
|
||||
startTimer();
|
||||
m_dbConnection.send(cmd,
|
||||
[this](std::shared_ptr<Pgsql::Result> res)
|
||||
{
|
||||
QueueTask([this, res]() { query_ready(res); });
|
||||
});
|
||||
|
||||
QString command = ui->queryEdit->toPlainText();
|
||||
std::string cmd = command.toUtf8().data();
|
||||
startTimer();
|
||||
m_dbConnection.send(cmd,
|
||||
[this](std::shared_ptr<Pgsql::Result> res)
|
||||
{
|
||||
QueueTask([this, res]() { query_ready(res); });
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::query_ready(std::shared_ptr<Pgsql::Result> dbres)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue