Add Commit and Rollback buttons to the Query Tool. Fixes #2418

This commit is contained in:
Akshay Joshi
2019-02-22 14:28:05 +00:00
committed by Dave Page
parent 0766b17726
commit 38b034ec3c
19 changed files with 453 additions and 110 deletions

View File

@@ -81,6 +81,12 @@ class ExecuteQuery {
} else {
self.loadingScreen.hide();
self.enableSQLEditorButtons();
// Enable/Disable commit and rollback button.
if (result.data.data.transaction_status == 2 || result.data.data.transaction_status == 3) {
self.enableTransactionButtons();
} else {
self.disableTransactionButtons();
}
self.sqlServerObject.update_msg_history(false, httpMessageData.data.result);
if ('notifies' in httpMessageData.data)
self.sqlServerObject.update_notifications(httpMessageData.data.notifies);
@@ -114,6 +120,13 @@ class ExecuteQuery {
})
).then(
(httpMessage) => {
// Enable/Disable commit and rollback button.
if (httpMessage.data.data.transaction_status == 2 || httpMessage.data.data.transaction_status == 3) {
self.enableTransactionButtons();
} else {
self.disableTransactionButtons();
}
if (ExecuteQuery.isQueryFinished(httpMessage)) {
self.loadingScreen.setMessage('Loading data from the database server and rendering...');
@@ -184,6 +197,7 @@ class ExecuteQuery {
this.sqlServerObject.rows_affected = 0;
this.sqlServerObject._init_polling_flags();
this.disableSQLEditorButtons();
this.disableTransactionButtons();
}
static prepareAnalyzeSql(sqlStatement, analyzeSql) {
@@ -247,6 +261,15 @@ class ExecuteQuery {
this.sqlServerObject.disable_tool_buttons(true);
}
enableTransactionButtons() {
this.sqlServerObject.disable_transaction_buttons(false);
}
disableTransactionButtons() {
this.sqlServerObject.special_sql = undefined;
this.sqlServerObject.disable_transaction_buttons(true);
}
static wasConnectionLostToPythonServer(httpResponse) {
return _.isUndefined(httpResponse) || _.isUndefined(httpResponse.data);
}

View File

@@ -141,6 +141,18 @@ let queryToolActions = {
codeMirrorObj.replaceSelection(selectedText.toUpperCase());
}
},
executeCommit: function (sqlEditorController) {
var self = this;
sqlEditorController.special_sql = 'COMMIT;';
self.executeQuery(sqlEditorController);
},
executeRollback: function (sqlEditorController) {
var self = this;
sqlEditorController.special_sql = 'ROLLBACK;';
self.executeQuery(sqlEditorController);
},
};
module.exports = queryToolActions;

View File

@@ -97,6 +97,14 @@ function updateUIPreferences(sqlEditor) {
.attr('title',
shortcut_title('Download as CSV',preferences.download_csv));
$el.find('#btn-commit')
.attr('title',
shortcut_title('Commit',preferences.commit_transaction));
$el.find('#btn-rollback')
.attr('title',
shortcut_title('Rollback',preferences.rollback_transaction));
/* Set Auto-commit and auto-rollback on query editor */
if (preferences.auto_commit) {
$el.find('.auto-commit').removeClass('visibility-hidden');