aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2010-11-05 14:28:36 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2010-11-05 14:28:36 -0700
commit22a38c6a86bc6323f7aa1fd3179a9f8ed7591267 (patch)
treef800dd300d7ee0e9288e3dc20cd244fc4fc123bf
parenta1a01e2bb301a7a4ae5c5cdcc27ece9f7edf6c66 (diff)
downloadrails-22a38c6a86bc6323f7aa1fd3179a9f8ed7591267.tar.gz
rails-22a38c6a86bc6323f7aa1fd3179a9f8ed7591267.tar.bz2
rails-22a38c6a86bc6323f7aa1fd3179a9f8ed7591267.zip
mysql selects from dual on empty from statements
-rw-r--r--lib/arel/visitors/mysql.rb5
-rw-r--r--lib/arel/visitors/to_sql.rb1
-rw-r--r--test/visitors/test_mysql.rb8
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