Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,20 @@ void MainWindow::init()
#endif

// Set statusbar fields
statusBusyLabel = new QLabel(ui->statusbar);
statusBusyLabel->setEnabled(false);
statusBusyLabel->setVisible(false);
statusBusyLabel->setToolTip(tr("The database is currenctly busy."));
ui->statusbar->addPermanentWidget(statusBusyLabel);

statusStopButton = new QToolButton(ui->statusbar);
statusStopButton->setVisible(false);
statusStopButton->setIcon(QIcon(":icons/cancel"));
statusStopButton->setToolTip(tr("Click here to interrupt the currently running query."));
statusStopButton->setMaximumSize(ui->statusbar->geometry().height() - 6, ui->statusbar->geometry().height() - 6);
statusStopButton->setAutoRaise(true);
ui->statusbar->addPermanentWidget(statusStopButton);

statusEncryptionLabel = new QLabel(ui->statusbar);
statusEncryptionLabel->setEnabled(false);
statusEncryptionLabel->setVisible(false);
Expand Down Expand Up @@ -316,6 +330,11 @@ void MainWindow::init()
ui->editDeleteObjectAction->setToolTip(ui->editDeleteObjectAction->text());
});

// When clicking the interrupt query button in the status bar, ask SQLite to interrupt the current query
connect(statusStopButton, &QToolButton::clicked, [this]() {
db.interruptQuery();
});

// Connect some more signals and slots
connect(ui->dataTable->filterHeader(), SIGNAL(sectionClicked(int)), this, SLOT(browseTableHeaderClicked(int)));
connect(ui->dataTable->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(setRecordsetLabel()));
Expand All @@ -332,6 +351,8 @@ void MainWindow::init()
connect(ui->dataTable, &ExtendedTableWidget::selectedRowsToBeDeleted, this, &MainWindow::deleteRecord);
connect(ui->actionDropQualifiedCheck, &QAction::toggled, dbStructureModel, &DbStructureModel::setDropQualifiedNames);
connect(ui->actionEnquoteNamesCheck, &QAction::toggled, dbStructureModel, &DbStructureModel::setDropEnquotedNames);
connect(&db, &DBBrowserDB::databaseInUseChanged, this, &MainWindow::updateDatabaseBusyStatus);

ui->actionDropQualifiedCheck->setChecked(Settings::getValue("SchemaDock", "dropQualifiedNames").toBool());
ui->actionEnquoteNamesCheck->setChecked(Settings::getValue("SchemaDock", "dropEnquotedNames").toBool());

Expand Down Expand Up @@ -3541,3 +3562,10 @@ void MainWindow::printDbStructure ()
delete dialog;
delete document;
}

void MainWindow::updateDatabaseBusyStatus(bool busy, const QString& user)
{
statusBusyLabel->setText(tr("Busy (%1)").arg(user));
statusBusyLabel->setVisible(busy);
statusStopButton->setVisible(busy);
}
15 changes: 10 additions & 5 deletions src/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,21 @@
#include <QMainWindow>
#include <QMap>

class QDragEnterEvent;
class EditDialog;
class QIntValidator;
class QLabel;
class QModelIndex;
class QPersistentModelIndex;
class SqliteTableModel;
class DbStructureModel;
class RemoteDock;
class RemoteDatabase;
class FindReplaceDialog;
class ExtendedTableWidget;

class QDragEnterEvent;
class QIntValidator;
class QModelIndex;
class QLabel;
class QPersistentModelIndex;
class QToolButton;

namespace Ui {
class MainWindow;
}
Expand Down Expand Up @@ -157,6 +159,8 @@ class MainWindow : public QMainWindow
QLabel* statusEncodingLabel;
QLabel* statusEncryptionLabel;
QLabel* statusReadOnlyLabel;
QToolButton* statusStopButton;
QLabel* statusBusyLabel;

DbStructureModel* dbStructureModel;

Expand Down Expand Up @@ -301,6 +305,7 @@ private slots:
void updateInsertDeleteRecordButton();
void runSqlNewTab(const QString& query, const QString& title);
void printDbStructure();
void updateDatabaseBusyStatus(bool busy, const QString& user);
};

#endif
Binary file added src/icons/cancel.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/icons/icons.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,6 @@
<file alias="text_indent">text_indent.png</file>
<file alias="print">printer.png</file>
<file alias="project_save">package_save.png</file>
<file alias="cancel">cancel.png</file>
</qresource>
</RCC>
9 changes: 9 additions & 0 deletions src/sqlitedb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,7 @@ DBBrowserDB::db_pointer_type DBBrowserDB::get(QString user)

db_user = user;
db_used = true;
emit databaseInUseChanged(true, user);

return db_pointer_type(_db, DatabaseReleaser(this));
}
Expand Down Expand Up @@ -1871,3 +1872,11 @@ QString DBBrowserDB::generateTemporaryTableName(const QString& schema) const
return table_name;
}
}

void DBBrowserDB::interruptQuery()
{
if(!_db)
return;

sqlite3_interrupt(_db);
}
7 changes: 7 additions & 0 deletions src/sqlitedb.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class DBBrowserDB : public QObject
std::unique_lock<std::mutex> lk(pParent->m);
pParent->db_used = false;
lk.unlock();
emit pParent->databaseInUseChanged(false, QString());
pParent->cv.notify_one();
}
};
Expand Down Expand Up @@ -111,6 +112,11 @@ class DBBrowserDB : public QObject
*/
bool getRow(const sqlb::ObjectIdentifier& table, const QString& rowid, QVector<QByteArray>& rowdata);

/**
* @brief Interrupts the currenty running statement as soon as possible.
*/
void interruptQuery();

private:
/**
* @brief max Queries the table t for the max value of field.
Expand Down Expand Up @@ -202,6 +208,7 @@ class DBBrowserDB : public QObject
void dbChanged(bool dirty);
void structureUpdated();
void requestCollation(QString name, int eTextRep);
void databaseInUseChanged(bool busy, QString user);

private:
/// external code needs to go through get() to obtain access to the database
Expand Down