diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2011-12-05 20:45:45 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2011-12-05 20:45:45 +0000 |
commit | 5ca558f19177472cd17f0b5e72e649845c301ae7 (patch) | |
tree | 83ede372e6d07e3ae10e3efb4ad6113c37da9b03 /app/models/query.rb | |
parent | c562d79e4fb12c44693e50c815ed0d1cc822ab78 (diff) | |
download | redmine-5ca558f19177472cd17f0b5e72e649845c301ae7.tar.gz redmine-5ca558f19177472cd17f0b5e72e649845c301ae7.zip |
Fixed: error when filtering by numeric custom field with postgresql (#9719).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@8098 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models/query.rb')
-rw-r--r-- | app/models/query.rb | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/app/models/query.rb b/app/models/query.rb index 0f1404745..3e2fec29d 100644 --- a/app/models/query.rb +++ b/app/models/query.rb @@ -674,9 +674,17 @@ class Query < ActiveRecord::Base when :date, :date_past sql = date_clause(db_table, db_field, (Date.parse(value.first) rescue nil), (Date.parse(value.first) rescue nil)) when :integer - sql = "#{db_table}.#{db_field} = #{value.first.to_i}" + if is_custom_filter + sql = "(#{db_table}.#{db_field} <> '' AND CAST(#{db_table}.#{db_field} AS decimal(60,3)) = #{value.first.to_i})" + else + sql = "#{db_table}.#{db_field} = #{value.first.to_i}" + end when :float - sql = "#{db_table}.#{db_field} BETWEEN #{value.first.to_f - 1e-5} AND #{value.first.to_f + 1e-5}" + if is_custom_filter + sql = "(#{db_table}.#{db_field} <> '' AND CAST(#{db_table}.#{db_field} AS decimal(60,3)) BETWEEN #{value.first.to_f - 1e-5} AND #{value.first.to_f + 1e-5})" + else + sql = "#{db_table}.#{db_field} BETWEEN #{value.first.to_f - 1e-5} AND #{value.first.to_f + 1e-5}" + end else sql = "#{db_table}.#{db_field} IN (" + value.collect{|val| "'#{connection.quote_string(val)}'"}.join(",") + ")" end @@ -702,7 +710,7 @@ class Query < ActiveRecord::Base sql = date_clause(db_table, db_field, (Date.parse(value.first) rescue nil), nil) else if is_custom_filter - sql = "CAST(#{db_table}.#{db_field} AS decimal(60,3)) >= #{value.first.to_f}" + sql = "(#{db_table}.#{db_field} <> '' AND CAST(#{db_table}.#{db_field} AS decimal(60,3)) >= #{value.first.to_f})" else sql = "#{db_table}.#{db_field} >= #{value.first.to_f}" end @@ -712,7 +720,7 @@ class Query < ActiveRecord::Base sql = date_clause(db_table, db_field, nil, (Date.parse(value.first) rescue nil)) else if is_custom_filter - sql = "CAST(#{db_table}.#{db_field} AS decimal(60,3)) <= #{value.first.to_f}" + sql = "(#{db_table}.#{db_field} <> '' AND CAST(#{db_table}.#{db_field} AS decimal(60,3)) <= #{value.first.to_f})" else sql = "#{db_table}.#{db_field} <= #{value.first.to_f}" end @@ -722,7 +730,7 @@ class Query < ActiveRecord::Base sql = date_clause(db_table, db_field, (Date.parse(value[0]) rescue nil), (Date.parse(value[1]) rescue nil)) else if is_custom_filter - sql = "CAST(#{db_table}.#{db_field} AS decimal(60,3)) BETWEEN #{value[0].to_f} AND #{value[1].to_f}" + sql = "(#{db_table}.#{db_field} <> '' AND CAST(#{db_table}.#{db_field} AS decimal(60,3)) BETWEEN #{value[0].to_f} AND #{value[1].to_f})" else sql = "#{db_table}.#{db_field} BETWEEN #{value[0].to_f} AND #{value[1].to_f}" end |