Skip to content

Commit

Permalink
Guard against paged operations usage when using emulated offsets on DB2
Browse files Browse the repository at this point in the history
The approach used does not work with emulated offsets. At least
the :limit_offset offset_strategy works.
  • Loading branch information
jeremyevans committed Sep 26, 2023
1 parent 856a918 commit d18e976
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
3 changes: 3 additions & 0 deletions lib/sequel/plugins/paged_operations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ def paged_update(values, opts=OPTS)
# and return the primary key to operate on as a Sequel::Identifier.
def _paged_operations_pk(meth)
raise Error, "cannot use #{meth} if dataset has a limit or offset" if @opts[:limit] || @opts[:offset]
if db.database_type == :db2 && db.offset_strategy == :emulate
raise Error, "the paged_operations plugin is not supported on DB2 when using emulated offsets, set the :offset_strategy Database option to 'limit_offset' or 'offset_fetch'"
end

case pk = model.primary_key
when Symbol
Expand Down
8 changes: 8 additions & 0 deletions spec/extensions/paged_operations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,14 @@
proc{@ds.limit(1).paged_datasets{}}.must_raise Sequel::Error
end

it "should raise error for DB2 with emulated offsets" do
@c.dataset = Sequel.mock('db2')[:t]
ds = @c.dataset
proc{ds.offset(1).paged_delete}.must_raise Sequel::Error
proc{ds.offset(1).paged_update(:x=>1)}.must_raise Sequel::Error
proc{ds.offset(1).paged_datasets{}}.must_raise Sequel::Error
end

it "should raise error for dataset with offset" do
proc{@ds.offset(1).paged_delete}.must_raise Sequel::Error
proc{@ds.offset(1).paged_update(:x=>1)}.must_raise Sequel::Error
Expand Down
2 changes: 1 addition & 1 deletion spec/integration/plugin_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3123,4 +3123,4 @@ def set(k, v, ttl) self[k] = v end
ds.paged_datasets{|ds| counts << ds.count}
counts.must_equal [49]
end
end
end unless DB.database_type == :db2 && DB.offset_strategy == :emulate

0 comments on commit d18e976

Please sign in to comment.