Project

General

Profile

Feature #24013 » current_trunk_Decimal_data_type_fix.patch

Andrey Lobanov (RedSoft), 2017-01-23 15:47

View differences:

app/models/query.rb (date 1485182791000)
1024 1024
          int_values = value.first.to_s.scan(/[+-]?\d+/).map(&:to_i).join(",")
1025 1025
          if int_values.present?
1026 1026
            if is_custom_filter
1027
              sql = "(#{db_table}.#{db_field} <> '' AND CAST(CASE #{db_table}.#{db_field} WHEN '' THEN '0' ELSE #{db_table}.#{db_field} END AS decimal(30,3)) IN (#{int_values}))"
1027
              sql = "(#{db_table}.#{db_field} <> '' AND CAST(CASE #{db_table}.#{db_field} WHEN '' THEN '0' ELSE #{db_table}.#{db_field} END AS decimal(18,3)) IN (#{int_values}))"
1028 1028
            else
1029 1029
              sql = "#{db_table}.#{db_field} IN (#{int_values})"
1030 1030
            end
......
1033 1033
          end
1034 1034
        when :float
1035 1035
          if is_custom_filter
1036
            sql = "(#{db_table}.#{db_field} <> '' AND CAST(CASE #{db_table}.#{db_field} WHEN '' THEN '0' ELSE #{db_table}.#{db_field} END AS decimal(30,3)) BETWEEN #{value.first.to_f - 1e-5} AND #{value.first.to_f + 1e-5})"
1036
            sql = "(#{db_table}.#{db_field} <> '' AND CAST(CASE #{db_table}.#{db_field} WHEN '' THEN '0' ELSE #{db_table}.#{db_field} END AS decimal(18,3)) BETWEEN #{value.first.to_f - 1e-5} AND #{value.first.to_f + 1e-5})"
1037 1037
          else
1038 1038
            sql = "#{db_table}.#{db_field} BETWEEN #{value.first.to_f - 1e-5} AND #{value.first.to_f + 1e-5}"
1039 1039
          end
......
1062 1062
        sql = date_clause(db_table, db_field, parse_date(value.first), nil, is_custom_filter)
1063 1063
      else
1064 1064
        if is_custom_filter
1065
          sql = "(#{db_table}.#{db_field} <> '' AND CAST(CASE #{db_table}.#{db_field} WHEN '' THEN '0' ELSE #{db_table}.#{db_field} END AS decimal(30,3)) >= #{value.first.to_f})"
1065
          sql = "(#{db_table}.#{db_field} <> '' AND CAST(CASE #{db_table}.#{db_field} WHEN '' THEN '0' ELSE #{db_table}.#{db_field} END AS decimal(18,3)) >= #{value.first.to_f})"
1066 1066
        else
1067 1067
          sql = "#{db_table}.#{db_field} >= #{value.first.to_f}"
1068 1068
        end
......
1072 1072
        sql = date_clause(db_table, db_field, nil, parse_date(value.first), is_custom_filter)
1073 1073
      else
1074 1074
        if is_custom_filter
1075
          sql = "(#{db_table}.#{db_field} <> '' AND CAST(CASE #{db_table}.#{db_field} WHEN '' THEN '0' ELSE #{db_table}.#{db_field} END AS decimal(30,3)) <= #{value.first.to_f})"
1075
          sql = "(#{db_table}.#{db_field} <> '' AND CAST(CASE #{db_table}.#{db_field} WHEN '' THEN '0' ELSE #{db_table}.#{db_field} END AS decimal(18,3)) <= #{value.first.to_f})"
1076 1076
        else
1077 1077
          sql = "#{db_table}.#{db_field} <= #{value.first.to_f}"
1078 1078
        end
......
1082 1082
        sql = date_clause(db_table, db_field, parse_date(value[0]), parse_date(value[1]), is_custom_filter)
1083 1083
      else
1084 1084
        if is_custom_filter
1085
          sql = "(#{db_table}.#{db_field} <> '' AND CAST(CASE #{db_table}.#{db_field} WHEN '' THEN '0' ELSE #{db_table}.#{db_field} END AS decimal(30,3)) BETWEEN #{value[0].to_f} AND #{value[1].to_f})"
1085
          sql = "(#{db_table}.#{db_field} <> '' AND CAST(CASE #{db_table}.#{db_field} WHEN '' THEN '0' ELSE #{db_table}.#{db_field} END AS decimal(18,3)) BETWEEN #{value[0].to_f} AND #{value[1].to_f})"
1086 1086
        else
1087 1087
          sql = "#{db_table}.#{db_field} BETWEEN #{value[0].to_f} AND #{value[1].to_f}"
1088 1088
        end
lib/redmine/field_format.rb (date 1485182791000)
432 432
        # Postgresql will raise an error if a value can not be casted!
433 433
        # CustomValue validations should ensure that it doesn't occur
434 434
        value_col = 'value'.quote_column_name
435
        "CAST(CASE #{join_alias custom_field}.#{value_col} WHEN '' THEN '0' ELSE #{join_alias custom_field}.#{value_col} END AS decimal(30,3))"
435
        "CAST(CASE #{join_alias custom_field}.#{value_col} WHEN '' THEN '0' ELSE #{join_alias custom_field}.#{value_col} END AS decimal(18,3))"
436 436
      end
437 437

  
438 438
      # Returns totals for the given scope
......
440 440
        scope.joins(:custom_values).
441 441
          where(:custom_values => {:custom_field_id => custom_field.id}).
442 442
          where.not(:custom_values => {:value => ''}).
443
          sum("CAST(#{CustomValue.table_name}.#{'value'.quote_column_name} AS decimal(30,3))")
443
          sum("CAST(#{CustomValue.table_name}.#{'value'.quote_column_name} AS decimal(18,3))")
444 444
      end
445 445

  
446 446
      def cast_total_value(custom_field, value)
(9-9/11)