feat(sql): authored write block — Update/Insert/Upsert/Procedure + timestamp stamp; ODBC scope + login docs (lmxopcua#781)
v2-ci / unit-tests (push) Has been cancelled
v2-ci / unit-tests (push) Has been cancelled
Item 2: a tag's optional `write` block picks the statement the driver builds from its own catalog-validated identifiers (no authored SQL; values always bound): - Update (default, unchanged back-compat UPDATE ... WHERE key; 0 rows = BadNoData) - Insert (key+value[+stamp]; append for a WideRow topByTimestamp tag) - Upsert: SQL Server MERGE WITH (HOLDLOCK), PostgreSQL INSERT ... ON CONFLICT, MySQL ON DUPLICATE KEY UPDATE (1-or-2 rows), Oracle MERGE from DUAL - Procedure: named stored procedure resolved against the routine catalog by the catalog gate (INFORMATION_SCHEMA.ROUTINES / ALL_PROCEDURES), value/key/timestamp params by name (MySQL positional) - stampTimestamp sets the tag's timestamp column to the write time (UTC) Odbc serves Update/Insert only (shared SqlWriteSupport table). Constraint failures map to BadEntryExists (unique) / BadOutOfRange (other integrity, data exception); everything else, permission denied included, stays BadCommunicationError. WriteIdempotent stays false. The parser refuses malformed blocks (strict keys/enums/param charset); DraftValidator emits blocking SqlWriteBlockInvalid / SqlWriteModeUnsupported from the driver's own parse; the AdminUI editor surfaces the same message. Items 1 + 4 (docs/drivers/Sql.md): ODBC stays the ANSI SQL:2008 profile (native providers for SQL Server/MySQL, DB2 unsupported) with an ops note on driver manager + vendor driver on every Odbc and AdminUI host; read-only drivers require a SELECT-only login, writable drivers a login limited to their write targets. Tests: SqlWriteModeTests (parse, every dialect's SQL, gate, status map, SQLite end-to-end), DraftValidatorSqlWriteBlockTests, AdminUI round-trip; live SqlWriteModesLiveTests on SQL Server, PostgreSQL, MySQL, Oracle (seeds gain write_targets + set_target) and an Odbc write leg. Claude-Session: https://claude.ai/code/session_01GT67AEHd2Acv1YPwGfXEoV
This commit is contained in:
+29
-1
@@ -363,7 +363,7 @@ public sealed class SqlPollServerFixture : IAsyncLifetime
|
||||
{
|
||||
// Views first: a view over a dropped table blocks nothing, but dropping the table under a live
|
||||
// view leaves the catalog reporting a column set that no longer resolves.
|
||||
foreach (var statement in SeedStatements())
|
||||
foreach (var statement in SeedStatements().Concat(WriteTargetStatements()))
|
||||
await ExecuteAsync(connection, statement).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
@@ -378,6 +378,11 @@ public sealed class SqlPollServerFixture : IAsyncLifetime
|
||||
private static IEnumerable<string> SeedStatements()
|
||||
{
|
||||
yield return $"DROP VIEW IF EXISTS [{Schema}].[{WideRowView}];";
|
||||
// lmxopcua#781 write-mode targets (SqlWriteModesLiveTests): a primary-keyed setpoint table for
|
||||
// Update / Insert / Upsert and a procedure that journals its arguments into proc_calls.
|
||||
yield return $"DROP PROCEDURE IF EXISTS [{Schema}].[set_target];";
|
||||
yield return $"DROP TABLE IF EXISTS [{Schema}].[write_targets];";
|
||||
yield return $"DROP TABLE IF EXISTS [{Schema}].[proc_calls];";
|
||||
yield return $"DROP TABLE IF EXISTS [{Schema}].[{KeyValueTable}];";
|
||||
yield return $"DROP TABLE IF EXISTS [{Schema}].[{WideRowTable}];";
|
||||
yield return $"DROP TABLE IF EXISTS [{Schema}].[{TypeProbeTable}];";
|
||||
@@ -446,6 +451,29 @@ public sealed class SqlPollServerFixture : IAsyncLifetime
|
||||
}
|
||||
|
||||
/// <summary>Runs one non-query batch.</summary>
|
||||
private static IEnumerable<string> WriteTargetStatements()
|
||||
{
|
||||
yield return $"""
|
||||
CREATE TABLE [{Schema}].[write_targets] (
|
||||
[tag_name] nvarchar(128) NOT NULL PRIMARY KEY,
|
||||
[sp_value] float NOT NULL,
|
||||
[stamp_ts] datetime2(3) NULL
|
||||
);
|
||||
""";
|
||||
yield return $"INSERT INTO [{Schema}].[write_targets] ([tag_name], [sp_value], [stamp_ts]) VALUES (N'Present', 1.0, NULL);";
|
||||
yield return $"""
|
||||
CREATE TABLE [{Schema}].[proc_calls] (
|
||||
[tag_name] nvarchar(128) NOT NULL,
|
||||
[sp_value] float NULL,
|
||||
[stamp_ts] datetime2(3) NULL
|
||||
);
|
||||
""";
|
||||
yield return $"""
|
||||
CREATE PROCEDURE [{Schema}].[set_target] @p_value float, @p_key nvarchar(128), @p_ts datetime2(3) AS
|
||||
INSERT INTO [{Schema}].[proc_calls] ([tag_name], [sp_value], [stamp_ts]) VALUES (@p_key, @p_value, @p_ts);
|
||||
""";
|
||||
}
|
||||
|
||||
private static async Task ExecuteAsync(SqlConnection connection, string sql)
|
||||
{
|
||||
var command = connection.CreateCommand();
|
||||
|
||||
Reference in New Issue
Block a user