feat(sql): named-query tag model — read-only SELECTs declared on the driver (lmxopcua#753)
SqlTagModel.Query (design §5.4) is now served end to end instead of refused. The driver config declares `queries` (name -> sql, params, maxRows); a tag names the query, the result `column` it reads and optionally a `rowKey` picking its row. - Parser/deploy gate: query + column required, rowKey all-or-nothing; Inspect explains each refusal. Table is not read for this model. - SqlReadOnlyStatement: single SELECT/WITH only, no data/schema-changing keyword outside literals/comments (refuses SELECT INTO, FOR UPDATE, DML CTEs). Shared by the factory and the AdminUI driver form (SqlNamedQueryRules.Describe), so the form refuses what the driver refuses. One bad entry fails the driver. - Parameters are always bound; the factory refuses a declared parameter whose dialect marker the statement never uses. - Reader: one execution per query per poll, inside a transaction that is always rolled back; result columns matched exact-then-unique-CI; no row -> BadNoData, ambiguous row / missing column / over maxRows -> BadConfigurationError. - Catalog gate passes Query tags through (nothing is quoted into SQL); a Query-only driver skips the catalog load. A tag naming an undeclared query is skipped with the reason on /hosts. - AdminUI: typed editor offers Query (query/column/rowKey); driver form edits `queries` as JSON and keeps the last valid set on a typo. (lmxopcua#753) Claude-Session: https://claude.ai/code/session_01GT67AEHd2Acv1YPwGfXEoV
This commit is contained in:
@@ -53,4 +53,27 @@ public sealed class SqlDriverOptions
|
||||
/// It never governs an absent row, which is always <see cref="SqlStatusCodes.BadNoData"/>.
|
||||
/// </summary>
|
||||
public bool NullIsBad { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// The validated named queries (design §5.4) a <see cref="SqlTagModel.Query"/> tag reads by name, keyed
|
||||
/// ordinally. Empty when the config declares none.
|
||||
/// </summary>
|
||||
public IReadOnlyDictionary<string, SqlNamedQuery> Queries { get; init; } =
|
||||
new Dictionary<string, SqlNamedQuery>(StringComparer.Ordinal);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// One validated named query — what <see cref="SqlNamedQueryDto"/> becomes once the factory has checked it
|
||||
/// (<see cref="SqlNamedQueryRules.Describe"/> plus the dialect's marker check).
|
||||
/// </summary>
|
||||
/// <param name="Name">The <c>queries</c> key tags reference.</param>
|
||||
/// <param name="Sql">The normalised single read-only statement (no trailing terminator).</param>
|
||||
/// <param name="ParameterNames">The bare parameter base names, in authored order.</param>
|
||||
/// <param name="ParameterValues">The values bound under <paramref name="ParameterNames"/>, aligned index-for-index.</param>
|
||||
/// <param name="MaxRows">The per-poll row ceiling; one row more refuses the whole query.</param>
|
||||
public sealed record SqlNamedQuery(
|
||||
string Name,
|
||||
string Sql,
|
||||
IReadOnlyList<string> ParameterNames,
|
||||
IReadOnlyList<object?> ParameterValues,
|
||||
int MaxRows);
|
||||
|
||||
Reference in New Issue
Block a user