Files
SQLLint/SQLLinter/Infrastructure/Rules/InsertValuesInsteadOfSelectRule.cs

27 lines
1009 B
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using Microsoft.SqlServer.TransactSql.ScriptDom;
using SQLLinter.Common;
namespace SQLLinter.Infrastructure.Rules;
public class InsertValuesInsteadOfSelectRule : BaseRuleVisitor
{
public override string Text => "Для вставки константных значений используйте VALUES(...)";
public override void Visit(InsertStatement node)
{
// Проверяем, что источник данных - SELECT
if (node.InsertSpecification.InsertSource is SelectInsertSource selectSource)
{
var query = selectSource.Select as QuerySpecification;
if (query != null)
{
// Если в SELECT нет таблиц (т.е. просто SELECT 1,2,3)
if (query.FromClause == null || query.FromClause.TableReferences.Count == 0)
{
AddViolation(Name, Text, GetLineNumber(node), GetColumnNumber(node));
}
}
}
}
}