private void Append(string tableName, Index index) { string unique = index.Unique ? "UNIQUE" : ""; string clustered = index.Clustered ? "CLUSTERED" : "NONCLUSTERED"; string dropExisting = index.DropExisting ? "DROP_EXISTING = ON" : "DROP_EXISTING = OFF"; string ignoreDupKey = index.IgnoreDupKey ? "IGNORE_DUP_KEY = ON" : "IGNORE_DUP_KEY = OFF"; string online = index.Online ? "ONLINE = ON" : "ONLINE = OFF"; string padIndex = index.Online ? "PAD_INDEX = ON" : "PAD_INDEX = OFF"; string sortInTempdb = index.SortInTempdb ? "SORT_IN_TEMPDB = ON" : "SORT_IN_TEMPDB = OFF"; string sProperties = string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0},\n{1},\n{2},\n{3},\n{4}", padIndex, sortInTempdb, dropExisting, ignoreDupKey, online); string kName; string keys = new KeysBuilder(index.Keys).Build(index.Name, out kName); TemplatePlatformEmitter te = new TemplatePlatformEmitter("CreateIndex", unique, clustered, kName, tableName, keys, sProperties, string.Empty); _stringBuilder.Append(te.Emit(index)); _stringBuilder.Append(NEWLINE); }
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); } }