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