using Microsoft.SqlServer.TransactSql.ScriptDom; using SQLLinter.Common; using SQLLinter.Common.Helpers; namespace SQLLinter.Infrastructure.Rules; public class TempTableModificationRule : BaseRuleVisitor { public override string Text => "Избегать ALTER/UPDATE/DELETE для временных таблиц: {0}"; public override void Visit(UpdateStatement node) { if (node.UpdateSpecification.Target is NamedTableReference tbl && tbl.SchemaObject.BaseIdentifier.Value.StartsWith("#")) { AddViolation(node.UpdateSpecification.Target, SQLHelpers.ObjectGetFullName(tbl.SchemaObject)); } } public override void Visit(DeleteStatement node) { if (node.DeleteSpecification.Target is NamedTableReference tbl && tbl.SchemaObject.BaseIdentifier.Value.StartsWith("#")) { AddViolation(node.DeleteSpecification.Target, SQLHelpers.ObjectGetFullName(tbl.SchemaObject)); } } public override void Visit(AlterTableStatement node) { if (node.SchemaObjectName.BaseIdentifier.Value.StartsWith("#")) { AddViolation(node.SchemaObjectName, SQLHelpers.ObjectGetFullName(node.SchemaObjectName)); } } }