Esempio n. 1
0
        protected virtual void Generate([NotNull] RestartSequenceOperation operation, [NotNull] IndentedStringBuilder builder)
        {
            Check.NotNull(operation, nameof(operation));
            Check.NotNull(builder, nameof(builder));

            builder.AppendLine(".RestartSequence(");

            using (builder.Indent())
            {
                builder
                .Append("name: ")
                .Append(_code.Literal(operation.Name));

                if (operation.Schema != null)
                {
                    builder
                    .AppendLine(",")
                    .Append("schema: ")
                    .Append(_code.Literal(operation.Schema));
                }
                builder
                .AppendLine(",")
                .Append("with: ")
                .Append(_code.Literal(operation.RestartWith))
                .Append(")");

                Annotations(operation.Annotations, builder);
            }
        }
 protected override void Generate(RestartSequenceOperation operation, IModel model, MigrationCommandListBuilder builder)
 {
     builder.Append("ALTER SEQUENCE ");
     builder.Append(Dependencies.SqlGenerationHelper.DelimitIdentifier(operation.Name, operation.Schema));
     builder.Append(" START WITH ");
     builder.Append(operation.StartValue.ToString(CultureInfo.InvariantCulture));
     TerminateStatement(builder);
 }
    public async Task RestartSequence()
    {
        var operation = new RestartSequenceOperation()
        {
            Name       = "MySequence",
            StartValue = 23,
        };
        var batch = await Generate(new[] { operation });

        Assert.AreEqual(1, batch.Count());
        Assert.AreEqual(NewLineEnd(@"ALTER SEQUENCE ""MySequence"" START WITH 23;"), batch[0].CommandText);
    }
Esempio n. 4
0
        public virtual void Generate(
            [NotNull] RestartSequenceOperation operation,
            [CanBeNull] IModel model,
            [NotNull] SqlBatchBuilder builder)
        {
            Check.NotNull(operation, nameof(operation));
            Check.NotNull(builder, nameof(builder));

            builder
            .Append("ALTER SEQUENCE ")
            .Append(_sql.DelimitIdentifier(operation.Name, operation.Schema))
            .Append(" RESTART WITH ")
            .Append(_sql.GenerateLiteral(operation.RestartWith));
        }
Esempio n. 5
0
        protected virtual void Generate(
            [NotNull] RestartSequenceOperation operation,
            [CanBeNull] IModel model,
            [NotNull] RelationalCommandListBuilder builder)
        {
            Check.NotNull(operation, nameof(operation));
            Check.NotNull(builder, nameof(builder));

            builder
            .Append("ALTER SEQUENCE ")
            .Append(SqlGenerator.DelimitIdentifier(operation.Name, operation.Schema))
            .Append(" RESTART WITH ")
            .Append(SqlGenerator.GenerateLiteral(operation.StartValue));
        }
Esempio n. 6
0
        public virtual OperationBuilder <RestartSequenceOperation> RestartSequence(string name, long startValue = 1L, string schema = null)
        {
            Check.NotEmpty(name, nameof(name));

            var operation = new RestartSequenceOperation
            {
                Name       = name,
                Schema     = schema,
                StartValue = startValue
            };

            Operations.Add(operation);

            return(new OperationBuilder <RestartSequenceOperation>(operation));
        }
        /// <summary>
        /// 重新计算序列号。
        /// </summary>
        /// <param name="operation">操作实例。</param>
        /// <param name="builder"><see cref="MigrationCommandListBuilder"/>实例对象。</param>
        protected virtual void Generate(
            [NotNull] RestartSequenceOperation operation,
            [NotNull] MigrationCommandListBuilder builder)
        {
            Check.NotNull(operation, nameof(operation));
            Check.NotNull(builder, nameof(builder));

            builder
            .Append("ALTER SEQUENCE ")
            .Append(SqlHelper.DelimitIdentifier(operation.Name, operation.Schema))
            .Append(" RESTART WITH ")
            .Append(SqlHelper.EscapeLiteral(operation.StartValue))
            .AppendLine(SqlHelper.StatementTerminator);

            EndStatement(builder);
        }
Esempio n. 8
0
        /// <summary>
        ///     Builds commands for the given <see cref="RestartSequenceOperation" /> by making calls on the given
        ///     <see cref="MigrationCommandListBuilder" />, and then terminates the final command.
        /// </summary>
        /// <param name="operation"> The operation. </param>
        /// <param name="model"> The target model which may be <c>null</c> if the operations exist without a model. </param>
        /// <param name="builder"> The command builder to use to build the commands. </param>
        protected override void Generate(
            RestartSequenceOperation operation,
            IModel model,
            MigrationCommandListBuilder builder)
        {
            Check.NotNull(operation, nameof(operation));
            Check.NotNull(builder, nameof(builder));

            builder
            .Append("ALTER SEQUENCE ")
            .Append(Dependencies.SqlGenerationHelper.DelimitIdentifier(operation.Name, operation.Schema))
            .Append(" RESTART WITH ")
            .Append(IntegerConstant(operation.StartValue))
            .AppendLine(Dependencies.SqlGenerationHelper.StatementTerminator);

            EndStatement(builder);
        }
Esempio n. 9
0
        public virtual OperationBuilder <RestartSequenceOperation> RestartSequence(
            [NotNull] string name,
            long with,
            [CanBeNull] string schema = null)
        {
            Check.NotEmpty(name, nameof(name));

            var operation = new RestartSequenceOperation
            {
                Name        = name,
                Schema      = schema,
                RestartWith = with
            };

            Operations.Add(operation);

            return(new OperationBuilder <RestartSequenceOperation>(operation));
        }
        protected virtual void Generate(
            [NotNull] RestartSequenceOperation operation,
            [CanBeNull] IModel model,
            [NotNull] MigrationCommandListBuilder builder)
        {
            Check.NotNull(operation, nameof(operation));
            Check.NotNull(builder, nameof(builder));

            var longTypeMapping = Dependencies.TypeMapper.GetMapping(typeof(long));

            builder
            .Append("ALTER SEQUENCE ")
            .Append(Dependencies.SqlGenerationHelper.DelimitIdentifier(operation.Name, operation.Schema))
            .Append(" RESTART WITH ")
            .Append(longTypeMapping.GenerateSqlLiteral(operation.StartValue))
            .AppendLine(Dependencies.SqlGenerationHelper.StatementTerminator);

            EndStatement(builder);
        }
Esempio n. 11
0
 // SQLite does not have sequences
 protected override void Generate(RestartSequenceOperation operation, IModel model, MigrationCommandListBuilder builder)
 {
     throw new NotSupportedException(SqliteStrings.SequencesNotSupported);
 }
Esempio n. 12
0
 // JET does not have sequences
 protected override void Generate(RestartSequenceOperation operation, IModel model, MigrationCommandListBuilder builder)
 {
     throw new NotSupportedException("JET does not support sequences");
 }
Esempio n. 13
0
 protected override void Generate(RestartSequenceOperation operation, IModel model, MigrationCommandListBuilder builder)
 {
     throw new NotSupportedException(string.Format(NotSupported, operation.GetType().Name));
 }
 // SQLite does not have sequences
 protected override void Generate(RestartSequenceOperation operation, IModel model, SqlBatchBuilder builder)
 {
     throw new NotSupportedException(Strings.SequencesNotSupported);
 }
 protected override void Generate(RestartSequenceOperation operation, IModel model, RelationalCommandListBuilder builder)
 {
     throw new NotSupportedException("SQL Server Compact does not support sequences.");
 }