Skip to content

Commit 908ea2c

Browse files
Fixed review comments
1 parent 4aacb38 commit 908ea2c

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

web/pgadmin/tools/sqleditor/__init__.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2221,7 +2221,6 @@ def download_binary_data(trans_id):
22212221
return internal_server_error(
22222222
errormsg=gettext('No active result cursor.')
22232223
)
2224-
register_binary_data_typecasters(cur)
22252224

22262225
data = request.values if request.values else request.get_json(silent=True)
22272226
if data is None:
@@ -2234,12 +2233,23 @@ def download_binary_data(trans_id):
22342233
)
22352234

22362235
try:
2236+
register_binary_data_typecasters(cur)
22372237
row_pos = int(data['rowpos'])
22382238
col_pos = int(data['colpos'])
22392239
if row_pos < 0 or col_pos < 0:
22402240
raise ValueError
2241-
cur.scroll(row_pos)
2242-
row = cur.fetchone()
2241+
2242+
# Save the current cursor position
2243+
saved_pos = cur.rownumber if cur.rownumber is not None else 0
2244+
2245+
try:
2246+
# Scroll to the requested row and fetch it
2247+
cur.scroll(row_pos, mode='absolute')
2248+
row = cur.fetchone()
2249+
finally:
2250+
# Always restore the cursor position
2251+
cur.scroll(saved_pos, mode='absolute')
2252+
22432253
if row is None or col_pos >= len(row):
22442254
return internal_server_error(
22452255
errormsg=gettext('Requested cell is out of range.')

web/pgadmin/utils/driver/psycopg3/typecast.py

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -258,20 +258,12 @@ def load(self, data):
258258
class ByteaDataLoader(Loader):
259259
# Loads the actual binary data.
260260
def load(self, data):
261-
if data:
262-
if isinstance(data, memoryview):
263-
data = bytes(data).decode()
264-
if data.startswith('\\x'):
265-
data = data[2:]
266-
try:
267-
return bytes.fromhex(data)
268-
except ValueError:
269-
# In case of error while converting hex to bytes, return
270-
# original data.
271-
return data
272-
else:
273-
return data
274-
return data if data is not None else None
261+
if data is None:
262+
return None
263+
raw = bytes(data) if isinstance(data, memoryview) else data
264+
if isinstance(raw, str) and raw.startswith('\\x'):
265+
return bytes.fromhex(raw[2:])
266+
return raw
275267

276268

277269
class ByteaBinaryDataLoader(Loader):

0 commit comments

Comments
 (0)