Files
sql-utilities/src/Strata.SqlTools.SqlBreakdown/Classes/RawSqlBreakdown.cs
T
Thom LambandClaude Opus 4.7 0f8d505616
SonarQube Analysis / sonarqube (pull_request) Successful in 2m47s
chore(sonar): apply collection-expression syntax across all sites (IDE0028)
Manual sweep of all 42 IDE0028 sites flagged by SonarQube — `dotnet format
analyzers --diagnostics IDE0028` declined to fix these (no .editorconfig
opt-in for `dotnet_style_prefer_collection_expression`), so applied by
hand. The repo already targets `<LangVersion>latest</LangVersion>` on
net8.0, so C# 12 collection expressions are available.

Pattern: `new List<T>()` / `new Dictionary<K,V>()` / `new ArrayList()` /
`new()` -> `[]` for empty; `new List<T> { ... }` -> `[...]` for literal.

24 files touched in src/{EFCore, LinqToSql, Query, Snowflake, SqlBreakdown,
SqlServer}; tests untouched (no IDE0028 sites in test code).

Build clean (35 warnings unchanged from baseline, 0 errors). All tests
remain green.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-26 17:01:30 -05:00

91 lines
2.6 KiB
C#

using System.Collections;
using Strata.SqlTools.SqlBreakdown.Interfaces;
namespace Strata.SqlTools.SqlBreakdown.Classes;
/// <summary>
/// A simple ISqlBreakdown implementation that holds only raw SQL without parsing into clauses.
/// </summary>
/// <remarks>
/// This class is primarily used for batch SQL parsing where raw statements need to be stored
/// without detailed clause breakdown. Actual clause parsing can be performed separately.
/// </remarks>
public class RawSqlBreakdown : ISqlBreakdown
{
/// <summary>
/// Gets or sets the raw SQL statement.
/// </summary>
public string? RawSql { get; set; }
/// <summary>
/// Gets or sets the setup clauses to execute before the main statement.
/// </summary>
public List<string> SetupClauses { get; set; } = [];
/// <summary>
/// Gets a value indicating whether setup clauses are being used.
/// </summary>
public bool IsUsingSetupClause => SetupClauses.Count > 0;
/// <summary>
/// Gets or sets the finish clauses to execute after the main statement.
/// </summary>
public ArrayList FinishClauses { get; set; } = [];
/// <summary>
/// Gets a value indicating whether finish clauses are being used.
/// </summary>
public bool IsUsingFinishClause => FinishClauses.Count > 0;
/// <summary>
/// Gets the complete SQL statement including optional setup and finish clauses.
/// </summary>
/// <param name="includeSetupFinish">Whether to include setup and finish clauses.</param>
/// <returns>The complete SQL statement string.</returns>
public string GetSql(bool includeSetupFinish = true)
{
if (!includeSetupFinish)
{
return RawSql ?? string.Empty;
}
var sql = RawSql ?? string.Empty;
if (IsUsingSetupClause || IsUsingFinishClause)
{
var lines = new List<string>();
if (IsUsingSetupClause)
{
lines.AddRange(SetupClauses);
}
lines.Add(sql);
if (IsUsingFinishClause)
{
lines.AddRange(FinishClauses.Cast<string>());
}
return string.Join(Environment.NewLine, lines);
}
return sql;
}
/// <summary>
/// Creates a deep copy of this breakdown.
/// </summary>
/// <returns>A new RawSqlBreakdown with copied data.</returns>
public object Clone()
{
return new RawSqlBreakdown
{
RawSql = RawSql,
SetupClauses = new List<string>(SetupClauses),
FinishClauses = new ArrayList(FinishClauses)
};
}
}