aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/arel/visitors/mysql.rb2
-rw-r--r--lib/arel/visitors/postgresql.rb2
-rw-r--r--test/visitors/test_mysql.rb4
-rw-r--r--test/visitors/test_postgres.rb6
4 files changed, 8 insertions, 6 deletions
diff --git a/lib/arel/visitors/mysql.rb b/lib/arel/visitors/mysql.rb
index b37d76f710..e90161eee4 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 #{visit o.limit}" if o.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 01fbda75b9..0e82a703ca 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 #{visit o.limit}" if o.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 135348580d..c3b79ca667 100644
--- a/test/visitors/test_mysql.rb
+++ b/test/visitors/test_mysql.rb
@@ -19,8 +19,8 @@ module Arel
it "should escape LIMIT" do
sc = Arel::Nodes::UpdateStatement.new
- sc.limit = "omg"
- assert_match(/LIMIT 'omg'/, @visitor.accept(sc))
+ sc.limit = Nodes::Limit.new("omg")
+ assert_equal("UPDATE NULL LIMIT 'omg'", @visitor.accept(sc))
end
it 'uses DUAL for empty from' do
diff --git a/test/visitors/test_postgres.rb b/test/visitors/test_postgres.rb
index b98f78ca12..6e8f399b6b 100644
--- a/test/visitors/test_postgres.rb
+++ b/test/visitors/test_postgres.rb
@@ -15,10 +15,12 @@ module Arel
it "should escape LIMIT" do
sc = Arel::Nodes::SelectStatement.new
- sc.limit = "omg"
+ sc.limit = Nodes::Limit.new("omg")
sc.cores.first.projections << 'DISTINCT ON'
sc.orders << "xyz"
- assert_match(/LIMIT 'omg'/, @visitor.accept(sc))
+ sql = @visitor.accept(sc)
+ assert_match(/LIMIT 'omg'/, sql)
+ assert_equal 1, sql.scan(/LIMIT/).length, 'should have one limit'
end
end
end