use of org.apache.derby.iapi.types.TypeId in project derby by apache.
the class BaseExpressionActivation method maxValue.
/**
* <p>
* Get the maximum value of 4 input values. If less than 4 values, input
* {@code null} for the unused parameters and place them at the end.
* If more than 4 input values, call this multiple times to
* accumulate results. Also have judge's type as parameter to have a base
* upon which the comparison is based. An example use is for code
* generation in bug 3858.
* </p>
*
* <p>
* If all the input values are SQL NULL, return SQL NULL. Otherwise, return
* the maximum value of the non-NULL inputs.
* </p>
*
* @param v1 1st value
* @param v2 2nd value
* @param v3 3rd value
* @param v4 4th value
* @param judgeTypeFormatId type format id of the judge
* @param judgeUserJDBCTypeId JDBC type id if judge is user type;
* -1 if not user type
*
* @return The maximum value of the 4.
*/
public static DataValueDescriptor maxValue(DataValueDescriptor v1, DataValueDescriptor v2, DataValueDescriptor v3, DataValueDescriptor v4, int judgeTypeFormatId, int judgeUserJDBCTypeId, int judgePrecision, int judgeScale, boolean judgeIsNullable, int judgeMaximumWidth, int judgeCollationType, int judgeCollationDerivation) throws StandardException {
DataValueDescriptor judge;
if (judgeUserJDBCTypeId == -1) {
judge = new DataTypeDescriptor(new TypeId(judgeTypeFormatId, null), judgePrecision, judgeScale, judgeIsNullable, judgeMaximumWidth, judgeCollationType, judgeCollationDerivation).getNull();
} else
judge = new TypeId(judgeTypeFormatId, new UserDefinedTypeIdImpl()).getNull();
DataValueDescriptor maxVal = v1;
if (v2 != null && (maxVal.isNull() || judge.greaterThan(v2, maxVal).equals(true)))
maxVal = v2;
if (v3 != null && (maxVal.isNull() || judge.greaterThan(v3, maxVal).equals(true)))
maxVal = v3;
if (v4 != null && (maxVal.isNull() || judge.greaterThan(v4, maxVal).equals(true)))
maxVal = v4;
return maxVal;
}
use of org.apache.derby.iapi.types.TypeId in project derby by apache.
the class ValueNode method checkIsBoolean.
/**
* Bind time logic. Raises an error if this ValueNode does not resolve to
* a boolean value. This method is called by WHERE clauses.
*
* @return bound coercion of this node to a builtin type as necessary
*
* @exception StandardException Thrown on error
*/
public ValueNode checkIsBoolean() throws StandardException {
ValueNode whereClause = this;
/*
** Is the datatype of the WHERE clause BOOLEAN?
**
** NOTE: This test is not necessary in SQL92 entry level, because
** it is syntactically impossible to have a non-Boolean WHERE clause
** in that level of the standard. But we intend to extend the
** language to allow Boolean user functions in the WHERE clause,
** so we need to test for the error condition.
*/
TypeId whereTypeId = whereClause.getTypeId();
/* If the where clause is not a built-in type, then generate a bound
* conversion tree to a built-in type.
*/
if (whereTypeId.userType()) {
whereClause = whereClause.genSQLJavaSQLTree();
whereTypeId = whereClause.getTypeId();
}
if (!whereTypeId.equals(TypeId.BOOLEAN_ID)) {
throw StandardException.newException(SQLState.LANG_NON_BOOLEAN_WHERE_CLAUSE, whereTypeId.getSQLTypeName());
}
return whereClause;
}
use of org.apache.derby.iapi.types.TypeId in project derby by apache.
the class ValueNodeList method compatible.
/**
* Make sure that passed ValueNode's type is compatible with the non-parameter elements in the ValueNodeList.
*
* @param leftOperand Check for compatibility against this parameter's type
*/
void compatible(ValueNode leftOperand) throws StandardException {
TypeId leftType = leftOperand.getTypeId();
TypeCompiler leftTC = leftOperand.getTypeCompiler();
for (ValueNode valueNode : this) {
if (valueNode.requiresTypeFromContext()) {
continue;
}
/*
** Are the types compatible to each other? If not, throw an exception.
*/
if (!leftTC.compatible(valueNode.getTypeId())) {
throw StandardException.newException(SQLState.LANG_DB2_COALESCE_DATATYPE_MISMATCH, leftType.getSQLTypeName(), valueNode.getTypeId().getSQLTypeName());
}
}
}
use of org.apache.derby.iapi.types.TypeId in project derby by apache.
the class TernaryOperatorNode method locateBind.
/**
* Bind locate operator
* The variable receiver is the string which will searched
* The variable leftOperand is the search character that will looked in the
* receiver variable.
*
* @return The new top of the expression tree.
*
* @exception StandardException Thrown on error
*/
ValueNode locateBind() throws StandardException {
TypeId firstOperandType, secondOperandType, offsetType;
/*
* Is there a ? parameter for the first arg. Copy the
* left/firstOperand's. If the left/firstOperand are both parameters,
* both will be max length.
*/
if (receiver.requiresTypeFromContext()) {
if (leftOperand.requiresTypeFromContext()) {
receiver.setType(getVarcharDescriptor());
// Since both receiver and leftOperands are parameters, use the
// collation of compilation schema for receiver.
receiver.setCollationUsingCompilationSchema();
} else {
if (leftOperand.getTypeId().isStringTypeId()) {
// Since the leftOperand is not a parameter, receiver will
// get it's collation from leftOperand through following
// setType method
receiver.setType(leftOperand.getTypeServices());
}
}
}
/*
* Is there a ? parameter for the second arg. Copy the receiver's.
* If the receiver are both parameters, both will be max length.
*/
if (leftOperand.requiresTypeFromContext()) {
if (receiver.requiresTypeFromContext()) {
leftOperand.setType(getVarcharDescriptor());
} else {
if (receiver.getTypeId().isStringTypeId()) {
leftOperand.setType(receiver.getTypeServices());
}
}
// collation of ? operand should be picked up from the context.
// By the time we come here, receiver will have correct collation
// set on it and hence we can rely on it to get correct collation
// for this ?
leftOperand.setCollationInfo(receiver.getTypeServices());
}
/*
* Is there a ? parameter for the third arg. It will be an int.
*/
if (rightOperand.requiresTypeFromContext()) {
rightOperand.setType(new DataTypeDescriptor(TypeId.INTEGER_ID, true));
}
bindToBuiltIn();
/*
** Check the type of the operand - this function is allowed only
** for: receiver = CHAR
** firstOperand = CHAR
** secondOperand = INT
*/
secondOperandType = leftOperand.getTypeId();
offsetType = rightOperand.getTypeId();
firstOperandType = receiver.getTypeId();
if (!firstOperandType.isStringTypeId() || !secondOperandType.isStringTypeId() || offsetType.getJDBCTypeId() != Types.INTEGER)
throw StandardException.newException(SQLState.LANG_DB2_FUNCTION_INCOMPATIBLE, "LOCATE", "FUNCTION");
/*
** The result type of a LocateFunctionNode is an integer.
*/
setType(new DataTypeDescriptor(TypeId.INTEGER_ID, receiver.getTypeServices().isNullable()));
return this;
}
use of org.apache.derby.iapi.types.TypeId in project derby by apache.
the class AlterTableConstantAction method getRangeBound.
/**
* Get the ran max or min range bound for an autoincrement column.
*
* @param dtd The type of the autoincrement column.
* @param topOrBottom RANGE_TOP or RANGE_BOTTOM
*
* @return the top or bottom of the range
*/
private long getRangeBound(DataTypeDescriptor dtd, int topOrBottom) throws StandardException {
TypeId typeId = dtd.getTypeId();
boolean bottom = (topOrBottom == RANGE_BOTTOM);
if (typeId == TypeId.SMALLINT_ID) {
return (bottom ? Long.valueOf(Short.MIN_VALUE) : Long.valueOf(Short.MAX_VALUE));
} else if (typeId == TypeId.INTEGER_ID) {
return (bottom ? Long.valueOf(Integer.MIN_VALUE) : Long.valueOf(Integer.MAX_VALUE));
} else // must be BIGINT
{
// a new numeric type in the future
if (typeId != TypeId.BIGINT_ID) {
throw StandardException.newException(SQLState.NOT_IMPLEMENTED);
}
return (bottom ? Long.MIN_VALUE : Long.MAX_VALUE);
}
}
Aggregations