Skip to content

Commit 4aacb38

Browse files
Fixed review comments.
1 parent a524eaa commit 4aacb38

3 files changed

Lines changed: 15 additions & 14 deletions

File tree

web/pgadmin/tools/sqleditor/__init__.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
convert_connection_parameter, get_db_disp_restriction
7474
from pgadmin.misc.workspaces import check_and_delete_adhoc_server
7575
from pgadmin.utils.driver.psycopg3.typecast import \
76-
register_binary_data_typecasters
76+
register_binary_data_typecasters, register_binary_typecasters
7777

7878
MODULE_NAME = 'sqleditor'
7979
TRANSACTION_STATUS_CHECK_FAILED = gettext("Transaction status check failed.")
@@ -2229,13 +2229,9 @@ def download_binary_data(trans_id):
22292229
status=410,
22302230
success=0,
22312231
errormsg=gettext(
2232-
"Could not find the required parameter (query)."
2232+
"Could not find the required parameters (rowpos, colpos)."
22332233
)
22342234
)
2235-
col_pos = data['colpos']
2236-
cur.scroll(int(data['rowpos']))
2237-
binary_data = cur.fetchone()
2238-
binary_data = binary_data[col_pos]
22392235

22402236
try:
22412237
row_pos = int(data['rowpos'])
@@ -2254,6 +2250,15 @@ def download_binary_data(trans_id):
22542250
return internal_server_error(
22552251
errormsg='Invalid row/column position.'
22562252
)
2253+
finally:
2254+
# Always restore the original typecasters
2255+
# (works on connection or cursor)
2256+
register_binary_typecasters(cur)
2257+
2258+
if binary_data is None:
2259+
return bad_request(
2260+
errormsg=gettext('The selected cell contains NULL.')
2261+
)
22572262

22582263
return send_file(
22592264
BytesIO(binary_data),

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

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

77-
export function BinaryFormatter({row, column}) {
77+
export function BinaryFormatter({row, column, ...props}) {
7878
let value = row[column.key];
7979
const eventBus = useContext(QueryToolEventsContext);
8080
const dataGridExtras = useContext(DataGridExtrasContext);
8181
const downloadBinaryData = usePreferences().getPreferences('misc', 'enable_binary_data_download').value;
8282

83-
// Use clientPK as the absolute row position
84-
// rowKeyGetter returns the clientPK value which is a sequential counter (0, 1, 2, ...)
85-
// that persists across pagination and represents the 0-based absolute position in the result set
86-
const absoluteRowPos = parseInt(dataGridExtras?.rowKeyGetter?.(row) ?? 0);
87-
console.log(absoluteRowPos)
83+
const absoluteRowPos = (dataGridExtras?.startRowNum ?? 1) - 1 + props.rowIdx;
8884

8985
return (
9086
<StyledNullAndDefaultFormatter value={value} column={column}>

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,8 +429,8 @@ export default function QueryToolDataGrid({columns, rows, totalRowCount, dataCha
429429
}, []);
430430

431431
const dataGridExtras = useMemo(()=>({
432-
onSelectedCellChange, handleShortcuts, startRowNum, rowKeyGetter: props.rowKeyGetter
433-
}), [onSelectedCellChange, props.rowKeyGetter]);
432+
onSelectedCellChange, handleShortcuts, startRowNum
433+
}), [onSelectedCellChange]);
434434

435435
// Save column width to window object on resize
436436
const handleColumnResize = (column, width) => {

0 commit comments

Comments
 (0)