public void checkUserType(TableDescriptor td)
throws StandardException
{
ColumnDescriptor cd;
TypeDescriptor oldType;
DataTypeDescriptor newType = dataTypeServices;
TypeId oldTypeId;
TypeId newTypeId;
if (getNodeType() != C_NodeTypes.MODIFY_COLUMN_TYPE_NODE)
return; // nothing to do if user not changing length
cd = td.getColumnDescriptor(name);
if (cd == null)
{
throw StandardException.newException(
SQLState.LANG_COLUMN_NOT_FOUND_IN_TABLE, name, td.getName());
}
oldType = cd.getType();
oldTypeId = cd.getType().getTypeId();
newTypeId = dataTypeServices.getTypeId();
newType.setNullability(oldType.isNullable());
// can't change types yet.
if (!(oldTypeId.equals(newTypeId)))
{
throw StandardException.newException(
SQLState.LANG_MODIFY_COLUMN_CHANGE_TYPE, name);
}
// can only alter the length of varchar, nvarchar, bitvarying columns
String typeName = dataTypeServices.getTypeName();
if (!(typeName.equals(TypeId.NATIONAL_VARCHAR_NAME)) &&
!(typeName.equals(TypeId.VARCHAR_NAME)) &&
!(typeName.equals(TypeId.VARBIT_NAME)))
{
throw StandardException.newException(
SQLState.LANG_MODIFY_COLUMN_INVALID_TYPE);
}
// cannot decrease the length of a column
if (newType.getMaximumWidth() < oldType.getMaximumWidth())
{
throw StandardException.newException(
SQLState.LANG_MODIFY_COLUMN_INVALID_LENGTH, name);
}
}