Fix Sybase duration arithmetic problem
This commit is contained in:
parent
35fa14a666
commit
b57fbb1245
|
@ -103,7 +103,7 @@ public class IntegralTimestampaddFunction
|
|||
|
||||
private Expression convertedArgument(DurationUnit field, TemporalUnit unit, Expression magnitude) {
|
||||
final BasicValuedMapping expressionType = (BasicValuedMapping) magnitude.getExpressionType();
|
||||
final String conversionFactor = field.getUnit().conversionFactor( unit, dialect );
|
||||
final String conversionFactor = field.getUnit().conversionFactorFull( unit, dialect );
|
||||
return conversionFactor.isEmpty()
|
||||
? magnitude
|
||||
: new BinaryArithmeticExpression(
|
||||
|
|
|
@ -197,6 +197,33 @@ public enum TemporalUnit {
|
|||
}
|
||||
}
|
||||
|
||||
public String conversionFactorFull(TemporalUnit unit, Dialect dialect) {
|
||||
|
||||
if ( unit == this ) {
|
||||
//same unit, nothing to do
|
||||
return "";
|
||||
}
|
||||
|
||||
if ( unit.normalized() != normalized() ) {
|
||||
throw new SemanticException("Illegal unit conversion " + this + " to " + unit);
|
||||
}
|
||||
|
||||
long from = normalizationFactor( dialect );
|
||||
long to = unit.normalizationFactor( dialect );
|
||||
if ( from == to ) {
|
||||
// the units represent the same amount of time
|
||||
return "";
|
||||
}
|
||||
else {
|
||||
// if from < to, then this unit represents a
|
||||
// smaller amount of time than the given unit
|
||||
// we are converting to (so we're going to
|
||||
// need to use division)
|
||||
return (from < to ? "/" : "*")
|
||||
+ (from < to ? to / from : from / to);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The conversion factor required to convert this
|
||||
* unit to its {@link #normalized()} unit.
|
||||
|
|
Loading…
Reference in New Issue