Permalink
Browse files

quoting limit nodes

  • Loading branch information...
1 parent c28fe4c commit 40105685957e377c263cfdd59178d3efc3a64181 @tenderlove tenderlove committed Dec 7, 2010
@@ -25,7 +25,7 @@ def visit_Arel_Nodes_UpdateStatement o
("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
@@ -17,7 +17,7 @@ def visit_Arel_Nodes_SelectStatement o
[
"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
@@ -76,7 +76,7 @@ def visit_Arel_Nodes_SelectStatement o
[
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 ' '
@@ -17,6 +17,12 @@ module Visitors
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)
@@ -12,6 +12,14 @@ module Visitors
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
@@ -30,6 +30,12 @@ module Visitors
@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

0 comments on commit 4010568

Please sign in to comment.