Merge #974 + #987: dialect-aware Sql read-only guard + read-only execution (13 bypasses closed), provider-semantics key matching, trigger-safe SQL Server rowcount

This commit is contained in:
Joseph Doherty
2026-12-03 10:34:08 -05:00
26 changed files with 2067 additions and 298 deletions
@@ -17,7 +17,7 @@
<div class="row g-3">
<div class="col-md-4">
<label for="@FieldId("field-01")" class="form-label">Provider</label>
<InputSelect aria-describedby="@FieldIds("field-01-hint")" id="@FieldId("field-01")" @bind-Value="_form.Provider" @bind-Value:after="EmitAsync" class="form-select form-select-sm">
<InputSelect aria-describedby="@FieldIds("field-01-hint")" id="@FieldId("field-01")" @bind-Value="_form.Provider" @bind-Value:after="OnProviderChangedAsync" class="form-select form-select-sm">
@* Every provider SqlDialects constructs. *@
<option value="@SqlProvider.SqlServer">@SqlProvider.SqlServer</option>
<option value="@SqlProvider.Postgres">@SqlProvider.Postgres</option>
@@ -184,6 +184,14 @@
await DriverConfigJsonChanged.InvokeAsync(json);
}
// The named-query guard lexes the SQL as the provider's own dialect (lmxopcua#974), so a provider change
// re-validates the queries text: what is a plain read under one dialect can be ambiguous under another.
private async Task OnProviderChangedAsync()
{
_form.SetQueriesJson(_form.QueriesJson);
await EmitAsync();
}
private async Task OnResilienceChanged(string? r)
{
ResilienceConfig = r;
@@ -230,17 +238,19 @@
};
/// <summary>Adopts edited queries text when it parses and every entry passes the runtime's own rules
/// (<see cref="SqlNamedQueryRules.Describe"/>); otherwise records why and keeps the last valid set, so a
/// typo never silently drops queries the deployed tags read.</summary>
/// (<see cref="SqlNamedQueryRules.Describe"/>, lexed as <see cref="Provider"/>'s dialect); otherwise records
/// why and keeps the last valid set, so a typo never silently drops queries the deployed tags read.</summary>
public void SetQueriesJson(string? text)
{
QueriesJson = text ?? "";
QueriesError = TryParseQueries(QueriesJson, out var parsed);
QueriesError = TryParseQueries(QueriesJson, Provider, out var parsed);
if (QueriesError is null) { Queries = parsed; }
}
/// <summary>Parses + validates queries text. Blank ⇒ no queries. Returns the problem, or null.</summary>
public static string? TryParseQueries(string? text, out Dictionary<string, SqlNamedQueryDto>? queries)
/// <summary>Parses + validates queries text as <paramref name="provider"/>'s dialect (the factory's own
/// rule). Blank ⇒ no queries. Returns the problem, or null.</summary>
public static string? TryParseQueries(
string? text, SqlProvider provider, out Dictionary<string, SqlNamedQueryDto>? queries)
{
queries = null;
if (string.IsNullOrWhiteSpace(text)) { return null; }
@@ -256,7 +266,7 @@
if (queries is null) { return "named queries must be a JSON object"; }
foreach (var (name, query) in queries)
{
if (SqlNamedQueryRules.Describe(name, query) is { } problem) { queries = null; return problem; }
if (SqlNamedQueryRules.Describe(name, query, provider) is { } problem) { queries = null; return problem; }
}
if (queries.Count == 0) { queries = null; }