Skip to content

Commit d61e1da

Browse files
committed
Fix pagination issues in the query tool data output when using a server-side cursor.
1 parent 6fdb82d commit d61e1da

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

web/pgadmin/tools/sqleditor/__init__.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,7 +1080,10 @@ def poll(trans_id):
10801080
rows_affected = conn.rows_affected()
10811081

10821082
st, result = \
1083-
conn.async_fetchmany_2darray(data_result_rows_per_page)
1083+
conn.async_fetchmany_2darray(data_result_rows_per_page +1
1084+
if trans_obj.server_cursor
1085+
else data_result_rows_per_page
1086+
)
10841087

10851088
# There may be additional messages even if result is present
10861089
# eg: Function can provide result as well as RAISE messages
@@ -1200,13 +1203,24 @@ def poll(trans_id):
12001203
data_obj['db_id'] = trans_obj.did \
12011204
if trans_obj is not None and hasattr(trans_obj, 'did') else 0
12021205

1206+
12031207
page_size = rows_fetched_to - rows_fetched_from + 1
1208+
1209+
# Check the next recordset/page is available or not for the server cursor
1210+
next_page = 0
1211+
if (trans_obj.server_cursor and len(result) > 0 and len(result)
1212+
> data_result_rows_per_page):
1213+
result = result[0:len(result) - 1]
1214+
next_page = 1
1215+
rows_fetched_to = rows_fetched_to - 1
1216+
12041217
pagination = {
12051218
'page_size': page_size,
12061219
'page_count': math.ceil(conn.total_rows / page_size),
12071220
'page_no': math.floor((rows_fetched_from - 1) / page_size) + 1,
12081221
'rows_from': rows_fetched_from,
1209-
'rows_to': rows_fetched_to
1222+
'rows_to': rows_fetched_to,
1223+
'next_page': next_page
12101224
}
12111225

12121226
return make_json_response(
@@ -1275,7 +1289,7 @@ def fetch_window(trans_id, from_rownum=0, to_rownum=0):
12751289

12761290
page_size = to_rownum - from_rownum + 1
12771291

1278-
# Check whether the next recordset/page is available or not
1292+
# Check the next recordset/page is available or not for the server cursor
12791293
next_page = 0
12801294
if trans_obj.server_cursor and len(result) > 0 and len(result) > page_size:
12811295
result = result[0:len(result) - 1]

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ class DictCursor(_cursor):
132132
identifies duplicate column name
133133
"""
134134

135-
def __init__(self, *args, **kwargs):
135+
def __init__(self, *args):
136136
self._odt_desc = None
137137
_cursor.__init__(self, *args, row_factory=dict_row)
138138

@@ -401,8 +401,8 @@ class AsyncDictServerCursor(AsyncDictCursor, _async_server_cursor):
401401

402402
def __init__(self, *args, name=None, **kwargs):
403403
self._odt_desc = None
404-
_async_server_cursor.__init__(self, name=name, *args,
405-
row_factory=dict_row)
404+
kwargs['row_factory'] = dict_row
405+
_async_server_cursor.__init__(self, name=name, *args, **kwargs)
406406
self.cursor = _async_server_cursor
407407

408408
def get_rowcount(self):

0 commit comments

Comments
 (0)