}
//Judged as default value is constant value.
CompilerContext cc = getCompilerContext();
ValueNode defaultTree = defaultNode.getDefaultTree();
/* bind the default.
* Verify that it does not contain any ColumnReferences or subqueries
* and that it is type compatable with the column.
*/
final int previousReliability = cc.getReliability();
try
{
/*
Defaults cannot have dependencies as they
should just be constants. Code used to exist
to handle dependencies in defaults, now this
is under sanity to ensure no dependencies exist.
*/
ProviderList apl = null;
ProviderList prevAPL = null;
if (SanityManager.DEBUG) {
apl = new ProviderList();
prevAPL = cc.getCurrentAuxiliaryProviderList();
cc.setCurrentAuxiliaryProviderList(apl);
}
// Tell the compiler context to only allow deterministic nodes
cc.setReliability( CompilerContext.DEFAULT_RESTRICTION );
defaultTree = defaultTree.bindExpression(
(FromList) getNodeFactory().getNode(
C_NodeTypes.FROM_LIST,
getNodeFactory().doJoinOrderOptimization(),
getContextManager()),
(SubqueryList) null,
(Vector) null);
TypeId columnTypeId = (TypeId) dataTypeServices.getTypeId();
TypeId defaultTypeId = defaultTree.getTypeId();
// Check for 'invalid default' errors (42894)
// before checking for 'not storable' errors (42821).
if (!defaultTypeIsValid(columnTypeId, dataTypeServices,
defaultTypeId, defaultTree, defaultNode.getDefaultText()))
{
throw StandardException.newException(
SQLState.LANG_DB2_INVALID_DEFAULT_VALUE,
this.name);
}
// Now check 'not storable' errors.
if (! getTypeCompiler(columnTypeId).
storable(defaultTypeId, getClassFactory()))
{
throw StandardException.newException(SQLState.LANG_NOT_STORABLE,
columnTypeId.getSQLTypeName(),
defaultTypeId.getSQLTypeName() );
}
// Save off the default text
// RESOLVEDEFAULT - Convert to constant if possible
defaultInfo = new DefaultInfoImpl(false,
defaultNode.getDefaultText(),
defaultValue);
if (SanityManager.DEBUG)
{
/* Save the APL off in the constraint node */
if (apl.size() > 0)
{
SanityManager.THROWASSERT("DEFAULT clause has unexpected dependencies");
}
// Restore the previous AuxiliaryProviderList
cc.setCurrentAuxiliaryProviderList(prevAPL);
}
}
finally
{
cc.setReliability(previousReliability);
}
}