Пример #1
0
        public bool IsIdentityColumn(Column column)
        {
            IdentityConstraint c = this.ContainsIdentities();

            if (c != null)
            {
                foreach (Key k in c.Keys)
                {
                    if (k.Name.Equals(column.Name, StringComparison.InvariantCultureIgnoreCase))
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Пример #2
0
        public static PhysicalTSQL.Table Lower(this AstTable.AstTableNode astNode)
        {
            if (astNode.AsClassOnly)
            {
                return null;
            }

            try
            {
                PhysicalTSQL.Table table = new Ssis2008Emitter.IR.TSQL.Table();
                table.Name = astNode.Name;
                table.Columns.Parent = table;
                table.Indexes.Parent = table;

                ProcessStaticSources(astNode, table);
                table.ConnectionConfiguration = astNode.Connection != null ? astNode.Connection.Lower() : null;

                foreach (AstTable.AstTableColumnBaseNode columnBase in astNode.Columns)
                {
                    ProcessAstTableColumnBaseNode(table, columnBase);
                }

                // TODO: Strip out UniqueKey if it is identical to keyPhysicalConstraint above
                foreach (AstTable.AstTableKeyBaseNode keyBase in astNode.Keys)
                {
                    PhysicalTSQL.Constraint keyPhysicalConstraint = null;
                    if (keyBase is AstTable.AstTablePrimaryKeyNode)
                    {
                        keyPhysicalConstraint = new Ssis2008Emitter.IR.TSQL.PrimaryKeyConstraint();
                    }
                    else if (keyBase is AstTable.AstTableIdentityNode)
                    {
                        PhysicalTSQL.IdentityConstraint physicalIdentity = new Ssis2008Emitter.IR.TSQL.IdentityConstraint();
                        physicalIdentity.Seed = ((AstTable.AstTableIdentityNode)keyBase).Seed;
                        physicalIdentity.Increment = ((AstTable.AstTableIdentityNode)keyBase).Increment;
                        keyPhysicalConstraint = physicalIdentity;
                    }
                    else
                    {
                        keyPhysicalConstraint = new Ssis2008Emitter.IR.TSQL.Constraint();
                    }

                    if (keyPhysicalConstraint != null)
                    {
                        keyPhysicalConstraint.Clustered = keyBase.Clustered;
                        keyPhysicalConstraint.DropExisting = keyBase.DropExisting;
                        keyPhysicalConstraint.IgnoreDupKey = keyBase.IgnoreDupKey;
                        keyPhysicalConstraint.Name = keyBase.Name;
                        keyPhysicalConstraint.Online = keyBase.Online;
                        keyPhysicalConstraint.PadIndex = keyBase.PadIndex;
                        keyPhysicalConstraint.Parent = table;
                        keyPhysicalConstraint.SortInTempdb = keyBase.SortInTempdb;
                        keyPhysicalConstraint.Unique = keyBase.Unique;
                        foreach (AstTable.AstTableKeyColumnNode key in keyBase.Columns)
                        {
                            PhysicalTSQL.Key physicalKey = new Ssis2008Emitter.IR.TSQL.Key();
                            physicalKey.Name = key.Column.Name;
                            keyPhysicalConstraint.Keys.Add(physicalKey);
                        }
                        table.ConstraintList.Add(keyPhysicalConstraint);
                    }
                }

                foreach (AstTable.AstTableForeignKeyNode foreignKey in astNode.ForeignKeys)
                {
                    PhysicalTSQL.ForeignKeyConstraint physicalForeignKey = new Ssis2008Emitter.IR.TSQL.ForeignKeyConstraint();
                    foreach (AstTable.AstTableForeignKeyColumnNode column in foreignKey.Columns)
                    {
                        PhysicalTSQL.Key localColumn = new Ssis2008Emitter.IR.TSQL.Key();
                        localColumn.Name = column.OutputName;
                        physicalForeignKey.LocalColumnList.Add(localColumn);
                        PhysicalTSQL.Key foreignColumn = new Ssis2008Emitter.IR.TSQL.Key();
                        foreignColumn.Name = column.ColumnName;
                        physicalForeignKey.ForeignColumnList.Add(foreignColumn);
                    }
                    physicalForeignKey.Table = foreignKey.Dimension.Name;
                    physicalForeignKey.Name = foreignKey.Name;
                    table.AddForeignKeyConstraint(physicalForeignKey);
                }

                foreach (AstTable.AstTableIndexNode index in astNode.Indexes)
                {
                    PhysicalTSQL.Index physicalIndex = new Ssis2008Emitter.IR.TSQL.Index();
                    physicalIndex.Clustered = index.Clustered;
                    physicalIndex.DropExisting = index.DropExisting;
                    physicalIndex.IgnoreDupKey = index.IgnoreDupKey;
                    physicalIndex.Name = index.Name;
                    physicalIndex.Online = index.Online;
                    physicalIndex.PadIndex = index.PadIndex;
                    physicalIndex.Parent = table;
                    physicalIndex.SortInTempdb = index.SortInTempdb;
                    physicalIndex.Unique = index.Unique;

                    foreach (AstTable.AstTableIndexColumnNode key in index.Columns)
                    {
                        PhysicalTSQL.Key physicalKey = new Ssis2008Emitter.IR.TSQL.Key();
                        physicalKey.Name = key.Column.Name;
                        physicalIndex.Keys.Add(physicalKey);
                    }
                    foreach (AstTable.AstTableColumnBaseNode leaf in index.Leafs)
                    {
                        PhysicalTSQL.Leaf physicalLeaf = new Ssis2008Emitter.IR.TSQL.Leaf();
                        physicalLeaf.Name = leaf.Name;
                        physicalIndex.Leaves.Add(physicalLeaf);
                    }

                    table.Indexes.IndexList.Add(physicalIndex);
                }
                //TODO: table.Tags;

                return table;
            }
            catch (Exception e)
            {
                throw new SSISEmitterException(astNode, e);
            }
        }