public void AddColumn()
        {
            ITableDefinition table = new TableDefinition("Foo");
            IColumnDefinition column = new ColumnDefinition("ID");

            table.AddColumn(column);

            Assert.AreSame(column, table.Columns[0]);
            Assert.AreEqual(table.Name, column.Table);
        }
        public void Execute(IDbPlatform platform, IRefactorNode refactorNode, Environment environment)
        {
            string auditTableName = AstNodePropertyUtil.AsString(refactorNode.Properties["audit-table"].Value);
            string tableName = AstNodePropertyUtil.AsString(refactorNode.Properties["table"].Value);
            //
            // We only need columns here
            ITableDefinition tableDefinition = environment.Schema.GetTable(tableName);

            ITableDefinition auditTable = new TableDefinition(auditTableName);
            foreach(ColumnDefinition column in tableDefinition.Columns)
            {
                //
                // Keep name and type only.
                IColumnDefinition auditColumn = new ColumnDefinition(column.Name);
                
                //
                // Special handling for rowversion
                if(column.Type == DbType.Time)
                {
                    auditColumn.Length = 8;
                    auditColumn.Type = DbType.Binary;
                } // if
                else
                {
                    auditColumn.Length = column.Length;
                    auditColumn.Type = column.Type;
                } // else

                auditColumn.Nullable = true;

                auditTable.AddColumn(auditColumn);
            } // foreach

            environment.Schema.AddTable(auditTable);

            //
            // Now build an AST
            IAddTableNode addAuditTableNode = new AddTableNode(refactorNode.Parent, auditTableName);
            foreach(IColumnDefinition auditColumn in auditTable.Columns)
            {
                IAddColumnNode addAuditColumnNode = new AddColumnNode(addAuditTableNode, auditColumn.Name);
                addAuditColumnNode.Type = auditColumn.Type;
                addAuditColumnNode.Length = auditColumn.Length;
                addAuditColumnNode.Nullable = auditColumn.Nullable;

                addAuditTableNode.ChildNodes.Add(addAuditColumnNode);
            } // foreach

            addAuditTableNode.Parent.ChildNodes.Add(addAuditTableNode);
        }
        public void CopyColumnProperties()
        {
            IColumnDefinition columnDefinition = new ColumnDefinition("Foo", null, DbType.Binary, true, 234, 56, 78, true, true);
            
            IColumnNode columnNode = new AddColumnNode(null, "Foo");
            AstUtil.CopyProperties(columnDefinition, columnNode);

            Assert.AreEqual("true", AstNodePropertyUtil.AsString(columnNode.Properties[MdlSyntax.Identity].Value));
            Assert.AreEqual(234, AstNodePropertyUtil.AsInteger(columnNode.Properties[MdlSyntax.Length].Value));
            Assert.AreEqual("true", AstNodePropertyUtil.AsString(columnNode.Properties[MdlSyntax.Nullable].Value));
            Assert.AreEqual(78, AstNodePropertyUtil.AsInteger(columnNode.Properties[MdlSyntax.Precision].Value));
            Assert.AreEqual("true", AstNodePropertyUtil.AsString(columnNode.Properties[MdlSyntax.PrimaryKey].Value));
            Assert.AreEqual(56, AstNodePropertyUtil.AsInteger(columnNode.Properties[MdlSyntax.Scale].Value));
            Assert.AreEqual("Binary", AstNodePropertyUtil.AsString(columnNode.Properties[MdlSyntax.Type].Value));
        }
        private ColumnDefinition BindAddColumn(IAddColumnNode addColumnNode)
        {
            ColumnDefinition column = new ColumnDefinition(addColumnNode.Name);
            BindColumnProperties(addColumnNode, column);

            return column;
        }