Добавьте файлы проекта.
This commit is contained in:
47
SQLLinter/Infrastructure/Rules/NamedConstraintRule.cs
Normal file
47
SQLLinter/Infrastructure/Rules/NamedConstraintRule.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using Microsoft.SqlServer.TransactSql.ScriptDom;
|
||||
using SQLLinter.Common;
|
||||
using SQLLinter.Common.Helpers;
|
||||
|
||||
namespace SQLLinter.Infrastructure.Rules;
|
||||
|
||||
public class NamedConstraintRule : BaseRuleVisitor, IRule
|
||||
{
|
||||
|
||||
public override string Text => "Именованные ограничения во временных таблицах могут вызывать коллизии при параллельном запуске: {0}";
|
||||
|
||||
public override void Visit(CreateTableStatement node)
|
||||
{
|
||||
// применять правило только к временным таблицам
|
||||
if (!node.SchemaObjectName.BaseIdentifier.Value.Contains("#"))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var constraintVisitor = new ConstraintVisitor();
|
||||
node.AcceptChildren(constraintVisitor);
|
||||
|
||||
if (constraintVisitor.NamedConstraintExists)
|
||||
{
|
||||
AddViolation(node, SQLHelpers.ObjectGetFullName(node.SchemaObjectName));
|
||||
}
|
||||
}
|
||||
|
||||
private class ConstraintVisitor : TSqlFragmentVisitor
|
||||
{
|
||||
public bool NamedConstraintExists
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public override void Visit(ConstraintDefinition node)
|
||||
{
|
||||
if (NamedConstraintExists)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
NamedConstraintExists = node.ConstraintIdentifier != null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user