Files
SQLLint/SQLLinter/Infrastructure/Rules/TempTableModificationRule.cs
FrigaT 507c466b5d
All checks were successful
CI / build-test (push) Successful in 35s
Release / pack-and-publish (release) Successful in 34s
Доработаны правила
2025-12-29 01:40:25 +03:00

35 lines
1.2 KiB
C#

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));
}
}
}