aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2010-09-24 15:09:26 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2010-09-24 15:09:26 -0700
commit245d797a8ccab3ed2de9a0eedf455d3094a091ce (patch)
tree9291f4e4536a3e16c8a57c8138d5488117a6275f
parent6420041b88bc16d8f838815185b4d004907b837e (diff)
downloadrails-245d797a8ccab3ed2de9a0eedf455d3094a091ce.tar.gz
rails-245d797a8ccab3ed2de9a0eedf455d3094a091ce.tar.bz2
rails-245d797a8ccab3ed2de9a0eedf455d3094a091ce.zip
yay, more oracle hacks
-rw-r--r--lib/arel/visitors/oracle.rb4
-rw-r--r--spec/arel/visitors/oracle_spec.rb12
2 files changed, 14 insertions, 2 deletions
diff --git a/lib/arel/visitors/oracle.rb b/lib/arel/visitors/oracle.rb
index 8d6c15f37d..659b75f16d 100644
--- a/lib/arel/visitors/oracle.rb
+++ b/lib/arel/visitors/oracle.rb
@@ -54,11 +54,11 @@ module Arel
/DISTINCT.*FIRST_VALUE/ === projection
end
end
- orders = o.orders
+ orders = o.orders.map { |x| visit x }.join(', ').split(',')
o.orders = []
orders.each_with_index do |order, i|
o.orders <<
- Nodes::SqlLiteral.new("alias_#{i}__ #{'DESC' if /\bdesc$/i === order}")
+ Nodes::SqlLiteral.new("alias_#{i}__#{' DESC' if /\bdesc$/i === order}")
end
o
end
diff --git a/spec/arel/visitors/oracle_spec.rb b/spec/arel/visitors/oracle_spec.rb
index 784f4b24e1..cdf0e3427f 100644
--- a/spec/arel/visitors/oracle_spec.rb
+++ b/spec/arel/visitors/oracle_spec.rb
@@ -31,6 +31,18 @@ module Arel
check sql.should == sql2
end
+ it 'splits orders with commas' do
+ # *sigh*
+ select = "DISTINCT foo.id, FIRST_VALUE(projects.name) OVER (foo) AS alias_0__"
+ stmt = Nodes::SelectStatement.new
+ stmt.cores.first.projections << Nodes::SqlLiteral.new(select)
+ stmt.orders << Nodes::SqlLiteral.new('foo, bar')
+ sql = @visitor.accept(stmt)
+ sql.should be_like %{
+ SELECT #{select} ORDER BY alias_0__, alias_1__
+ }
+ end
+
describe 'Nodes::SelectStatement' do
describe 'limit' do
it 'adds a rownum clause' do