Skip to content

Commit e1ead7e

Browse files
Some more review fix
1 parent f692806 commit e1ead7e

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

web/pgadmin/tools/sqleditor/__init__.py

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2200,14 +2200,24 @@ def download_binary_data(trans_id):
22002200
(status, error_msg, conn, trans_obj,
22012201
session_obj) = check_transaction_status(trans_id)
22022202

2203-
cur = conn._Connection__async_cursor
2204-
register_binary_data_typecasters(cur)
2203+
if error_msg:
2204+
return internal_server_error(
2205+
errormsg=error_msg
2206+
)
2207+
22052208
if not status or conn is None or trans_obj is None or \
22062209
session_obj is None:
22072210
return internal_server_error(
22082211
errormsg=TRANSACTION_STATUS_CHECK_FAILED
22092212
)
22102213

2214+
cur = conn._Connection__async_cursor
2215+
if cur is None:
2216+
return internal_server_error(
2217+
errormsg=gettext('No active result cursor.')
2218+
)
2219+
register_binary_data_typecasters(cur)
2220+
22112221
data = request.values if request.values else request.get_json(silent=True)
22122222
if data is None:
22132223
return make_json_response(
@@ -2222,7 +2232,25 @@ def download_binary_data(trans_id):
22222232
binary_data = cur.fetchone()
22232233
binary_data = binary_data[col_pos]
22242234

2225-
return send_file(
2235+
try:
2236+
row_pos = int(data['rowpos'])
2237+
col_pos = int(data['colpos'])
2238+
if row_pos < 0 or col_pos < 0:
2239+
raise ValueError
2240+
cur.scroll(row_pos)
2241+
row = cur.fetchone()
2242+
if row is None or col_pos >= len(row):
2243+
return internal_server_error(
2244+
errormsg=gettext('Requested cell is out of range.')
2245+
)
2246+
binary_data = row[col_pos]
2247+
except (ValueError, IndexError, TypeError) as e:
2248+
current_app.logger.error(e)
2249+
return internal_server_error(
2250+
errormsg='Invalid row/column position.'
2251+
)
2252+
2253+
return send_file(
22262254
BytesIO(binary_data),
22272255
as_attachment=True,
22282256
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)