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()
|
public QueryBreakdown(string selectClause, string fromClause, bool isMicrosoftSql = false) : base()
|
||||||
{
|
{
|
||||||
var parser = isMicrosoftSql ? Parser : PostgreSqlParserInstance;
|
var parser = isMicrosoftSql ? Parser : PostgreSqlParserInstance;
|
||||||
|
parser.PopulateClauseWithComments(selectClause, SelectClause);
|
||||||
var cleanSelect = parser.ExtractSqlComments(selectClause, out var selectComments);
|
parser.PopulateClauseWithComments(fromClause, FromClause);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -39,14 +39,8 @@ public class QueryBreakdown : SqlServerQueryBreakdown
|
|||||||
public QueryBreakdown(string selectClause, string fromClause, bool isMicrosoftSql = false) : base()
|
public QueryBreakdown(string selectClause, string fromClause, bool isMicrosoftSql = false) : base()
|
||||||
{
|
{
|
||||||
var parser = isMicrosoftSql ? Parser : SnowflakeParserInstance;
|
var parser = isMicrosoftSql ? Parser : SnowflakeParserInstance;
|
||||||
|
parser.PopulateClauseWithComments(selectClause, SelectClause);
|
||||||
var cleanSelect = parser.ExtractSqlComments(selectClause, out var selectComments);
|
parser.PopulateClauseWithComments(fromClause, FromClause);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -140,6 +140,22 @@ public class StatementParser
|
|||||||
/// <param name="sql">The SQL statement containing comments.</param>
|
/// <param name="sql">The SQL statement containing comments.</param>
|
||||||
/// <param name="comments">The extracted comments as a list of strings.</param>
|
/// <param name="comments">The extracted comments as a list of strings.</param>
|
||||||
/// <returns>The SQL statement with comments removed.</returns>
|
/// <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 S3776 // Cognitive Complexity of methods should not be too high
|
||||||
#pragma warning disable S127 // "for" loop stop conditions should be invariant
|
#pragma warning disable S127 // "for" loop stop conditions should be invariant
|
||||||
public virtual string ExtractSqlComments(string sql, out List<string> comments)
|
public virtual string ExtractSqlComments(string sql, out List<string> comments)
|
||||||
|
|||||||
Reference in New Issue
Block a user