Skip to content

Commit 3f42091

Browse files
committed
some more fixes for limit offset
1 parent 7d7d80c commit 3f42091

File tree

3 files changed

+29
-16
lines changed

3 files changed

+29
-16
lines changed

sqlalchemy_iris/base.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -411,20 +411,19 @@ def limit_clause(self, select, **kw):
411411
# handle the limit and offset clauses
412412
if not self.dialect.supports_modern_pagination:
413413
return ""
414+
sql = ""
414415
if select._has_row_limiting_clause and not self._use_top(select):
415416
limit_clause = self._get_limit_or_fetch(select)
416417
offset_clause = select._offset_clause
417418

418419
if limit_clause is not None:
419-
if offset_clause is not None:
420-
return " LIMIT %s OFFSET %s" % (
421-
self.process(limit_clause, **kw),
422-
self.process(offset_clause, **kw),
423-
)
424-
else:
425-
return " LIMIT %s" % self.process(limit_clause, **kw)
426-
else:
427-
return ""
420+
sql += " LIMIT %s" % self.process(limit_clause, **kw)
421+
elif offset_clause is not None and self.dialect.server_version_info < (2025, 2):
422+
# IRIS 2025.1 has a bug with offset without limit
423+
sql += " LIMIT 100"
424+
if offset_clause is not None:
425+
sql += " OFFSET %s" % self.process(offset_clause, **kw)
426+
return sql
428427

429428
def fetch_clause(self, select, **kw):
430429
if not self.dialect.supports_modern_pagination:
@@ -506,6 +505,8 @@ def get_select_precolumns(self, select, **kw):
506505
return text
507506

508507
def _use_top(self, select):
508+
if self.dialect.supports_modern_pagination:
509+
return False
509510
return (select._offset_clause is None) and (
510511
select._simple_int_clause(select._limit_clause)
511512
or select._simple_int_clause(select._fetch_clause)
@@ -631,11 +632,11 @@ def _handle_modern_pagination(self, select, select_stmt):
631632

632633
def order_by_clause(self, select, **kw):
633634
order_by = self.process(select._order_by_clause, **kw)
635+
limit_clause = self._get_limit_or_fetch(select)
634636

635-
if order_by and (not self.is_subquery() or select._limit):
637+
if order_by and not self.is_subquery() and limit_clause is None and select._offset_clause is None:
636638
return " ORDER BY " + order_by
637-
else:
638-
return ""
639+
return ""
639640

640641
def visit_concat_op_binary(self, binary, operator, **kw):
641642
return "STRING(%s, %s)" % (

sqlalchemy_iris/provision.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
1-
from sqlalchemy.testing.provision import temp_table_keyword_args
1+
from sqlalchemy.testing.provision import temp_table_keyword_args, create_db, drop_db
22

33

44
@temp_table_keyword_args.for_db("iris")
55
def _iris_temp_table_keyword_args(cfg, eng):
66
return {"prefixes": ["GLOBAL TEMPORARY"]}
7+
8+
9+
@create_db.for_db("iris")
10+
def _iris_create_db(cfg, eng, ident):
11+
with eng.connect().execution_options(isolation_level="AUTOCOMMIT") as conn:
12+
conn.exec_driver_sql("create database %s" % ident)
13+
14+
15+
@drop_db.for_db("iris")
16+
def _iris_drop_db(cfg, eng, ident):
17+
with eng.connect().execution_options(isolation_level="AUTOCOMMIT") as conn:
18+
conn.exec_driver_sql("drop database %s" % ident)

sqlalchemy_iris/requirements.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -432,8 +432,8 @@ def sql_expression_limit_offset(self):
432432
SQL expression, such as one that uses the addition operator.
433433
parameter
434434
"""
435-
436-
return exclusions.open()
435+
# IRIS does not support expressions in LIMIT/OFFSET
436+
return exclusions.closed()
437437

438438
@property
439439
def parens_in_union_contained_select_w_limit_offset(self):
@@ -1454,7 +1454,7 @@ def fetch_expression(self):
14541454
SELECT * FROM some_table
14551455
OFFSET 1 + 1 ROWS FETCH FIRST 1 + 1 ROWS ONLY
14561456
"""
1457-
return exclusions.open()
1457+
return exclusions.closed()
14581458

14591459
@property
14601460
def autoincrement_without_sequence(self):

0 commit comments

Comments
 (0)