if (rightOperand.requiresTypeFromContext()) {
throw StandardException.newException(
SQLState.LANG_BINARY_OPERANDS_BOTH_PARMS, operator);
}
TypeId leftType;
/*
* * A ? on the left gets its type from the right. There are eight *
* legal types for the concatenation operator: CHAR, VARCHAR, * LONG
* VARCHAR, CLOB, BIT, BIT VARYING, LONG BIT VARYING, and BLOB. * If
* the right type is BLOB, set the parameter type to BLOB with max
* length. * If the right type is one of the other bit types, set
* the parameter type to * BIT VARYING with maximum length. * * If
* the right type is CLOB, set parameter type to CLOB with max
* length. * If the right type is anything else, set it to VARCHAR
* with * maximum length. We count on the resolveConcatOperation
* method to * catch an illegal type. * * NOTE: When I added the
* long types, I could have changed the * resulting parameter types
* to LONG VARCHAR and LONG BIT VARYING, * but they were already
* VARCHAR and BIT VARYING, and it wasn't * clear to me what effect
* it would have to change it. - Jeff
*/
if (rightOperand.getTypeId().isBitTypeId()) {
if (rightOperand.getTypeId().isBlobTypeId())
leftType = TypeId.getBuiltInTypeId(Types.BLOB);
else
leftType = TypeId.getBuiltInTypeId(Types.VARBINARY);
} else {
if (rightOperand.getTypeId().isClobTypeId())
leftType = TypeId.getBuiltInTypeId(Types.CLOB);
else
leftType = TypeId.getBuiltInTypeId(Types.VARCHAR);
}
leftOperand.setType(new DataTypeDescriptor(leftType, true));
if (rightOperand.getTypeId().isStringTypeId()) {
//collation of ? operand should be picked from the context
leftOperand.getTypeServices().setCollationDerivation(
rightOperand.getTypeServices().getCollationDerivation());
leftOperand.getTypeServices().setCollationType(
rightOperand.getTypeServices().getCollationType());
}
}
/*
* Is there a ? parameter on the right?
*/
if (rightOperand.requiresTypeFromContext()) {
TypeId rightType;
/*
* * A ? on the right gets its type from the left. There are eight *
* legal types for the concatenation operator: CHAR, VARCHAR, * LONG
* VARCHAR, CLOB, BIT, BIT VARYING, LONG BIT VARYING, and BLOB. * If