mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
generate correct select if only offset is present (in Oracle)
This commit is contained in:
parent
c66f025a8e
commit
ec6ac6654e
2 changed files with 30 additions and 0 deletions
|
@ -40,6 +40,20 @@ module Arel
|
||||||
return "SELECT * FROM (#{super(o)}) WHERE ROWNUM <= #{limit}"
|
return "SELECT * FROM (#{super(o)}) WHERE ROWNUM <= #{limit}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if o.offset
|
||||||
|
o = o.dup
|
||||||
|
offset = o.offset
|
||||||
|
o.offset = nil
|
||||||
|
sql = super(o)
|
||||||
|
return <<-eosql
|
||||||
|
SELECT * FROM (
|
||||||
|
SELECT raw_sql_.*, rownum raw_rnum_
|
||||||
|
FROM (#{sql}) raw_sql_
|
||||||
|
)
|
||||||
|
WHERE #{visit offset}
|
||||||
|
eosql
|
||||||
|
end
|
||||||
|
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -105,6 +105,22 @@ module Arel
|
||||||
sql.must_equal sql2
|
sql.must_equal sql2
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe 'only offset' do
|
||||||
|
it 'creates a select from subquery with rownum condition' do
|
||||||
|
stmt = Nodes::SelectStatement.new
|
||||||
|
stmt.offset = Nodes::Offset.new(10)
|
||||||
|
sql = @visitor.accept stmt
|
||||||
|
sql.must_be_like %{
|
||||||
|
SELECT * FROM (
|
||||||
|
SELECT raw_sql_.*, rownum raw_rnum_
|
||||||
|
FROM (SELECT ) raw_sql_
|
||||||
|
)
|
||||||
|
WHERE raw_rnum_ > 10
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue