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
Fix#367 pagination not working with group on SQLSERVER 2000.
The pagination condition was added before the ORDER condition.
If there is a GROUP BY clause, the pagination was in the GROUP BY
instead of the WHERE clause. New approach is extraction each clause and
build a new proper query.
additional_condition="#{table_name}.#{primary_key} NOT IN (#{select} TOP #{offset}#{table_name}.#{primary_key}#{query_without_select}#{new_order})"
75
76
76
-
if(rest_of_query.match(/WHERE/).nil?)
77
-
new_sql="#{select} TOP #{limit}#{rest_of_query} WHERE #{table_name}.#{primary_key} NOT IN (#{select} TOP #{offset}#{table_name}.#{primary_key}#{rest}#{new_order}) #{order} "
# Update the where part to add our additional condition
81
+
ifwhere.blank?
82
+
where="WHERE #{additional_condition}"
78
83
else
79
-
new_sql="#{select} TOP #{limit}#{rest_of_query}AND #{table_name}.#{primary_key} NOT IN (#{select} TOP #{offset}#{table_name}.#{primary_key}#{rest}#{new_order}) #{order}"
84
+
where="#{where}AND #{additional_condition}"
80
85
end
81
86
82
-
sql.replace(new_sql)
87
+
# Replace the query to be our new customized query
88
+
sql.replace("#{select} TOP #{limit}#{selection}#{from}#{where}#{group_by}#{having}#{new_order}")
83
89
end
84
90
end
85
91
sql
86
92
end
93
+
94
+
# Split the rest_of_query into chunks based on regexs (applied from end of string to the beginning)
95
+
# The result is an array of regexs.size+1 elements (the last one being the remaining once everything was chopped away)
96
+
defsplit_sqlrest_of_query, *regexs
97
+
results=Array.new
98
+
99
+
regexs.eachdo |regex|
100
+
ifposition=(regex =~ rest_of_query)
101
+
# Extract the matched string and chop the rest_of_query
102
+
matched=rest_of_query[position..-1]
103
+
rest_of_query=rest_of_query[0...position]
104
+
else
105
+
matched=nil
106
+
end
107
+
108
+
results << matched
109
+
end
110
+
results << rest_of_query
111
+
112
+
results
113
+
end
87
114
88
115
defget_primary_key(order,table_name)# table_name might be quoted
0 commit comments