return;
}
// Variably sized types need to fit within the target width.
if (neededType == VoltType.VARBINARY) {
if ( ! Encoder.isHexEncodedString(getValue())) {
throw new PlanningErrorException("Value (" + getValue() +
") has an invalid format for a constant " +
neededType.toSQLString() + " value");
}
size_unit = 2;
}
else {
assert neededType == VoltType.STRING;
}
if (getValue().length() > size_unit*neededSize ) {
throw new PlanningErrorException("Value (" + getValue() +
") is too wide for a constant " +
neededType.toSQLString() +
" value of size " + neededSize);
}
setValueSize(neededSize);
return;
}
if (m_isNull) {
setValueType(neededType);
setValueSize(neededSize);
return;
}
// Constant's apparent type may not exactly match the target type needed.
if (neededType == VoltType.VARBINARY &&
(m_valueType == VoltType.STRING || m_valueType == null)) {
if ( ! Encoder.isHexEncodedString(getValue())) {
throw new PlanningErrorException("Value (" + getValue() +
") has an invalid format for a constant " +
neededType.toSQLString() + " value");
}
size_unit = 2;
if (getValue().length() > size_unit*neededSize ) {
throw new PlanningErrorException("Value (" + getValue() +
") is too wide for a constant " +
neededType.toSQLString() +
" value of size " + neededSize);
}
setValueType(neededType);
setValueSize(neededSize);
return;
}
if (neededType == VoltType.STRING && m_valueType == null) {
if (getValue().length() > size_unit*neededSize ) {
throw new PlanningErrorException("Value (" + getValue() +
") is too wide for a constant " +
neededType.toSQLString() +
" value of size " + neededSize);
}
setValueType(neededType);
setValueSize(neededSize);
return;
}
if (neededType == VoltType.TIMESTAMP) {
if (m_valueType == VoltType.STRING) {
try {
// Convert date value in whatever format is supported by TimeStampType
// into VoltDB native microsecond count.
TimestampType ts = new TimestampType(m_value);
m_value = String.valueOf(ts.getTime());
}
// It couldn't be converted to timestamp.
catch (IllegalArgumentException e) {
throw new PlanningErrorException("Value (" + getValue() +
") has an invalid format for a constant " +
neededType.toSQLString() + " value");
}
setValueType(neededType);
setValueSize(neededSize);
return;
}
}
if ((neededType == VoltType.FLOAT) || (neededType == VoltType.DECIMAL)) {
if (m_valueType == null ||
(m_valueType != VoltType.NUMERIC && ! m_valueType.isExactNumeric())) {
try {
Double.parseDouble(getValue());
} catch (NumberFormatException nfe) {
throw new PlanningErrorException("Value (" + getValue() +
") has an invalid format for a constant " +
neededType.toSQLString() + " value");
}
}
setValueType(neededType);
setValueSize(neededSize);
return;
}
if (neededType.isInteger()) {
long value = 0;
try {
value = Long.parseLong(getValue());
} catch (NumberFormatException nfe) {
throw new PlanningErrorException("Value (" + getValue() +
") has an invalid format for a constant " +
neededType.toSQLString() + " value");
}
checkIntegerValueRange(value, neededType);
m_valueType = neededType;
m_valueSize = neededType.getLengthInBytesForFixedTypes();
return;
}
// That's it for known type conversions.
throw new PlanningErrorException("Value (" + getValue() +
") has an invalid format for a constant " +
neededType.toSQLString() + " value");
}