Class | Sequel::JDBC::AS400::Dataset |
In: |
lib/sequel/adapters/jdbc/as400.rb
|
Parent: | JDBC::Dataset |
WILDCARD | = | Sequel::LiteralString.new('*').freeze |
FETCH_FIRST_ROW_ONLY | = | " FETCH FIRST ROW ONLY".freeze |
FETCH_FIRST | = | " FETCH FIRST ".freeze |
ROWS_ONLY | = | " ROWS ONLY".freeze |
Modify the sql to limit the number of rows returned
# File lib/sequel/adapters/jdbc/as400.rb, line 65 65: def select_limit_sql(sql) 66: if l = @opts[:limit] 67: if l == 1 68: sql << FETCH_FIRST_ROW_ONLY 69: elsif l > 1 70: sql << FETCH_FIRST 71: literal_append(sql, l) 72: sql << ROWS_ONLY 73: end 74: end 75: end
AS400 needs to use a couple of subselects for queries with offsets.
# File lib/sequel/adapters/jdbc/as400.rb, line 47 47: def select_sql 48: return super unless o = @opts[:offset] 49: l = @opts[:limit] 50: order = @opts[:order] 51: dsa1 = dataset_alias(1) 52: dsa2 = dataset_alias(2) 53: rn = row_number_column 54: irn = Sequel::SQL::Identifier.new(rn).qualify(dsa2) 55: subselect_sql(unlimited. 56: from_self(:alias=>dsa1). 57: select_more(Sequel::SQL::QualifiedIdentifier.new(dsa1, WILDCARD), 58: Sequel::SQL::WindowFunction.new(SQL::Function.new(:ROW_NUMBER), Sequel::SQL::Window.new(:order=>order)).as(rn)). 59: from_self(:alias=>dsa2). 60: select(Sequel::SQL::QualifiedIdentifier.new(dsa2, WILDCARD)). 61: where(l ? ((irn > o) & (irn <= l + o)) : (irn > o))) # Leave off limit in case of limit(nil, offset) 62: end