Skip to content

Commit e39a6a6

Browse files
committed
keep working legacy pagination
1 parent 7c210ff commit e39a6a6

File tree

1 file changed

+25
-8
lines changed

1 file changed

+25
-8
lines changed

sqlalchemy_iris/base.py

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,8 @@ def visit_exists_unary_operator(
409409

410410
def limit_clause(self, select, **kw):
411411
# handle the limit and offset clauses
412+
if not self.dialect.supports_modern_pagination:
413+
return ""
412414
if select._has_row_limiting_clause and not self._use_top(select):
413415
limit_clause = self._get_limit_or_fetch(select)
414416
offset_clause = select._offset_clause
@@ -424,6 +426,11 @@ def limit_clause(self, select, **kw):
424426
else:
425427
return ""
426428

429+
def fetch_clause(self, select, **kw):
430+
if not self.dialect.supports_modern_pagination:
431+
return ""
432+
return super().fetch_clause(select, **kw)
433+
427434
def visit_empty_set_expr(self, type_, **kw):
428435
return "SELECT 1 WHERE 1!=1"
429436

@@ -493,7 +500,7 @@ def get_select_precolumns(self, select, **kw):
493500
else:
494501
text += "DISTINCT "
495502

496-
if select._has_row_limiting_clause and self._use_top(select):
503+
if not self.dialect.supports_modern_pagination and select._has_row_limiting_clause and self._use_top(select):
497504
text += "TOP %s " % self.process(self._get_limit_or_fetch(select), **kw)
498505

499506
return text
@@ -552,13 +559,10 @@ def translate_select_structure(self, select_stmt, **kwargs):
552559
if not (select._has_row_limiting_clause and not self._use_top(select)):
553560
return select
554561

555-
# check the current version of the iris server
556-
server_version = self.dialect.server_version_info
557-
558-
if server_version is None or server_version < (2025, 1):
559-
return self._handle_legacy_pagination(select, select_stmt)
560-
else:
562+
if self.dialect.supports_modern_pagination:
561563
return self._handle_modern_pagination(select, select_stmt)
564+
else:
565+
return self._handle_legacy_pagination(select, select_stmt)
562566

563567
def _get_default_order_by(self, select_stmt, select):
564568
"""Get default ORDER BY clauses when none are specified."""
@@ -625,7 +629,6 @@ def _handle_modern_pagination(self, select, select_stmt):
625629

626630
return new_select
627631

628-
629632
def order_by_clause(self, select, **kw):
630633
order_by = self.process(select._order_by_clause, **kw)
631634

@@ -884,6 +887,14 @@ def create_cursor(self):
884887
cursor = self._dbapi_connection.cursor()
885888
return cursor
886889

890+
@util.non_memoized_property
891+
def rowcount(self) -> int:
892+
print("_rowcount", self._rowcount, self.cursor._closed, self.cursor.rowcount)
893+
if self._rowcount is not None:
894+
return self._rowcount
895+
else:
896+
return self.cursor.rowcount
897+
887898

888899
colspecs = {
889900
sqltypes.Boolean: IRISBoolean,
@@ -959,6 +970,8 @@ class IRISDialect(default.DefaultDialect):
959970
update_executemany_returning = False
960971
delete_executemany_returning = False
961972

973+
supports_modern_pagination = False
974+
962975
construct_arguments = [
963976
(schema.Index, {"include": None}),
964977
]
@@ -986,6 +999,10 @@ def _get_server_version_info(self, connection):
986999
def _get_default_schema_name(self, connection):
9871000
return IRISDialect.default_schema_name
9881001

1002+
def initialize(self, connection):
1003+
super().initialize(connection)
1004+
self.supports_modern_pagination = self.server_version_info >= (2025, 1)
1005+
9891006
def on_connect(self):
9901007
super_ = super().on_connect()
9911008

0 commit comments

Comments
 (0)