diff options
-rw-r--r-- | lib/arel/visitors/mysql.rb | 5 | ||||
-rw-r--r-- | lib/arel/visitors/to_sql.rb | 1 | ||||
-rw-r--r-- | test/visitors/test_mysql.rb | 8 |
3 files changed, 13 insertions, 1 deletions
diff --git a/lib/arel/visitors/mysql.rb b/lib/arel/visitors/mysql.rb index 594fd5504a..afffd37f9b 100644 --- a/lib/arel/visitors/mysql.rb +++ b/lib/arel/visitors/mysql.rb @@ -10,6 +10,11 @@ module Arel super end + def visit_Arel_Nodes_SelectCore o + o.froms ||= Arel.sql('DUAL') + super + end + def visit_Arel_Nodes_UpdateStatement o [ "UPDATE #{visit o.relation}", diff --git a/lib/arel/visitors/to_sql.rb b/lib/arel/visitors/to_sql.rb index 1412797fb5..3c96b3e259 100644 --- a/lib/arel/visitors/to_sql.rb +++ b/lib/arel/visitors/to_sql.rb @@ -48,6 +48,7 @@ module Arel ("WHERE #{wheres.map { |x| visit x }.join ' AND '}" unless wheres.empty?) ].compact.join ' ' end + def visit_Arel_Nodes_InsertStatement o [ "INSERT INTO #{visit o.relation}", diff --git a/test/visitors/test_mysql.rb b/test/visitors/test_mysql.rb index 1d38161caf..871d662d4b 100644 --- a/test/visitors/test_mysql.rb +++ b/test/visitors/test_mysql.rb @@ -14,7 +14,13 @@ module Arel stmt = Nodes::SelectStatement.new stmt.offset = Nodes::Offset.new(1) sql = @visitor.accept(stmt) - sql.must_be_like "SELECT LIMIT 18446744073709551615 OFFSET 1" + sql.must_be_like "SELECT FROM DUAL LIMIT 18446744073709551615 OFFSET 1" + end + + it 'uses DUAL for empty from' do + stmt = Nodes::SelectStatement.new + sql = @visitor.accept(stmt) + sql.must_be_like "SELECT FROM DUAL" end end end |