mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
Modify the Download as CSV option to use the same connection as the Query Tool its running in so temporary tables etc. can be used. Fixes #3673
This commit is contained in:
committed by
Dave Page
parent
292ac32db5
commit
34045efb38
@@ -19,6 +19,7 @@ Bug fixes
|
|||||||
*********
|
*********
|
||||||
|
|
||||||
| `Bug #3544 <https://redmine.postgresql.org/issues/3544>`_ - Make the Query Tool tab titles more concise and useful.
|
| `Bug #3544 <https://redmine.postgresql.org/issues/3544>`_ - Make the Query Tool tab titles more concise and useful.
|
||||||
|
| `Bug #3673 <https://redmine.postgresql.org/issues/3673>`_ - Modify the Download as CSV option to use the same connection as the Query Tool its running in so temporary tables etc. can be used.
|
||||||
| `Bug #3873 <https://redmine.postgresql.org/issues/3873>`_ - Fix context sub-menu alignment on Safari.
|
| `Bug #3873 <https://redmine.postgresql.org/issues/3873>`_ - Fix context sub-menu alignment on Safari.
|
||||||
| `Bug #3906 <https://redmine.postgresql.org/issues/3906>`_ - Fix alignment of Close and Maximize button of Grant Wizard.
|
| `Bug #3906 <https://redmine.postgresql.org/issues/3906>`_ - Fix alignment of Close and Maximize button of Grant Wizard.
|
||||||
| `Bug #3912 <https://redmine.postgresql.org/issues/3912>`_ - Fix editing of table data with a JSON primary key.
|
| `Bug #3912 <https://redmine.postgresql.org/issues/3912>`_ - Fix editing of table data with a JSON primary key.
|
||||||
|
@@ -342,7 +342,6 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<iframe id="download-csv" style="display:none"></iframe>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
@@ -1393,29 +1393,16 @@ def save_file():
|
|||||||
@login_required
|
@login_required
|
||||||
def start_query_download_tool(trans_id):
|
def start_query_download_tool(trans_id):
|
||||||
sync_conn = None
|
sync_conn = None
|
||||||
(status, error_msg, conn, trans_obj,
|
(status, error_msg, sync_conn, trans_obj,
|
||||||
session_obj) = check_transaction_status(trans_id)
|
session_obj) = check_transaction_status(trans_id)
|
||||||
|
|
||||||
if status and conn is not None and \
|
if status and sync_conn is not None and \
|
||||||
trans_obj is not None and session_obj is not None:
|
trans_obj is not None and session_obj is not None:
|
||||||
|
|
||||||
data = request.args if request.args else None
|
data = request.args if request.args else None
|
||||||
try:
|
try:
|
||||||
if data and 'query' in data:
|
if data and 'query' in data:
|
||||||
sql = data['query']
|
sql = data['query']
|
||||||
conn_id = str(random.randint(1, 9999999))
|
|
||||||
sync_conn = conn.manager.connection(
|
|
||||||
did=trans_obj.did,
|
|
||||||
conn_id=conn_id,
|
|
||||||
auto_reconnect=False,
|
|
||||||
async_=False
|
|
||||||
)
|
|
||||||
|
|
||||||
sync_conn.connect(autocommit=False)
|
|
||||||
|
|
||||||
def cleanup():
|
|
||||||
conn.manager.connections[sync_conn.conn_id]._release()
|
|
||||||
del conn.manager.connections[sync_conn.conn_id]
|
|
||||||
|
|
||||||
# This returns generator of records.
|
# This returns generator of records.
|
||||||
status, gen = sync_conn.execute_on_server_as_csv(
|
status, gen = sync_conn.execute_on_server_as_csv(
|
||||||
@@ -1427,7 +1414,6 @@ def start_query_download_tool(trans_id):
|
|||||||
r.headers[
|
r.headers[
|
||||||
"Content-Disposition"
|
"Content-Disposition"
|
||||||
] = "attachment;filename=error.csv"
|
] = "attachment;filename=error.csv"
|
||||||
r.call_on_close(cleanup)
|
|
||||||
return r
|
return r
|
||||||
|
|
||||||
r = Response(
|
r = Response(
|
||||||
@@ -1459,13 +1445,11 @@ def start_query_download_tool(trans_id):
|
|||||||
"Content-Disposition"
|
"Content-Disposition"
|
||||||
] = "attachment;filename={0}".format(filename)
|
] = "attachment;filename={0}".format(filename)
|
||||||
|
|
||||||
r.call_on_close(cleanup)
|
|
||||||
return r
|
return r
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
r = Response('"{0}"'.format(e), mimetype='text/csv')
|
r = Response('"{0}"'.format(e), mimetype='text/csv')
|
||||||
r.headers["Content-Disposition"] = "attachment;filename=error.csv"
|
r.headers["Content-Disposition"] = "attachment;filename=error.csv"
|
||||||
r.call_on_close(cleanup)
|
|
||||||
return r
|
return r
|
||||||
else:
|
else:
|
||||||
return internal_server_error(
|
return internal_server_error(
|
||||||
|
@@ -307,12 +307,12 @@ define('tools.querytool', [
|
|||||||
geometry_viewer.load(main_docker);
|
geometry_viewer.load(main_docker);
|
||||||
|
|
||||||
// Add all the panels to the docker
|
// Add all the panels to the docker
|
||||||
self.data_output_panel = main_docker.addPanel('data_output', wcDocker.DOCK.BOTTOM, sql_panel_obj);
|
self.scratch_panel = main_docker.addPanel('scratch', wcDocker.DOCK.RIGHT, sql_panel_obj);
|
||||||
|
self.history_panel = main_docker.addPanel('history', wcDocker.DOCK.STACKED, sql_panel_obj);
|
||||||
|
self.data_output_panel = main_docker.addPanel('data_output', wcDocker.DOCK.BOTTOM);
|
||||||
self.explain_panel = main_docker.addPanel('explain', wcDocker.DOCK.STACKED, self.data_output_panel);
|
self.explain_panel = main_docker.addPanel('explain', wcDocker.DOCK.STACKED, self.data_output_panel);
|
||||||
self.messages_panel = main_docker.addPanel('messages', wcDocker.DOCK.STACKED, self.data_output_panel);
|
self.messages_panel = main_docker.addPanel('messages', wcDocker.DOCK.STACKED, self.data_output_panel);
|
||||||
self.notifications_panel = main_docker.addPanel('notifications', wcDocker.DOCK.STACKED, self.data_output_panel);
|
self.notifications_panel = main_docker.addPanel('notifications', wcDocker.DOCK.STACKED, self.data_output_panel);
|
||||||
self.history_panel = main_docker.addPanel('history', wcDocker.DOCK.STACKED, sql_panel_obj);
|
|
||||||
self.scratch_panel = main_docker.addPanel('scratch', wcDocker.DOCK.RIGHT, sql_panel_obj);
|
|
||||||
|
|
||||||
self.render_history_grid();
|
self.render_history_grid();
|
||||||
queryToolNotifications.renderNotificationsGrid(self.notifications_panel);
|
queryToolNotifications.renderNotificationsGrid(self.notifications_panel);
|
||||||
@@ -3502,6 +3502,12 @@ define('tools.querytool', [
|
|||||||
}
|
}
|
||||||
self.disable_tool_buttons(false);
|
self.disable_tool_buttons(false);
|
||||||
is_query_running = false;
|
is_query_running = false;
|
||||||
|
if(!_.isUndefined(self.download_csv_obj)) {
|
||||||
|
self.download_csv_obj.abort();
|
||||||
|
$('#btn-flash').prop('disabled', false);
|
||||||
|
self.trigger(
|
||||||
|
'pgadmin-sqleditor:loading-icon:hide');
|
||||||
|
}
|
||||||
setTimeout(() => { self.gridView.query_tool_obj.focus(); }, 200);
|
setTimeout(() => { self.gridView.query_tool_obj.focus(); }, 200);
|
||||||
})
|
})
|
||||||
.fail(function(e) {
|
.fail(function(e) {
|
||||||
@@ -3517,7 +3523,6 @@ define('tools.querytool', [
|
|||||||
// Trigger query result download to csv.
|
// Trigger query result download to csv.
|
||||||
trigger_csv_download: function(query, filename) {
|
trigger_csv_download: function(query, filename) {
|
||||||
var self = this,
|
var self = this,
|
||||||
link = $(this.container).find('#download-csv'),
|
|
||||||
url = url_for('sqleditor.query_tool_download', {
|
url = url_for('sqleditor.query_tool_download', {
|
||||||
'trans_id': self.transId,
|
'trans_id': self.transId,
|
||||||
});
|
});
|
||||||
@@ -3526,7 +3531,57 @@ define('tools.querytool', [
|
|||||||
query: query,
|
query: query,
|
||||||
filename: filename,
|
filename: filename,
|
||||||
});
|
});
|
||||||
link.attr('src', url);
|
|
||||||
|
// Get the CSV file
|
||||||
|
self.download_csv_obj = $.ajax({
|
||||||
|
type: 'GET',
|
||||||
|
url: url,
|
||||||
|
cache: false,
|
||||||
|
async: true,
|
||||||
|
xhrFields: {
|
||||||
|
responseType: 'blob',
|
||||||
|
},
|
||||||
|
beforeSend: function() {
|
||||||
|
// Disable the Execute button
|
||||||
|
$('#btn-flash').prop('disabled', true);
|
||||||
|
self.disable_tool_buttons(true);
|
||||||
|
|
||||||
|
self.trigger(
|
||||||
|
'pgadmin-sqleditor:loading-icon:show',
|
||||||
|
gettext('Downloading CSV...')
|
||||||
|
);
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.done(function(response) {
|
||||||
|
let urlCreator = window.URL || window.webkitURL,
|
||||||
|
url = urlCreator.createObjectURL(response),
|
||||||
|
link = document.createElement('a');
|
||||||
|
|
||||||
|
link.setAttribute('href', url);
|
||||||
|
link.setAttribute('download', filename);
|
||||||
|
link.click();
|
||||||
|
|
||||||
|
self.download_csv_obj = undefined;
|
||||||
|
// Enable the execute button
|
||||||
|
$('#btn-flash').prop('disabled', false);
|
||||||
|
self.disable_tool_buttons(false);
|
||||||
|
self.trigger(
|
||||||
|
'pgadmin-sqleditor:loading-icon:hide');
|
||||||
|
|
||||||
|
})
|
||||||
|
.fail(function(err) {
|
||||||
|
let msg = '';
|
||||||
|
|
||||||
|
if (err.statusText == 'abort') {
|
||||||
|
msg = gettext('CSV Download cancelled.');
|
||||||
|
} else {
|
||||||
|
msg = httpErrorHandler.handleQueryToolAjaxError(
|
||||||
|
pgAdmin, self, err, gettext('Download CSV'), [], true
|
||||||
|
);
|
||||||
|
}
|
||||||
|
alertify.alert(gettext('Download CSV error'), msg);
|
||||||
|
});
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
call_cache_preferences: function() {
|
call_cache_preferences: function() {
|
||||||
|
@@ -673,7 +673,7 @@ WHERE
|
|||||||
Returns:
|
Returns:
|
||||||
Generator response
|
Generator response
|
||||||
"""
|
"""
|
||||||
status, cur = self.__cursor(server_cursor=True)
|
status, cur = self.__cursor()
|
||||||
self.row_count = 0
|
self.row_count = 0
|
||||||
|
|
||||||
if not status:
|
if not status:
|
||||||
|
Reference in New Issue
Block a user