35 lines
1.1 KiB
C#
35 lines
1.1 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, SQLHelpers.ObjectGetFullName(tbl.SchemaObject));
|
|
}
|
|
}
|
|
|
|
public override void Visit(DeleteStatement node)
|
|
{
|
|
if (node.DeleteSpecification.Target is NamedTableReference tbl && tbl.SchemaObject.BaseIdentifier.Value.StartsWith("#"))
|
|
{
|
|
AddViolation(node, SQLHelpers.ObjectGetFullName(tbl.SchemaObject));
|
|
}
|
|
}
|
|
|
|
public override void Visit(AlterTableStatement node)
|
|
{
|
|
if (node.SchemaObjectName.BaseIdentifier.Value.StartsWith("#"))
|
|
{
|
|
AddViolation(node, SQLHelpers.ObjectGetFullName(node.SchemaObjectName));
|
|
}
|
|
}
|
|
}
|