Beispiel #1
0
        public void Modify(SqlProject project)
        {
            foreach (var batch in project.Objects.Batches.ToList())
            {
                foreach (var statement in batch.Statements.OfType <CreateTableStatement>())
                {
                    var constrains = statement.Definition.TableConstraints;

                    if (constrains.Count == 0)
                    {
                        continue;
                    }

                    var alterTable =
                        new AlterTableAddTableElementStatement
                    {
                        SchemaObjectName = statement.SchemaObjectName,
                        Definition       = new TableDefinition()
                    };

                    foreach (var constraint in constrains)
                    {
                        alterTable.Definition.TableConstraints.Add(constraint);
                    }

                    project.Objects.Batches.Add(new TSqlBatch
                    {
                        Statements = { alterTable }
                    });

                    statement.Definition.TableConstraints.Clear();
                }
            }
        }
Beispiel #2
0
        public override void Visit(AlterTableAddTableElementStatement node)
        {
            sw.WriteLine("<AlterTableAddTableElementStatement>");
            node.AcceptChildren(this);

            sw.WriteLine("</AlterTableAddTableElementStatement>");
        }
        public override void ExplicitVisit(AlterTableAddTableElementStatement node)
        {
            _buffer.Append("alter table ");
            node.SchemaObjectName.Accept(new PgExpressionVisitor(_buffer));
            string  tableName = GetTableName(node.SchemaObjectName);
            PgTable table     = _database.Tables[tableName];

            _buffer.AppendLine();
            foreach (ConstraintDefinition constraint in node.Definition.TableConstraints)
            {
                if (constraint is ForeignKeyConstraintDefinition || constraint is CheckConstraintDefinition)
                {
                    _buffer.Append("\tadd constraint ");
                }
                constraint.Accept(new PgExpressionVisitor(_buffer, table));
            }
            _buffer.AppendLine(";");
            _buffer.AppendLine();
        }
Beispiel #4
0
 public override void Visit(AlterTableAddTableElementStatement node) { this.action(node); }
 public override void Visit(AlterTableAddTableElementStatement node)
 {
     AlterTableAddTableElementStatements.Add(node);
 }
 public override void ExplicitVisit(AlterTableAddTableElementStatement fragment)
 {
     _fragments.Add(fragment);
 }