53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/engine2/post_bootstrap.rb', line 53
def select_sql
return super if @opts[:sql]
if o = @opts[:offset]
columns = SequelFixes.fix_aliased_expression(clone(:append_sql=>String.new, :placeholder_literal_null=>true))
dsa1 = dataset_alias(1)
rn = row_number_column
limit = @opts[:limit]
ds = unlimited.
from_self(:alias=>dsa1).
select_append(ROW_NUMBER_EXPRESSION.as(rn)).
from_self(:alias=>dsa1).
select(*columns).
where(SQL::Identifier.new(rn) > o)
ds = ds.where(SQL::Identifier.new(rn) <= Sequel.+(o, limit)) if limit
sql = @opts[:append_sql] || String.new
subselect_sql_append(sql, ds)
sql
elsif limit = @opts[:limit]
ds = clone(:limit=>nil)
ds = ds.from_self unless @opts[:lock]
sql = @opts[:append_sql] || String.new
subselect_sql_append(sql, ds.where(SQL::ComplexExpression.new(:<=, ROW_NUMBER_EXPRESSION, limit)))
sql
else
super
end
end
|