예제 #1
0
        public string Emit(Table table)
        {
            if (table.DefaultValues == null)
            {
                return string.Empty;
            }

            bool bContainsIdentities;
            string columns = new ColumnsBuilder(table).BuildDefaultValues(out bContainsIdentities);
            StringBuilder str = new StringBuilder();

            if (bContainsIdentities)
            {
                str.AppendFormat("\nSET IDENTITY_INSERT {0} ON\n", table.Name);
            }
            str.Append("\n");
            foreach (DefaultValue val in table.DefaultValues.DefaultValueList)
            {
                str.Append(new TemplatePlatformEmitter("InsertDefaultValues", table.Name, columns, val.Value).Emit(val));
                str.Append("\n");
            }

            if (bContainsIdentities)
            {
                str.AppendFormat("\nSET IDENTITY_INSERT {0} OFF", table.Name);
            }

            str.Append("\n");
            return str.ToString();
        }
예제 #2
0
        public string Emit(Table table)
        {
            string sConstraints = new ConstraintsBuilder(table).BuildConstraints();
            TemplatePlatformEmitter te = new TemplatePlatformEmitter("CreateTable",table.Name,new ColumnsBuilder(table, sConstraints.Length > 0).Build(),sConstraints);

            StringBuilder sTable = new StringBuilder(te.Emit(table));
            sTable.Append(new ConstraintsBuilder(table).BuildForeignKeyConstraints());
            sTable.Append(new IndexesBuilder(table.Indexes).Build());
            sTable.Append(new InsertDefaultValuesEmitter().Emit(table));
            return sTable.ToString();
        }
예제 #3
0
        public SPColumnsBuilder(Columns columns, bool bAppendSeparator) : base(bAppendSeparator)
        {
            foreach (Column column in columns.ColumnList)
            {
                _columns.Add(IsKeyOrIdentityColumn(column));
            }

            if (columns.Parent != null && columns.Parent is Table)
            {
                _table = (Table)columns.Parent;
            }
            else if (columns.Parent == null)
            {
                MessageEngine.Global.Trace(Severity.Error, Resources.ParentIsNull, columns.ToString());
            }
            else
            {
                MessageEngine.Global.Trace(Severity.Error, Resources.ColumnsParentIsNotTable, columns.Parent.Name);
            }
            _identityColumn = null;
            _keyColumn = null;
        }
예제 #4
0
 public ColumnsBuilder(Table table, bool bAppendSeparator) : base(bAppendSeparator)
 {
     _table = table;
 }
예제 #5
0
 public ColumnsBuilder(Table table) : this(table, false) { }
예제 #6
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);
            }
        }
예제 #7
0
 public ConstraintsBuilder(Table table, bool bAppendSeparator) : base(bAppendSeparator)
 {
     _table = table;
 }
예제 #8
0
 public ConstraintsBuilder(Table table) : this(table, false) { }