Changeset 6557


Ignore:
Timestamp:
Oct 7, 2014, 2:35:33 PM (8 years ago)
Author:
Nicklas Nordborg
Message:

Fixes #1862: If() formula can't return null value

Location:
branches/3.3-stable/src/core/net/sf/basedb/core/query
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/3.3-stable/src/core/net/sf/basedb/core/query/CaseExpression.java

    r6127 r6557  
    7474    {
    7575      sb.append("WHEN ").append(when.getCondition().toQl(query, dc));
    76       sb.append(" THEN ").append(when.getValue().toQl(query, dc));
     76      sb.append(" THEN ").append(when.getValue() == null ? "null" : when.getValue().toQl(query, dc));
    7777      sb.append("\n");
    7878    }
     
    9595    {
    9696      all.add(when.getCondition());
    97       all.add(when.getValue());
     97      if (when.getValue() != null) all.add(when.getValue());
    9898    }
    9999    if (elseExpression != null) all.add(elseExpression);
  • branches/3.3-stable/src/core/net/sf/basedb/core/query/WhenStatement.java

    r5320 r6557  
    2323
    2424import net.sf.basedb.core.InvalidUseOfNullException;
     25import net.sf.basedb.util.EqualsHelper;
    2526
    2627/**
     
    4546      value is returned or not, null is not allowed
    4647    @param value The value to return if the condition is TRUE,
    47       null is not allowed
     48      null is allowed
    4849  */
    4950  public WhenStatement(Restriction condition, Expression value)
    5051  {
    5152    if (condition == null) throw new InvalidUseOfNullException("condition");
    52     if (value == null) throw new InvalidUseOfNullException("value");
    5353    this.condition = condition;
    5454    this.value = value;
     
    8282    StringBuilder sb = new StringBuilder();
    8383    sb.append("WHEN ").append(getCondition().toString());
    84     sb.append(" THEN ").append(getValue().toString());
     84    sb.append(" THEN ").append(getValue() == null ? "null" : getValue().toString());
    8585    return sb.toString();
    8686  }
     
    9696    if (other == null || this.getClass() != other.getClass()) return false;
    9797    WhenStatement o = (WhenStatement)other;
    98     return condition.equals(o.condition) && value.equals(o.value);
     98    return condition.equals(o.condition) && EqualsHelper.equals(value, o.value);
    9999  }
    100100
     
    102102  public int hashCode()
    103103  {
    104     return condition.hashCode() + value.hashCode();
     104    return condition.hashCode() + (value == null ? 0 : value.hashCode());
    105105  }
    106106  // -------------------------------------------
Note: See TracChangeset for help on using the changeset viewer.