mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
Add support for editing of resultsets in the Query Tool, if the data can be identified as updatable. Fixes #1760
When a query is run in the Query Tool, check if the source of the columns can be identified as being from a single table, and that we have all columns that make up the primary key. If so, consider the resultset to be editable and allow the user to edit data and add/remove rows in the grid. Changes to data are saved using SAVEPOINTs as part of any transaction that's in progress, and rolled back if there are integrity violations, without otherwise affecting the ongoing transaction. Implemented by Yosry Muhammad as a Google Summer of Code project.
This commit is contained in:
committed by
Dave Page
parent
beb06a4c76
commit
710d520631
@@ -37,7 +37,8 @@ export function callRenderAfterPoll(sqlEditor, alertify, res) {
|
||||
const msg = sprintf(
|
||||
gettext('Query returned successfully in %s.'), sqlEditor.total_time);
|
||||
res.result += '\n\n' + msg;
|
||||
sqlEditor.update_msg_history(true, res.result, false);
|
||||
sqlEditor.update_msg_history(true, res.result, true);
|
||||
sqlEditor.reset_data_store();
|
||||
if (isNotificationEnabled(sqlEditor)) {
|
||||
alertify.success(msg, sqlEditor.info_notifier_timeout);
|
||||
}
|
||||
|
||||
@@ -70,6 +70,8 @@ class ExecuteQuery {
|
||||
let httpMessageData = result.data;
|
||||
self.removeGridViewMarker();
|
||||
|
||||
self.updateSqlEditorLastTransactionStatus(httpMessageData.data.transaction_status);
|
||||
|
||||
if (ExecuteQuery.isSqlCorrect(httpMessageData)) {
|
||||
self.loadingScreen.setMessage('Waiting for the query to complete...');
|
||||
|
||||
@@ -118,6 +120,8 @@ class ExecuteQuery {
|
||||
})
|
||||
).then(
|
||||
(httpMessage) => {
|
||||
self.updateSqlEditorLastTransactionStatus(httpMessage.data.data.transaction_status);
|
||||
|
||||
// Enable/Disable commit and rollback button.
|
||||
if (httpMessage.data.data.transaction_status == 2 || httpMessage.data.data.transaction_status == 3) {
|
||||
self.enableTransactionButtons();
|
||||
@@ -126,6 +130,10 @@ class ExecuteQuery {
|
||||
}
|
||||
|
||||
if (ExecuteQuery.isQueryFinished(httpMessage)) {
|
||||
if (this.sqlServerObject.close_on_idle_transaction &&
|
||||
httpMessage.data.data.transaction_status == 0)
|
||||
this.sqlServerObject.check_needed_confirmations_before_closing_panel();
|
||||
|
||||
self.loadingScreen.setMessage('Loading data from the database server and rendering...');
|
||||
|
||||
self.sqlServerObject.call_render_after_poll(httpMessage.data.data);
|
||||
@@ -296,6 +304,10 @@ class ExecuteQuery {
|
||||
this.sqlServerObject.info_notifier_timeout = messageData.info_notifier_timeout;
|
||||
}
|
||||
|
||||
updateSqlEditorLastTransactionStatus(transactionStatus) {
|
||||
this.sqlServerObject.last_transaction_status = transactionStatus;
|
||||
}
|
||||
|
||||
static isSqlCorrect(httpMessageData) {
|
||||
return httpMessageData.data.status;
|
||||
}
|
||||
|
||||
@@ -156,6 +156,11 @@ let queryToolActions = {
|
||||
sqlEditorController.special_sql = 'ROLLBACK;';
|
||||
self.executeQuery(sqlEditorController);
|
||||
},
|
||||
|
||||
saveDataChanges: function (sqlEditorController) {
|
||||
sqlEditorController.close_on_save = false;
|
||||
sqlEditorController.save_data();
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = queryToolActions;
|
||||
|
||||
@@ -29,7 +29,7 @@ function updateUIPreferences(sqlEditor) {
|
||||
.attr('title', shortcut_accesskey_title('Open File',preferences.btn_open_file))
|
||||
.attr('accesskey', shortcut_key(preferences.btn_open_file));
|
||||
|
||||
$el.find('#btn-save')
|
||||
$el.find('#btn-save-file')
|
||||
.attr('title', shortcut_accesskey_title('Save File',preferences.btn_save_file))
|
||||
.attr('accesskey', shortcut_key(preferences.btn_save_file));
|
||||
|
||||
@@ -97,6 +97,10 @@ function updateUIPreferences(sqlEditor) {
|
||||
.attr('title',
|
||||
shortcut_title('Download as CSV',preferences.download_csv));
|
||||
|
||||
$el.find('#btn-save-data')
|
||||
.attr('title',
|
||||
shortcut_title('Save Data Changes',preferences.save_data));
|
||||
|
||||
$el.find('#btn-commit')
|
||||
.attr('title',
|
||||
shortcut_title('Commit',preferences.commit_transaction));
|
||||
|
||||
Reference in New Issue
Block a user