You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Ensure correct queries if the rest_of_query contains a 'GROUP BY'. Otherwise the following error occurs:
28
+
# ActiveRecord::StatementInvalid: ActiveRecord::JDBCError: Column 'users.id' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
29
+
# SELECT t.* FROM ( SELECT ROW_NUMBER() OVER(ORDER BY users.id) AS _row_num, [users].[lft], COUNT([users].[lft]) FROM [users] GROUP BY [users].[lft] HAVING COUNT([users].[lft]) > 1 ) AS t WHERE t._row_num BETWEEN 1 AND 1
30
+
ifrest_of_query.downcase.include?('group by')
31
+
iforder.count(',') == 0
32
+
order.gsub!(/ORDER BY (.*)/,'ORDER BY MIN(\1)')
33
+
else
34
+
raise('Only one order condition allowed.')
35
+
end
36
+
end
37
+
27
38
ifdistinct# select =~ /DISTINCT/i
28
39
order=order.gsub(/([a-z0-9_])+\./,'t.')
29
40
new_sql="SELECT t.* FROM "
30
41
new_sql << "( SELECT ROW_NUMBER() OVER(#{order}) AS _row_num, t.* FROM (#{select}#{rest_of_query}) AS t ) AS t"
31
42
new_sql << " WHERE t._row_num BETWEEN #{start_row} AND #{end_row}"
0 commit comments