diff options
-rw-r--r-- | History.txt | 6 | ||||
-rw-r--r-- | lib/arel/visitors/dot.rb | 12 | ||||
-rw-r--r-- | lib/arel/visitors/mysql.rb | 2 | ||||
-rw-r--r-- | lib/arel/visitors/postgresql.rb | 2 | ||||
-rw-r--r-- | lib/arel/visitors/to_sql.rb | 2 | ||||
-rw-r--r-- | test/visitors/test_mysql.rb | 6 | ||||
-rw-r--r-- | test/visitors/test_postgres.rb | 8 | ||||
-rw-r--r-- | test/visitors/test_to_sql.rb | 6 |
8 files changed, 29 insertions, 15 deletions
diff --git a/History.txt b/History.txt index d3172f4162..25c7fba1e6 100644 --- a/History.txt +++ b/History.txt @@ -24,6 +24,12 @@ * Arel::Table.table_cache is deprecated and will be removed in 3.0.0 with no replacement. +== 2.0.7 (unreleased) + +* Bug Fixes + + * Limit members are visited + == 2.0.6 12/01/2010 * Bug Fixes diff --git a/lib/arel/visitors/dot.rb b/lib/arel/visitors/dot.rb index c515cbe220..eab5e4afdc 100644 --- a/lib/arel/visitors/dot.rb +++ b/lib/arel/visitors/dot.rb @@ -28,10 +28,6 @@ module Arel end private - def visit_Arel_Nodes_Grouping o - visit_edge o, "expr" - end - def visit_Arel_Nodes_Ordering o visit_edge o, "expr" visit_edge o, "direction" @@ -55,10 +51,6 @@ module Arel visit_edge o, "distinct" end - def visit_Arel_Nodes_On o - visit_edge o, "expr" - end - def visit_Arel_Nodes_Values o visit_edge o, "expressions" end @@ -80,10 +72,6 @@ module Arel visit_edge o, "wheres" end - def visit_Arel_Nodes_UnqualifiedColumn o - visit_edge o, "attribute" - end - def unary o visit_edge o, "expr" end 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/lib/arel/visitors/to_sql.rb b/lib/arel/visitors/to_sql.rb index f4c529bf92..5446298189 100644 --- a/lib/arel/visitors/to_sql.rb +++ b/lib/arel/visitors/to_sql.rb @@ -109,7 +109,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 ' ' 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 3c9fc95a0b..c49d2a6bdf 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 |