refactor(dedup): second pass at src/ duplication — clear 10 of 13 remaining blocks #21
@@ -36,14 +36,8 @@ public class QueryBreakdown : SqlServerQueryBreakdown
|
||||
public QueryBreakdown(string selectClause, string fromClause, bool isMicrosoftSql = false) : base()
|
||||
{
|
||||
var parser = isMicrosoftSql ? Parser : PostgreSqlParserInstance;
|
||||
|
||||
var cleanSelect = parser.ExtractSqlComments(selectClause, out var selectComments);
|
||||
SelectClause.Clause = cleanSelect.Trim();
|
||||
SelectClause.Comment = selectComments.Count > 0 ? string.Join(" ", selectComments) : null;
|
||||
|
||||
var cleanFrom = parser.ExtractSqlComments(fromClause, out var fromComments);
|
||||
FromClause.Clause = cleanFrom.Trim();
|
||||
FromClause.Comment = fromComments.Count > 0 ? string.Join(" ", fromComments) : null;
|
||||
parser.PopulateClauseWithComments(selectClause, SelectClause);
|
||||
parser.PopulateClauseWithComments(fromClause, FromClause);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -39,14 +39,8 @@ public class QueryBreakdown : SqlServerQueryBreakdown
|
||||
public QueryBreakdown(string selectClause, string fromClause, bool isMicrosoftSql = false) : base()
|
||||
{
|
||||
var parser = isMicrosoftSql ? Parser : SnowflakeParserInstance;
|
||||
|
||||
var cleanSelect = parser.ExtractSqlComments(selectClause, out var selectComments);
|
||||
SelectClause.Clause = cleanSelect.Trim();
|
||||
SelectClause.Comment = selectComments.Count > 0 ? string.Join(" ", selectComments) : null;
|
||||
|
||||
var cleanFrom = parser.ExtractSqlComments(fromClause, out var fromComments);
|
||||
FromClause.Clause = cleanFrom.Trim();
|
||||
FromClause.Comment = fromComments.Count > 0 ? string.Join(" ", fromComments) : null;
|
||||
parser.PopulateClauseWithComments(selectClause, SelectClause);
|
||||
parser.PopulateClauseWithComments(fromClause, FromClause);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -140,6 +140,22 @@ public class StatementParser
|
||||
/// <param name="sql">The SQL statement containing comments.</param>
|
||||
/// <param name="comments">The extracted comments as a list of strings.</param>
|
||||
/// <returns>The SQL statement with comments removed.</returns>
|
||||
/// <summary>
|
||||
/// Runs <see cref="ExtractSqlComments"/> on <paramref name="rawText"/> and assigns the
|
||||
/// cleaned text to <paramref name="target"/>'s <see cref="ISqlClause.Clause"/> (trimmed)
|
||||
/// and the merged comments to its <see cref="ISqlClause.Comment"/>. Helper for
|
||||
/// dialect-specific <c>QueryBreakdown</c> constructors that need to ingest
|
||||
/// comment-bearing SQL fragments.
|
||||
/// </summary>
|
||||
/// <param name="rawText">The SQL fragment to clean.</param>
|
||||
/// <param name="target">The clause to populate.</param>
|
||||
public void PopulateClauseWithComments(string rawText, ISqlClause target)
|
||||
{
|
||||
var clean = ExtractSqlComments(rawText, out var comments);
|
||||
target.Clause = clean.Trim();
|
||||
target.Comment = comments.Count > 0 ? string.Join(" ", comments) : null;
|
||||
}
|
||||
|
||||
#pragma warning disable S3776 // Cognitive Complexity of methods should not be too high
|
||||
#pragma warning disable S127 // "for" loop stop conditions should be invariant
|
||||
public virtual string ExtractSqlComments(string sql, out List<string> comments)
|
||||
|
||||
Reference in New Issue
Block a user