protected override void VisitCreateIndexStatement(CreateIndexStatement statement) { State.Write(Symbols.CREATE); if (statement.Unique) { State.Write(Symbols.UNIQUE); } State.Write(Symbols.INDEX); if (statement.CheckIfNotExists) { State.Write(Symbols.IF); State.Write(Symbols.NOT); State.Write(Symbols.EXISTS); } VisitToken(statement.Name); State.Write(Symbols.ON); VisitToken(statement.On); // columns VisitTokenSetInParenthesis(statement.Columns); VisitWhereToken(statement.Where); }
private string BuildKey(CreateIndexStatement index) { var key = new StringBuilder(); if (index.OnName.Count == 1) { key.Append("dbo"); } else { key.Append(index.OnName.SchemaIdentifier.Value.UnQuote().ToLower()); } key.Append(index.OnName.BaseIdentifier.Value.UnQuote().ToLower()); foreach (var i in index.Columns) { key.AppendFormat("%$%{0}", i.Column.MultiPartIdentifier.Identifiers.LastOrDefault().Value.UnQuote().ToLower()); } foreach (var i in index.IncludeColumns) { key.AppendFormat("£&^%%I!{0}", i.MultiPartIdentifier.Identifiers.LastOrDefault().Value.UnQuote().ToLower()); } return(key.ToString()); }
public override void Visit(CreateIndexStatement node) { string indexName = node.Name.Value; var indexClassName = IdentifierName("Index"); FieldDeclarationSyntax indexNameField = FieldDeclaration( VariableDeclaration(indexClassName) .AddVariables( VariableDeclarator(Identifier(indexName)) .WithInitializer( EqualsValueClause( ObjectCreationExpression(indexClassName).AddArgumentListArguments( Argument( LiteralExpression( SyntaxKind.StringLiteralExpression, Literal(indexName)))))))) .AddModifiers(Token(SyntaxKind.InternalKeyword), Token(SyntaxKind.ReadOnlyKeyword)); string tableClassName = GetClassNameForTable(node.OnName.BaseIdentifier.Value); var memberIndex = MembersToAdd.FindIndex(m => m is ClassDeclarationSyntax c && c.Identifier.ValueText == tableClassName); if (memberIndex < 0) { throw new InvalidOperationException($"Index '{node.Name.Value}' is declared on an unrecognized type '{node.OnName.BaseIdentifier.Value}'"); } MembersToAdd[memberIndex] = ((ClassDeclarationSyntax)MembersToAdd[memberIndex]).AddMembers(indexNameField); base.Visit(node); }
public override void ExplicitVisit(CreateIndexStatement index) { if (IsSupportedForCurrentType(index.GetType())) { Name = index.Name; } }
private TSqlFragment GetReplacementCreate(CreateIndexStatement create) { if (_edition == SQLServerEdition.Enterprise) { return(AddOnline(create)); } return(RemoveOnline(create)); }
private TSqlFragment RemoveOnline(CreateIndexStatement create) { var onlineOption = (create.IndexOptions.FirstOrDefault(p => p.OptionKind == IndexOptionKind.Online)) as OnlineIndexOption; if (onlineOption == null) return create; onlineOption.OptionState = OptionState.Off; return create; }
public virtual bool Action(CreateIndexStatement stmt) { AddTablesContext(stmt); FixIdentifier(new DbObject(stmt.Name), ObjectType.OTHER, stmt.Name); FixIdentifiers(stmt.IndexTarget.TableSource.DbObject, ObjectType.TABLE, stmt.IndexTarget.TableSource.DbObject.Identifiers); foreach (OrderedColumn col in stmt.IndexColumns) { FixIdentifier(new DbObject(col.Name), ObjectType.COLUMN, col.Name); } return(false); }
private IfStatement GenerateCreateWithEditionCheck(CreateIndexStatement create) { var ifWrapper = new IfStatement(); ifWrapper.Predicate = GetIsNotNull(); var modifiedCreate = GetModifiedCreate(create); ifWrapper.ThenStatement = WrapInBeginEnd(modifiedCreate); ifWrapper.ElseStatement = WrapInBeginEnd(create); return ifWrapper; }
private TSqlFragment RemoveOnline(CreateIndexStatement create) { var onlineOption = (create.IndexOptions.FirstOrDefault(p => p.OptionKind == IndexOptionKind.Online)) as OnlineIndexOption; if (onlineOption == null) { return(create); } onlineOption.OptionState = OptionState.Off; return(create); }
private CreateIndexStatement GetModifiedCreate(CreateIndexStatement create) { var modifiedCreate = new CreateIndexStatement(); foreach (var c in create.Columns) { modifiedCreate.Columns.Add( new ColumnWithSortOrder { Column = c.Column, SortOrder = c.SortOrder }); } foreach (var c in create.IncludeColumns) { modifiedCreate.IncludeColumns.Add( new ColumnReferenceExpression { ColumnType = c.ColumnType, MultiPartIdentifier = c.MultiPartIdentifier , Collation = c.Collation }); } modifiedCreate.Name = create.Name; modifiedCreate.OnName = create.OnName; modifiedCreate.Clustered = create.Clustered; modifiedCreate.FileStreamOn = create.FileStreamOn; modifiedCreate.FilterPredicate = create.FilterPredicate; modifiedCreate.OnFileGroupOrPartitionScheme = create.OnFileGroupOrPartitionScheme; modifiedCreate.Translated80SyntaxTo90 = create.Translated80SyntaxTo90; modifiedCreate.Unique = create.Unique; foreach (var option in create.IndexOptions) { modifiedCreate.IndexOptions.Add(option); } modifiedCreate.IndexOptions.Add(new OnlineIndexOption { OptionKind = IndexOptionKind.Online, OptionState = OptionState.On }); return(modifiedCreate); }
private IfStatement GenerateCreateWithEditionCheck(CreateIndexStatement create) { var ifWrapper = new IfStatement(); ifWrapper.Predicate = GetIsNotNull(); var modifiedCreate = GetModifiedCreate(create); ifWrapper.ThenStatement = WrapInBeginEnd(modifiedCreate); ifWrapper.ElseStatement = WrapInBeginEnd(create); return(ifWrapper); }
private TSqlFragment AddOnline(CreateIndexStatement create) { var onlineOption = (create.IndexOptions.FirstOrDefault(p => p.OptionKind == IndexOptionKind.Online)) as OnlineIndexOption; if (onlineOption == null) { create.IndexOptions.Add(new OnlineIndexOption { OptionKind = IndexOptionKind.Online, OptionState = OptionState.On }); return(create); } if (onlineOption.OptionState == OptionState.Off || onlineOption.OptionState == OptionState.NotSet) { onlineOption.OptionState = OptionState.On; } return(create); }
private TSqlFragment AddOnline(CreateIndexStatement create) { var onlineOption = (create.IndexOptions.FirstOrDefault(p => p.OptionKind == IndexOptionKind.Online)) as OnlineIndexOption; if (onlineOption == null) { create.IndexOptions.Add(new OnlineIndexOption { OptionKind = IndexOptionKind.Online, OptionState = OptionState.On }); return create; } if (onlineOption.OptionState == OptionState.Off || onlineOption.OptionState == OptionState.NotSet) { onlineOption.OptionState = OptionState.On; } return create; }
protected override void EmitCreateIndexStatement(CreateIndexStatement statement) { Indent(); AppendFormat("{0} ", SQL.Keywords.Create); if (statement.IsUnique) { AppendFormat("{0} ", SQL.Keywords.Unique); } AppendFormat("{0} ", SQL.Keywords.Index); if (statement.IndexSchema != String.Empty) { EmitIdentifier(statement.IndexSchema); Append(SQL.Keywords.Qualifier); } EmitIdentifier(statement.IndexName); AppendFormat(" {0} ", SQL.Keywords.On); if (statement.TableSchema != String.Empty) { EmitIdentifier(statement.TableSchema); Append(SQL.Keywords.Qualifier); } EmitIdentifier(statement.TableName); Append(SQL.Keywords.BeginGroup); for (int index = 0; index < statement.Columns.Count; index++) { if (index > 0) { EmitListSeparator(); } EmitOrderColumnDefinition(statement.Columns[index]); } Append(SQL.Keywords.EndGroup); if ((_product == UDB) && statement.IsClustered) { AppendFormat("{0} ", DB2.Keywords.Cluster); } }
/// <summary> /// Add all options to the list of index options, overriding existing values if present /// </summary> public override void ExplicitVisit(CreateIndexStatement node) { // IndexOptions is not expected to be null, since it can't be overridden if (node.IndexOptions != null) { // Remove existing values if we need to overwrite them List <IndexOption> existingOptions = new List <IndexOption>(node.IndexOptions); foreach (IndexOption option in existingOptions) { IndexOption updatedOption; if (_optionKindToOptionMap.TryGetValue(option.OptionKind, out updatedOption)) { node.IndexOptions.Remove(option); } } // Add the new values foreach (var option in _optionKindToOptionMap.Values) { node.IndexOptions.Add(option); } } }
public CreateIndexStatementCollection BuildStatement() { IDictionary <string, CreateIndexStatement> createIndexStatments = new Dictionary <string, CreateIndexStatement>(); foreach (var edmProperty in entitySet.ElementType.Properties) { var indexAnnotations = edmProperty.MetadataProperties .Select(x => x.Value) .OfType <IndexAnnotation>(); string tableName = NameCreator.EscapeName(entitySet.Table); foreach (var index in indexAnnotations.SelectMany(ia => ia.Indexes)) { CreateIndexStatement createIndexStatement; string indexName = GetIndexName(index, edmProperty); if (!createIndexStatments.TryGetValue(indexName, out createIndexStatement)) { createIndexStatement = new CreateIndexStatement { IsUnique = index.IsUnique, Name = indexName, Table = tableName, Columns = new Collection <CreateIndexStatement.IndexColumn>() }; createIndexStatments.Add(indexName, createIndexStatement); } createIndexStatement.Columns.Add(new CreateIndexStatement.IndexColumn { Name = edmProperty.Name, Order = index.Order }); } } return(new CreateIndexStatementCollection(createIndexStatments.Values)); }
public override void Visit(CreateIndexStatement node) { Statements.Add(node); }
protected override void VisitCreateIndexStatement(CreateIndexStatement statement) { this.CreateIndex(statement); }
private CreateIndexStatement GetModifiedCreate(CreateIndexStatement create) { var modifiedCreate = new CreateIndexStatement(); foreach (var c in create.Columns) { modifiedCreate.Columns.Add( new ColumnWithSortOrder { Column = c.Column, SortOrder = c.SortOrder }); } foreach (var c in create.IncludeColumns) { modifiedCreate.IncludeColumns.Add( new ColumnReferenceExpression { ColumnType = c.ColumnType, MultiPartIdentifier = c.MultiPartIdentifier , Collation = c.Collation }); } modifiedCreate.Name = create.Name; modifiedCreate.OnName = create.OnName; modifiedCreate.Clustered = create.Clustered; modifiedCreate.FileStreamOn = create.FileStreamOn; modifiedCreate.FilterPredicate = create.FilterPredicate; modifiedCreate.OnFileGroupOrPartitionScheme = create.OnFileGroupOrPartitionScheme; modifiedCreate.Translated80SyntaxTo90 = create.Translated80SyntaxTo90; modifiedCreate.Unique = create.Unique; foreach (var option in create.IndexOptions) { modifiedCreate.IndexOptions.Add(option); } modifiedCreate.IndexOptions.Add(new OnlineIndexOption { OptionKind = IndexOptionKind.Online, OptionState = OptionState.On }); return modifiedCreate; }
public override void ExplicitVisit(CreateIndexStatement node) { IsIndex = true; }
protected override void VisitCreateIndexStatement(CreateIndexStatement statement) { }
private TSqlFragment GetReplacementCreate(CreateIndexStatement create) { if (_edition == SQLServerEdition.Enterprise) return AddOnline(create); return RemoveOnline(create); }
public override void Visit(CreateIndexStatement node) { this.action(node); }
private IList <DbObjectTableSource> GetAvailTables(GrammarNode node) { IList <DbObjectTableSource> ret = new List <DbObjectTableSource>(); if (node is UpdateStatement) { UpdateStatement upd = (UpdateStatement)node; dynamic ts = upd.TableSource; AddAvailTable(ts, ret); AddAvailTables(upd.FromClause, ret); } if (node is DeleteStatement) { dynamic ts = ((DeleteStatement)node).Table; AddAvailTable(ts, ret); } if (node is InsertStatement) { InsertStatement insert = (InsertStatement)node; if (insert.InsertTarget is DbObjectInsertTarget) { AddAvailTable(((DbObjectInsertTarget)insert.InsertTarget).TableSource, ret); } } if (node is CreateIndexStatement) { CreateIndexStatement stmt = (CreateIndexStatement)node; if (stmt.IndexTarget is DbObjectIndexTarget) { AddAvailTable(stmt.IndexTarget.TableSource, ret); } } if (node is DropIndexStatement) { DropIndexStatement stmt = (DropIndexStatement)node; foreach (DropIndexAction action in stmt.Actions) { if (action.TableSource != null) { AddAvailTable(action.TableSource, ret); } } } if (node is AlterIndexStatement) { AlterIndexStatement stmt = (AlterIndexStatement)node; if (stmt.TableSource != null) { // It will be removed in Modifier, so probably useless code AddAvailTable(stmt.TableSource, ret); } } if (node is AlterTableStatement) { AlterTableStatement stmt = (AlterTableStatement)node; if (stmt.TableSource != null) { AddAvailTable(stmt.TableSource, ret); } } if (node is DropTableStatement) { DropTableStatement stmt = (DropTableStatement)node; foreach (DbObjectTableSource tableSource in stmt.TableSources) { if (tableSource != null) { AddAvailTable(tableSource, ret); } } } TrimTables(ref ret); return((ret.Count == 0) ? null : ret); }
public virtual bool PostAction(CreateIndexStatement stmt) { RemoveTablesContext(stmt); return(false); }
/// <summary> /// Add all options to the list of index options, overriding existing values if present /// </summary> public override void ExplicitVisit(CreateIndexStatement node) { IndexExplicitVisit(node); }
public override void ExplicitVisit(CreateIndexStatement node) { _called = true; Creates.Add(node); base.ExplicitVisit(node); }
public override void ExplicitVisit(CreateIndexStatement fragment) { _fragments.Add(fragment); }
protected abstract void VisitCreateIndexStatement(CreateIndexStatement statement);
public override void ExplicitVisit(CreateIndexStatement node) { _called = true; Creates.Add(node); base.ExplicitVisit(node); }
private string BuildKey(CreateIndexStatement index) { var key = new StringBuilder(); if (index.OnName.Count == 1) { key.Append("dbo"); } else { key.Append(index.OnName.SchemaIdentifier.Value.UnQuote().ToLower()); } key.Append(index.OnName.BaseIdentifier.Value.UnQuote().ToLower()); foreach (var i in index.Columns) { key.AppendFormat("%$%{0}", i.Column.MultiPartIdentifier.Identifiers.LastOrDefault().Value.UnQuote().ToLower()); } foreach (var i in index.IncludeColumns) { key.AppendFormat("£&^%%I!{0}", i.MultiPartIdentifier.Identifiers.LastOrDefault().Value.UnQuote().ToLower()); } return key.ToString(); }
public override void ExplicitVisit(CreateIndexStatement index) { if (IsSupportedForCurrentType(index.GetType())) { Name = index.Name; } }
protected override object InternalVisit(CreateIndexStatement node) { // INFO(Richo): Do nothing return(null); }
public override void Visit(CreateIndexStatement node) { base.Visit(node); _statements.Add(node); }
/// <summary> /// Add all options to the list of index options, overriding existing values if present /// </summary> public override void ExplicitVisit(CreateIndexStatement node) { IndexExplicitVisit(node); }
/// <summary> /// Add all options to the list of index options, overriding existing values if present /// </summary> public override void ExplicitVisit(CreateIndexStatement node) { // IndexOptions is not expected to be null, since it can't be overridden if (node.IndexOptions != null) { // Remove existing values if we need to overwrite them List<IndexOption> existingOptions = new List<IndexOption>(node.IndexOptions); foreach (IndexOption option in existingOptions) { IndexOption updatedOption; if (_optionKindToOptionMap.TryGetValue(option.OptionKind, out updatedOption)) { node.IndexOptions.Remove(option); } } // Add the new values foreach (var option in _optionKindToOptionMap.Values) { node.IndexOptions.Add(option); } } }