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 "asyncdbconnection.h"
|
||||||
#include "waithandlelist.h"
|
#include "waithandlelist.h"
|
||||||
|
#include "scopeguard.h"
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
|
||||||
ASyncDBConnection::ASyncDBConnection()
|
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)
|
//void ASyncDBConnection::setupConnection(const std::string &connstring)
|
||||||
//{
|
//{
|
||||||
// if (m_thread.joinable()) {
|
// if (m_thread.joinable()) {
|
||||||
|
|
@ -69,6 +75,10 @@ ASyncDBConnection::Thread::Thread()
|
||||||
void ASyncDBConnection::Thread::run()
|
void ASyncDBConnection::Thread::run()
|
||||||
{
|
{
|
||||||
m_terminated = false;
|
m_terminated = false;
|
||||||
|
SCOPE_EXIT {
|
||||||
|
m_state = State::NotConnected;
|
||||||
|
m_terminated = true;
|
||||||
|
};
|
||||||
while (!terminateRequested) {
|
while (!terminateRequested) {
|
||||||
|
|
||||||
// make or recover connection
|
// make or recover connection
|
||||||
|
|
@ -94,7 +104,6 @@ void ASyncDBConnection::Thread::run()
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m_terminated = true;
|
|
||||||
// close connection
|
// close connection
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,7 @@ public:
|
||||||
|
|
||||||
ASyncDBConnection();
|
ASyncDBConnection();
|
||||||
|
|
||||||
|
State state() const;
|
||||||
// void setupConnection(const std::string &connstring);
|
// void setupConnection(const std::string &connstring);
|
||||||
void setupConnection(const ConnectionConfig &config);
|
void setupConnection(const ConnectionConfig &config);
|
||||||
void closeConnection();
|
void closeConnection();
|
||||||
|
|
@ -81,6 +82,7 @@ private:
|
||||||
|
|
||||||
// std::string m_initString;
|
// std::string m_initString;
|
||||||
ConnectionConfig m_config;
|
ConnectionConfig m_config;
|
||||||
|
State m_state = State::NotConnected;
|
||||||
|
|
||||||
Thread();
|
Thread();
|
||||||
|
|
||||||
|
|
@ -94,7 +96,6 @@ private:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
State m_state = State::NotConnected;
|
|
||||||
|
|
||||||
Win32Event m_stopEvent;
|
Win32Event m_stopEvent;
|
||||||
Pgsql::Connection m_connection;
|
Pgsql::Connection m_connection;
|
||||||
|
|
|
||||||
|
|
@ -177,6 +177,11 @@ void MainWindow::connectionStateChanged(ASyncDBConnection::State state)
|
||||||
}
|
}
|
||||||
addLog(status_str);
|
addLog(status_str);
|
||||||
statusBar()->showMessage(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()
|
void MainWindow::startConnect()
|
||||||
|
|
@ -188,12 +193,14 @@ void MainWindow::startConnect()
|
||||||
|
|
||||||
void MainWindow::performQuery()
|
void MainWindow::performQuery()
|
||||||
{
|
{
|
||||||
|
if (m_dbConnection.state() == ASyncDBConnection::State::Connected) {
|
||||||
addLog("Query clicked");
|
addLog("Query clicked");
|
||||||
|
|
||||||
ui->ResultView->setModel(nullptr);
|
ui->ResultView->setModel(nullptr);
|
||||||
resultModel.reset();
|
resultModel.reset();
|
||||||
ui->messagesEdit->clear();
|
ui->messagesEdit->clear();
|
||||||
|
|
||||||
|
|
||||||
QString command = ui->queryEdit->toPlainText();
|
QString command = ui->queryEdit->toPlainText();
|
||||||
std::string cmd = command.toUtf8().data();
|
std::string cmd = command.toUtf8().data();
|
||||||
startTimer();
|
startTimer();
|
||||||
|
|
@ -202,6 +209,7 @@ void MainWindow::performQuery()
|
||||||
{
|
{
|
||||||
QueueTask([this, res]() { query_ready(res); });
|
QueueTask([this, res]() { query_ready(res); });
|
||||||
});
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::query_ready(std::shared_ptr<Pgsql::Result> dbres)
|
void MainWindow::query_ready(std::shared_ptr<Pgsql::Result> dbres)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue