HHH-9356 All arguments of a between are now given the same expected type.

This commit is contained in:
Etienne Miret 2014-08-24 10:45:19 +02:00 committed by Brett Meyer
parent dfb6ed1cba
commit 48210916c2
1 changed files with 20 additions and 15 deletions

View File

@ -34,9 +34,26 @@ public class BetweenOperatorNode extends SqlNode implements OperatorNode {
throw new SemanticException( "high operand of a between operator was null" );
}
check( fixture, low, high );
check( low, high, fixture );
check( high, fixture, low );
Type expectedType = null;
if ( fixture instanceof SqlNode ) {
expectedType = ( (SqlNode) fixture ).getDataType();
}
if ( expectedType == null && low instanceof SqlNode ) {
expectedType = ( (SqlNode) low ).getDataType();
}
if ( expectedType == null && high instanceof SqlNode ) {
expectedType = ( (SqlNode) high ).getDataType();
}
if ( fixture instanceof ExpectedTypeAwareNode ) {
( (ExpectedTypeAwareNode) fixture ).setExpectedType( expectedType );
}
if ( low instanceof ExpectedTypeAwareNode ) {
( (ExpectedTypeAwareNode) low ).setExpectedType( expectedType );
}
if ( high instanceof ExpectedTypeAwareNode ) {
( (ExpectedTypeAwareNode) high ).setExpectedType( expectedType );
}
}
@Override
@ -57,16 +74,4 @@ public class BetweenOperatorNode extends SqlNode implements OperatorNode {
return (Node) getFirstChild().getNextSibling().getNextSibling();
}
private void check(Node check, Node first, Node second) {
if ( ExpectedTypeAwareNode.class.isAssignableFrom( check.getClass() ) ) {
Type expectedType = null;
if ( SqlNode.class.isAssignableFrom( first.getClass() ) ) {
expectedType = ( (SqlNode) first ).getDataType();
}
if ( expectedType == null && SqlNode.class.isAssignableFrom( second.getClass() ) ) {
expectedType = ( (SqlNode) second ).getDataType();
}
( (ExpectedTypeAwareNode) check ).setExpectedType( expectedType );
}
}
}