1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

quoting limit nodes

This commit is contained in:
Aaron Patterson 2010-12-06 20:26:08 -08:00
parent c28fe4cbbb
commit 4018b5d66a
6 changed files with 23 additions and 3 deletions

View file

@ -25,7 +25,7 @@ module Arel
("SET #{o.values.map { |value| visit value }.join ', '}" unless o.values.empty?),
("WHERE #{o.wheres.map { |x| visit x }.join ' AND '}" unless o.wheres.empty?),
("ORDER BY #{o.orders.map { |x| visit x }.join(', ')}" unless o.orders.empty?),
("LIMIT #{o.limit}" if o.limit),
("LIMIT #{visit o.limit}" if o.limit),
].compact.join ' '
end

View file

@ -17,7 +17,7 @@ module Arel
[
"SELECT * FROM (#{sql}) AS id_list",
"ORDER BY #{aliased_orders(o.orders).join(', ')}",
("LIMIT #{o.limit}" if o.limit),
("LIMIT #{visit o.limit}" if o.limit),
(visit(o.offset) if o.offset),
].compact.join ' '
else

View file

@ -76,7 +76,7 @@ module Arel
[
o.cores.map { |x| visit_Arel_Nodes_SelectCore x }.join,
("ORDER BY #{o.orders.map { |x| visit x }.join(', ')}" unless o.orders.empty?),
("LIMIT #{o.limit}" if o.limit),
("LIMIT #{visit o.limit}" if o.limit),
(visit(o.offset) if o.offset),
(visit(o.lock) if o.lock),
].compact.join ' '

View file

@ -17,6 +17,12 @@ module Arel
sql.must_be_like "SELECT FROM DUAL LIMIT 18446744073709551615 OFFSET 1"
end
it "should escape LIMIT" do
sc = Arel::Nodes::UpdateStatement.new
sc.limit = "omg"
assert_match(/LIMIT 'omg'/, @visitor.accept(sc))
end
it 'uses DUAL for empty from' do
stmt = Nodes::SelectStatement.new
sql = @visitor.accept(stmt)

View file

@ -12,6 +12,14 @@ module Arel
FOR UPDATE
}
end
it "should escape LIMIT" do
sc = Arel::Nodes::SelectStatement.new
sc.limit = "omg"
sc.cores.first.projections << 'DISTINCT ON'
sc.orders << "xyz"
assert_match(/LIMIT 'omg'/, @visitor.accept(sc))
end
end
end
end

View file

@ -30,6 +30,12 @@ module Arel
@visitor.accept(DateTime).must_equal "'DateTime'"
end
it "should escape LIMIT" do
sc = Arel::Nodes::SelectStatement.new
sc.limit = "omg"
assert_match(/LIMIT 'omg'/, @visitor.accept(sc))
end
it "should visit_DateTime" do
@visitor.accept DateTime.now
end