Path: redb-route/tests/redb.Route.Tests.Sql/E2E/Infrastructure/SqlE2EProvider.cs Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages. License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route Page: https://redbase.app/src/dev-2026-12-06/redb-route/tests/redb.Route.Tests.Sql/E2E/Infrastructure/SqlE2EProvider.cs ---- using System.Data.Common; namespace redb.Route.Tests.Sql.E2E.Infrastructure; /// /// One database the SQL E2E suites run against: how to reach it, the statements each scenario needs, and /// the driver/server facts the characterization suite pins down. The expectations are facts measured on /// real servers, not wishes: when a driver upgrade changes one of them, the characterization suite fails /// first and the batch design is revisited before any product code relies on the old fact. /// /// /// "Transaction-killing error" means the error class that rolls the whole server transaction back on at /// least one provider (SQL Server conversion error 245, SQLite INSERT OR ROLLBACK). PostgreSQL gets a /// conversion error too, for symmetry: there any error aborts the transaction block, yet a savepoint still /// recovers it. /// public abstract class SqlE2EProvider { /// Trait value (SqlProvider=...) and the name used in messages. public abstract string Name { get; } /// ADO.NET factory; the connector gets it through a registered connection factory. public abstract DbProviderFactory Factory { get; } /// Connection string, environment override first. public abstract string ConnectionString { get; } /// How to bring the server up when it is not reachable. public abstract string StartHint { get; } /// SQL run on every opened connection (session settings), or null. public virtual string? SessionInitSql => null; // ── Statements ─────────────────────────────────────────────────────────── /// A two-column table: integer primary key and a non-null text value. public virtual string CreateTableSql(string table) => $"CREATE TABLE {table} (id int PRIMARY KEY, val varchar(50) NOT NULL)"; /// Like , but val and a bigint column n are nullable. public virtual string CreateNullableTableSql(string table) => $"CREATE TABLE {table} (id int PRIMARY KEY, val varchar(50) NULL, n bigint NULL)"; /// Insert through the connector (:#name) that returns the inserted id as a result set (RETURNING / OUTPUT). public abstract string ReturningInsertSql(string table); /// in the driver's own syntax (@name), for ADO.NET commands built directly. public abstract string NativeReturningInsertSql(string table); /// Literal insert of one row. public string InsertLiteral(string table, int id, string val) => $"INSERT INTO {table} (id, val) VALUES ({id}, '{val}')"; /// Parameterized insert the connector binds per batch item. public string InsertSql(string table) => $"INSERT INTO {table} (id, val) VALUES (:#id, :#val)"; /// in the driver's own syntax (@name), for ADO.NET commands built directly. public string NativeInsertSql(string table) => $"INSERT INTO {table} (id, val) VALUES (@id, @val)"; /// Literal statement that raises the transaction-killing error after row 1 exists. public abstract string TransactionKillingLiteral(string table); /// Parameterized statement whose middle item of fails. public abstract string TransactionKillingBatchSql(string table); /// Three items for : ids 1 and 3 succeed, the middle one fails. public abstract List> TransactionKillingItems(); /// Three items for : ids 1 and 3 succeed, the middle one repeats id 1. public List> DuplicateKeyItems() => [ new() { ["id"] = 1, ["val"] = "a" }, new() { ["id"] = 1, ["val"] = "dup" }, new() { ["id"] = 3, ["val"] = "c" }, ]; // ── Measured facts (characterization expectations) ────────────────────── /// Rows left after: insert 1, duplicate key, insert 3, commit — errors ignored, no savepoints. public abstract int[] LoopContinueDuplicateKeyRows { get; } /// Rows left after: insert 1, transaction-killing error, insert 3, commit attempt. public abstract int[] LoopContinueTransactionKillingRows { get; } /// After a duplicate key inside a savepoint, rolling back to that savepoint fails. public abstract bool DuplicateKeyDestroysTransaction { get; } /// After the transaction-killing error inside a savepoint, rolling back to that savepoint fails. public abstract bool TransactionKillingErrorDestroysTransaction { get; } /// What reports (not whether savepoints work). public abstract bool ReportsSavepointSupport { get; } /// /// The statement sent right after the transaction-killing error is refused by the driver or server. /// False means it runs — on SQL Server outside any transaction, in autocommit. /// public abstract bool CommandAfterTransactionKillingErrorIsRejected { get; } /// What reports. public abstract bool CanCreateBatch { get; } /// refuses parameters whose type was never set explicitly. public abstract bool PrepareRejectsUntypedParameters { get; } /// /// A reader left open in a and closed by a volatile enlistment on /// Prepare lets the scope commit. False where the driver commits before volatile enlistments are prepared. /// public virtual bool ReaderClosedOnPrepareLetsScopeCommit => false; /// /// The connection runs another statement while one of its readers is still open. False where the driver refuses it /// ("a command is already in progress", "already an open DataReader"). /// public virtual bool ReaderConnectionRunsAnotherCommand => false; /// /// The way a second connection in a scope can fail besides a : /// a driver that waits for the promotion until the command times out. False where only the transaction error comes. /// public virtual bool IsSecondConnectionTimeout(Exception error) => false; }