rename parameter/update code doc

it is actually expected to be an array...
pull/3338/head
Jan Sandbrink 9 years ago
parent d8ec635e9e
commit 92bb497a66
  1. 38
      app/models/query.rb

@ -496,24 +496,24 @@ class Query < ActiveRecord::Base
matchdata.nil? ? nil : matchdata[:id]
end
# Helper method to generate the WHERE sql for a +field+, +operator+ and a +value+
def sql_for_field(field, operator, value, db_table, db_field, is_custom_filter = false)
# Helper method to generate the WHERE sql for a +field+, +operator+ and a +values+ array
def sql_for_field(field, operator, values, db_table, db_field, is_custom_filter = false)
sql = ''
case operator
when '='
if value.present?
if value.include?('-1')
if values.present?
if values.include?('-1')
sql = "#{db_table}.#{db_field} IS NULL OR "
end
sql += "#{db_table}.#{db_field} IN (" + value.map { |val| "'#{connection.quote_string(val)}'" }.join(',') + ')'
sql += "#{db_table}.#{db_field} IN (" + values.map { |val| "'#{connection.quote_string(val)}'" }.join(',') + ')'
else
# empty set of allowed values produces no result
sql = '0=1'
end
when '!'
if value.present?
sql = "(#{db_table}.#{db_field} IS NULL OR #{db_table}.#{db_field} NOT IN (" + value.map { |val| "'#{connection.quote_string(val)}'" }.join(',') + '))'
if values.present?
sql = "(#{db_table}.#{db_field} IS NULL OR #{db_table}.#{db_field} NOT IN (" + values.map { |val| "'#{connection.quote_string(val)}'" }.join(',') + '))'
else
# empty set of forbidden values allows all results
sql = '1=1'
@ -526,32 +526,32 @@ class Query < ActiveRecord::Base
sql << " AND #{db_table}.#{db_field} <> ''" if is_custom_filter
when '>='
if is_custom_filter
sql = "#{db_table}.#{db_field} != '' AND CAST(#{db_table}.#{db_field} AS decimal(60,4)) >= #{value.first.to_f}"
sql = "#{db_table}.#{db_field} != '' AND CAST(#{db_table}.#{db_field} AS decimal(60,4)) >= #{values.first.to_f}"
else
sql = "#{db_table}.#{db_field} >= #{value.first.to_f}"
sql = "#{db_table}.#{db_field} >= #{values.first.to_f}"
end
when '<='
if is_custom_filter
sql = "#{db_table}.#{db_field} != '' AND CAST(#{db_table}.#{db_field} AS decimal(60,4)) <= #{value.first.to_f}"
sql = "#{db_table}.#{db_field} != '' AND CAST(#{db_table}.#{db_field} AS decimal(60,4)) <= #{values.first.to_f}"
else
sql = "#{db_table}.#{db_field} <= #{value.first.to_f}"
sql = "#{db_table}.#{db_field} <= #{values.first.to_f}"
end
when 'o'
sql = "#{Status.table_name}.is_closed=#{connection.quoted_false}" if field == 'status_id'
when 'c'
sql = "#{Status.table_name}.is_closed=#{connection.quoted_true}" if field == 'status_id'
when '>t-'
sql = date_range_clause(db_table, db_field, - value.first.to_i, 0)
sql = date_range_clause(db_table, db_field, - values.first.to_i, 0)
when '<t-'
sql = date_range_clause(db_table, db_field, nil, - value.first.to_i)
sql = date_range_clause(db_table, db_field, nil, - values.first.to_i)
when 't-'
sql = date_range_clause(db_table, db_field, - value.first.to_i, - value.first.to_i)
sql = date_range_clause(db_table, db_field, - values.first.to_i, - values.first.to_i)
when '>t+'
sql = date_range_clause(db_table, db_field, value.first.to_i, nil)
sql = date_range_clause(db_table, db_field, values.first.to_i, nil)
when '<t+'
sql = date_range_clause(db_table, db_field, 0, value.first.to_i)
sql = date_range_clause(db_table, db_field, 0, values.first.to_i)
when 't+'
sql = date_range_clause(db_table, db_field, value.first.to_i, value.first.to_i)
sql = date_range_clause(db_table, db_field, values.first.to_i, values.first.to_i)
when 't'
sql = date_range_clause(db_table, db_field, 0, 0)
when 'w'
@ -562,9 +562,9 @@ class Query < ActiveRecord::Base
Time.now.at_beginning_of_week
sql = "#{db_table}.#{db_field} BETWEEN '%s' AND '%s'" % [connection.quoted_date(from), connection.quoted_date(from + 7.days)]
when '~'
sql = "LOWER(#{db_table}.#{db_field}) LIKE '%#{connection.quote_string(value.first.to_s.downcase)}%'"
sql = "LOWER(#{db_table}.#{db_field}) LIKE '%#{connection.quote_string(values.first.to_s.downcase)}%'"
when '!~'
sql = "LOWER(#{db_table}.#{db_field}) NOT LIKE '%#{connection.quote_string(value.first.to_s.downcase)}%'"
sql = "LOWER(#{db_table}.#{db_field}) NOT LIKE '%#{connection.quote_string(values.first.to_s.downcase)}%'"
end
sql

Loading…
Cancel
Save