Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

quoting limit nodes

  • Loading branch information...
commit 40105685957e377c263cfdd59178d3efc3a64181 1 parent c28fe4c
@tenderlove tenderlove authored
View
2  lib/arel/visitors/mysql.rb
@@ -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
View
2  lib/arel/visitors/postgresql.rb
@@ -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
View
2  lib/arel/visitors/to_sql.rb
@@ -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 ' '
View
6 test/visitors/test_mysql.rb
@@ -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)
View
8 test/visitors/test_postgres.rb
@@ -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
View
6 test/visitors/test_to_sql.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.