Files
SQLLint/SQLLinter/Infrastructure/Rules/NestedSubqueryDepthRule.cs
FrigaT 9abf8daf90
All checks were successful
CI / build-test (push) Successful in 38s
Release / pack-and-publish (release) Successful in 40s
Исправлена проверка с глубиной подзапросов
2025-12-08 17:35:33 +03:00

37 lines
986 B
C#

using Microsoft.SqlServer.TransactSql.ScriptDom;
using SQLLinter.Common;
namespace SQLLinter.Infrastructure.Rules;
public class NestedSubqueryDepthRule : BaseRuleVisitor
{
public override string Text => "Слишком глубокие подзапросы (>" + _maxDepth + " уровней): {0}";
private int _depth = 0;
private const int _maxDepth = 3;
public override void Visit(QueryDerivedTable node)
{
_depth++;
if (_depth > _maxDepth)
{
AddViolation(node, $"Глубина подзапроса {_depth}");
}
node.QueryExpression.Accept(this);
_depth--;
base.Visit(node);
}
public override void Visit(ScalarSubquery node)
{
_depth++;
if (_depth > _maxDepth)
{
AddViolation(node, $"Глубина подзапроса {_depth}");
}
node.QueryExpression.Accept(this);
_depth--;
base.Visit(node);
}
}