[#250] Allow empty sets in query value lists

pull/351/head
Holger Just 14 years ago
parent f2285fa914
commit 21b8e8b5e5
  1. 10
      app/models/query.rb

@ -566,9 +566,19 @@ class Query < ActiveRecord::Base
sql = '' sql = ''
case operator case operator
when "=" when "="
if value.present?
sql = "#{db_table}.#{db_field} IN (" + value.collect{|val| "'#{connection.quote_string(val)}'"}.join(",") + ")" sql = "#{db_table}.#{db_field} IN (" + value.collect{|val| "'#{connection.quote_string(val)}'"}.join(",") + ")"
else
# empty set of allowed values produces no result
sql = "0=1"
end
when "!" when "!"
if value.present?
sql = "(#{db_table}.#{db_field} IS NULL OR #{db_table}.#{db_field} NOT IN (" + value.collect{|val| "'#{connection.quote_string(val)}'"}.join(",") + "))" sql = "(#{db_table}.#{db_field} IS NULL OR #{db_table}.#{db_field} NOT IN (" + value.collect{|val| "'#{connection.quote_string(val)}'"}.join(",") + "))"
else
# empty set of forbidden values allows all results
sql = "1=1"
end
when "!*" when "!*"
sql = "#{db_table}.#{db_field} IS NULL" sql = "#{db_table}.#{db_field} IS NULL"
sql << " OR #{db_table}.#{db_field} = ''" if is_custom_filter sql << " OR #{db_table}.#{db_field} = ''" if is_custom_filter

Loading…
Cancel
Save