protected override void ExecuteStatement(ExecutionContext context)
{
//if (!context.User.CanCreate(DbObjectType.Sequence, SequenceName))
// throw new MissingPrivilegesException(context.Request.UserName(), SequenceName, Privileges.Create);
if (context.DirectAccess.ObjectExists(SequenceName))
throw new StatementException(String.Format("An object named '{0}' already exists.", SequenceName));
if (context.DirectAccess.ObjectExists(DbObjectType.Sequence, SequenceName))
throw new StatementException(String.Format("The sequence '{0}' already exists.", SequenceName));
var startValue = SqlNumber.Zero;
var incrementBy = SqlNumber.One;
var minValue = SqlNumber.Zero;
var maxValue = new SqlNumber(Int64.MaxValue);
var cache = 16;
var cycle = Cycle;
if (StartWith != null)
startValue = (SqlNumber)StartWith.EvaluateToConstant(context.Request, null).AsBigInt().Value;
if (IncrementBy != null)
incrementBy = (SqlNumber)IncrementBy.EvaluateToConstant(context.Request, null).AsBigInt().Value;
if (MinValue != null)
minValue = (SqlNumber)MinValue.EvaluateToConstant(context.Request, null).AsBigInt().Value;
if (MaxValue != null)
maxValue = (SqlNumber)MaxValue.EvaluateToConstant(context.Request, null).AsBigInt().Value;
if (minValue >= maxValue)
throw new InvalidOperationException("The minimum value cannot be more than the maximum.");
if (startValue < minValue ||
startValue >= maxValue)
throw new InvalidOperationException("The start value cannot be out of the mim/max range.");
var seqInfo = new SequenceInfo(SequenceName, startValue, incrementBy, minValue, maxValue, cache, cycle);
context.Request.Access().CreateObject(seqInfo);
}