Skip to content

Commit bcef5c9

Browse files
Fixed review comments
1 parent f692806 commit bcef5c9

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

web/pgadmin/tools/sqleditor/__init__.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2222,7 +2222,25 @@ def download_binary_data(trans_id):
22222222
binary_data = cur.fetchone()
22232223
binary_data = binary_data[col_pos]
22242224

2225-
return send_file(
2225+
try:
2226+
row_pos = int(data['rowpos'])
2227+
col_pos = int(data['colpos'])
2228+
if row_pos < 0 or col_pos < 0:
2229+
raise ValueError
2230+
cur.scroll(row_pos)
2231+
row = cur.fetchone()
2232+
if row is None or col_pos >= len(row):
2233+
return internal_server_error(
2234+
errormsg=gettext('Requested cell is out of range.')
2235+
)
2236+
binary_data = row[col_pos]
2237+
except (ValueError, IndexError, TypeError) as e:
2238+
current_app.logger.error(e)
2239+
return internal_server_error(
2240+
errormsg='Invalid row/column position.'
2241+
)
2242+
2243+
return send_file(
22262244
BytesIO(binary_data),
22272245
as_attachment=True,
22282246
download_name='binary_data',

web/pgadmin/tools/sqleditor/static/js/components/QueryToolDataGrid/Formatters.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export function NumberFormatter({row, column}) {
7373
}
7474
NumberFormatter.propTypes = FormatterPropTypes;
7575

76-
export function BinaryFormatter({row, column}) {
76+
export function BinaryFormatter({row, column, ...props}) {
7777
let value = row[column.key];
7878
const eventBus = useContext(QueryToolEventsContext);
7979
const downloadBinaryData = usePreferences().getPreferences('misc', 'enable_binary_data_download').value;
@@ -82,7 +82,7 @@ export function BinaryFormatter({row, column}) {
8282
<span className='Formatters-disabledCell'>[{value}]</span>&nbsp;&nbsp;
8383
{downloadBinaryData &&
8484
<PgIconButton size="xs" title={gettext('Download binary data')} icon={<GetAppRoundedIcon />}
85-
onClick={()=>eventBus.fireEvent(QUERY_TOOL_EVENTS.TRIGGER_SAVE_BINARY_DATA, row.__temp_PK, column.pos)}/>}
85+
onClick={()=>eventBus.fireEvent(QUERY_TOOL_EVENTS.TRIGGER_SAVE_BINARY_DATA, props.rowIdx, column.pos)}/>}
8686
</StyledNullAndDefaultFormatter>
8787
);
8888
}

0 commit comments

Comments
 (0)