refactor(dedup): cross-dialect QueryBreakdown + StatementParser helpers (Cluster E)
SonarQube Analysis / sonarqube (pull_request) Successful in 4m5s
SonarQube Analysis / sonarqube (pull_request) Successful in 4m5s
Two shared scaffolds for blocks Sonar flagged across the SqlServer,
Snowflake, and PostgreSQL dialects:
1. **`AppendToClause` on `SqlBreakdownBase`** — collapses the "if
clause is empty set it, else append `{operation} {sql}`; then merge
comment with same rule" pattern that was repeated three times in
each of SqlServer/Snowflake `QueryBreakdown`. The matching
`AddWhereExpression` / `AddHavingExpression` / `AddWhereClause(string)`
sites in both files now delegate to a single `protected static`
helper. Operates against `ISqlClause`, so it works for both the
`WhereClause` and `HavingClause` properties.
2. **`HandleDoubleQuoteAsIdentifier` on `SqlServer.StatementParser`** —
PostgreSQL and Snowflake both override SqlServer's
`HandleDoubleQuote` (which produces a string-literal token) to
instead produce a `ColumnIdentifier` token. The two overrides had
identical 14-line bodies. The shared logic now lives once, and
each dialect's override is a one-liner that calls the helper.
Deliberately *not* refactored in this commit:
- The CTE WITH-clause SQL generation in SqlServer/Snowflake QueryBreakdown
(lines ~537-560 / ~579-601 Sonar flagged) — the surrounding logic
differs enough between the two that an extraction would obscure
rather than clarify.
- The PG/Snowflake QueryBreakdown constructor pair (lines 40-58 /
43-61) — only ~10 lines × 2; extracting requires either a new
shared helper for ~20 lines of savings or moving up the inheritance
chain, neither pays for itself.
All 1180 tests stay green.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.7
parent
c121dfa611
commit
f577c06558
@@ -53,6 +53,42 @@ public abstract class SqlBreakdownBase : ISqlBreakdown
|
||||
/// <returns>The SQL query string.</returns>
|
||||
protected abstract string GetSqlBreakdown();
|
||||
|
||||
/// <summary>
|
||||
/// Appends a SQL fragment to an <see cref="ISqlClause"/> with the given logical operation
|
||||
/// (e.g. <c>"and"</c> / <c>"or"</c>), and optionally merges an associated comment.
|
||||
/// If the target clause is empty, the fragment is set as the clause; otherwise it is
|
||||
/// joined with the operation.
|
||||
/// </summary>
|
||||
/// <param name="clause">The clause being built up (e.g. <c>WhereClause</c>, <c>HavingClause</c>).</param>
|
||||
/// <param name="sql">The already-generated SQL fragment to append.</param>
|
||||
/// <param name="operation">The logical operation used to join with the existing content.</param>
|
||||
/// <param name="comment">Optional comment to merge into <c>clause.Comment</c>.</param>
|
||||
protected static void AppendToClause(ISqlClause clause, string sql, string operation, string? comment)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(clause.Clause))
|
||||
{
|
||||
clause.Clause = sql;
|
||||
}
|
||||
else
|
||||
{
|
||||
clause.Clause = $"{clause.Clause} {operation} {sql}";
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(comment))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(clause.Comment))
|
||||
{
|
||||
clause.Comment = comment;
|
||||
}
|
||||
else
|
||||
{
|
||||
clause.Comment = $"{clause.Comment} {comment}";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a LINQ to SQL query of the specified type based on this breakdown.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user