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
@@ -649,6 +649,32 @@ public class StatementParser
|
||||
return ((TokenType.String, str.ToString(), start), position);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Helper used by dialects (PostgreSQL, Snowflake) where double-quoted text is an
|
||||
/// identifier rather than a string literal. Reads from the opening quote at
|
||||
/// <paramref name="position"/> and returns the inner text as a
|
||||
/// <see cref="TokenType.ColumnIdentifier"/> token.
|
||||
/// </summary>
|
||||
/// <param name="sql">The SQL statement being tokenized.</param>
|
||||
/// <param name="position">The current position in the SQL string (must point at the opening <c>"</c>).</param>
|
||||
/// <returns>The identifier token and the new position past the closing <c>"</c>.</returns>
|
||||
protected static ((TokenType type, string value, int position) token, int newPosition) HandleDoubleQuoteAsIdentifier(string sql, int position)
|
||||
{
|
||||
int start = position;
|
||||
position++; // Skip opening quote
|
||||
var identifier = new StringBuilder();
|
||||
while (position < sql.Length && sql[position] != '"')
|
||||
{
|
||||
identifier.Append(sql[position]);
|
||||
position++;
|
||||
}
|
||||
if (position < sql.Length)
|
||||
{
|
||||
position++; // Skip closing quote
|
||||
}
|
||||
return ((TokenType.ColumnIdentifier, identifier.ToString(), start), position);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Processes a list of tokens to find SQL keywords at the top level (outside parentheses).
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user