Permalink
Browse files

Merge branch 'master' of github.com:brynary/arel

* 'master' of github.com:brynary/arel:
  fix order_hacks method for Oracle when complex functions are used in order by
  • Loading branch information...
2 parents dbd0140 + 64b8765 commit a0c206b356315380493881aa139a85928b9b88ae @tenderlove tenderlove committed Nov 11, 2010
Showing with 17 additions and 1 deletion.
  1. +17 −1 lib/arel/visitors/oracle.rb
@@ -70,7 +70,23 @@ def order_hacks o
/DISTINCT.*FIRST_VALUE/ === projection
end
end
- orders = o.orders.map { |x| visit x }.join(', ').split(',')
+ # FIXME: previous version with join and split broke ORDER BY clause
+ # if it contained functions with several arguments (separated by ',').
+ # Currently splitting is done only if there is no function calls
+ #
+ # orders = o.orders.map { |x| visit x }.join(', ').split(',')
+ orders = o.orders.map do |x|
+ string = visit x
+ # if there is function call
+ if string.include?('(')
+ string
+ # if no function call then comma splits several ORDER BY columns
+ elsif string.include?(',')
+ string.split(',')
+ else
+ string
+ end
+ end.flatten
o.orders = []
orders.each_with_index do |order, i|
o.orders <<

0 comments on commit a0c206b

Please sign in to comment.