aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2010-12-06 20:26:15 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2010-12-06 20:26:15 -0800
commitee65dd6e0e5c79fa2d79944dbc541380f4b221d4 (patch)
tree9d83f4d5ec754826a7361d39b7b7d22efc0009f3
parent13d22766902af1d6f709b85a73e089b7afbb9dbf (diff)
parent4018b5d66a810a34273d4b198688896f6f7459f3 (diff)
downloadrails-ee65dd6e0e5c79fa2d79944dbc541380f4b221d4.tar.gz
rails-ee65dd6e0e5c79fa2d79944dbc541380f4b221d4.tar.bz2
rails-ee65dd6e0e5c79fa2d79944dbc541380f4b221d4.zip
Merge branch '2-0-stable'
* 2-0-stable: quoting limit nodes Make "not" apply to the whole sub-expression when generating sql.
-rw-r--r--lib/arel/visitors/mysql.rb2
-rw-r--r--lib/arel/visitors/postgresql.rb2
-rw-r--r--test/visitors/test_mysql.rb6
-rw-r--r--test/visitors/test_postgres.rb8
-rw-r--r--test/visitors/test_to_sql.rb6
5 files changed, 22 insertions, 2 deletions
diff --git a/lib/arel/visitors/mysql.rb b/lib/arel/visitors/mysql.rb
index 143b4d36f4..ace8fb0979 100644
--- a/lib/arel/visitors/mysql.rb
+++ b/lib/arel/visitors/mysql.rb
@@ -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
diff --git a/lib/arel/visitors/postgresql.rb b/lib/arel/visitors/postgresql.rb
index 553ee91bf9..01fbda75b9 100644
--- a/lib/arel/visitors/postgresql.rb
+++ b/lib/arel/visitors/postgresql.rb
@@ -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
diff --git a/test/visitors/test_mysql.rb b/test/visitors/test_mysql.rb
index 8606dc39d4..135348580d 100644
--- a/test/visitors/test_mysql.rb
+++ b/test/visitors/test_mysql.rb
@@ -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)
diff --git a/test/visitors/test_postgres.rb b/test/visitors/test_postgres.rb
index 618745c35d..b98f78ca12 100644
--- a/test/visitors/test_postgres.rb
+++ b/test/visitors/test_postgres.rb
@@ -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
diff --git a/test/visitors/test_to_sql.rb b/test/visitors/test_to_sql.rb
index bae291d87c..09f037f75f 100644
--- a/test/visitors/test_to_sql.rb
+++ b/test/visitors/test_to_sql.rb
@@ -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