public override void CanRenameColumnWithCustomSchema()
        {
            var expression = GeneratorTestHelper.GetRenameColumnExpression();

            expression.SchemaName = "TestSchema";

            var result = Generator.Generate(expression);

            result.ShouldBe($"ALTER TABLE {quoter.QuoteTableName("TestSchema")}.{quoter.QuoteTableName("TestTable1")} "
                            + $"RENAME COLUMN {quoter.QuoteColumnName("TestColumn1")} TO {quoter.QuoteColumnName("TestColumn2")}");
        }
Пример #2
0
        protected virtual void ProcessAlterTable(TableDefinition tableDefinition)
        {
            var tableName     = tableDefinition.Name;
            var tempTableName = tableName + "_temp";

            var uid = 0;

            while (TableExists(null, tempTableName))
            {
                tempTableName = tableName + "_temp" + uid++;
            }

            // What is the cleanest way to do this? Add function to Generator?
            var quoter            = new SQLiteQuoter();
            var columnsToTransfer = string.Join(", ", tableDefinition.Columns.Select(c => quoter.QuoteColumnName(c.Name)));

            Process(new CreateTableExpression()
            {
                TableName = tempTableName, Columns = tableDefinition.Columns.ToList()
            });

            Process(string.Format("INSERT INTO {0} SELECT {1} FROM {2}", quoter.QuoteTableName(tempTableName), columnsToTransfer, quoter.QuoteTableName(tableName)));

            Process(new DeleteTableExpression()
            {
                TableName = tableName
            });

            Process(new RenameTableExpression()
            {
                OldName = tempTableName, NewName = tableName
            });

            foreach (var index in tableDefinition.Indexes)
            {
                Process(new CreateIndexExpression()
                {
                    Index = index
                });
            }
        }
Пример #3
0
        protected virtual void ProcessAlterTable(TableDefinition tableDefinition)
        {
            var tableName = tableDefinition.Name;
            var tempTableName = tableName + "_temp";

            var uid = 0;
            while (TableExists(null, tempTableName))
            {
                tempTableName = tableName + "_temp" + uid++;
            }

            // What is the cleanest way to do this? Add function to Generator?
            var quoter = new SQLiteQuoter();
            var columnsToTransfer = string.Join(", ", tableDefinition.Columns.Select(c => quoter.QuoteColumnName(c.Name)));

            Process(new CreateTableExpression() { TableName = tempTableName, Columns = tableDefinition.Columns.ToList() });

            Process(string.Format("INSERT INTO {0} SELECT {1} FROM {2}", quoter.QuoteTableName(tempTableName), columnsToTransfer, quoter.QuoteTableName(tableName)));

            Process(new DeleteTableExpression() { TableName = tableName });

            Process(new RenameTableExpression() { OldName = tempTableName, NewName = tableName });

            foreach (var index in tableDefinition.Indexes)
            {
                Process(new CreateIndexExpression() { Index = index });
            }
        }