コード例 #1
0
        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, List <ColumnDefinition> oldColumnDefinitions = null)
        {
            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 columnsToInsert = string.Join(", ", tableDefinition.Columns.Select(c => quoter.QuoteColumnName(c.Name)));
            var columnsToFetch  = string.Join(", ", (oldColumnDefinitions ?? tableDefinition.Columns).Select(c => quoter.QuoteColumnName(c.Name)));


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

            Process(string.Format("INSERT INTO {0} ({1}) SELECT {2} FROM {3}", quoter.QuoteTableName(tempTableName), columnsToInsert, columnsToFetch, 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
 public override DataSet ReadTableData(string schemaName, string tableName)
 {
     return(Read("select * from {0}", _quoter.QuoteTableName(tableName)));
 }
コード例 #4
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 });
            }
        }