From da467c9675573a10628d3f4d0c81a6814982343c Mon Sep 17 00:00:00 2001 From: Joseph Doherty Date: Thu, 3 Dec 2026 14:54:34 -0500 Subject: [PATCH] docs(sql): #1042 MySQL read-only session is not a boundary; #1043 ODBC to SQL Server trigger row count and its remedies --- docs/drivers/Sql.md | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/docs/drivers/Sql.md b/docs/drivers/Sql.md index d25a5b960..c79f1b4fe 100644 --- a/docs/drivers/Sql.md +++ b/docs/drivers/Sql.md @@ -236,7 +236,11 @@ row: as one extended-protocol statement; the server rejects anything after a `;` itself. Oracle (ODP.NET) refuses a second statement anyway. SQL Server and MySQL execute a multi-statement batch — there the guard is the line (on SQL Server its T-SQL parse, above), and MySQL's read-only session is defence in depth - that hidden text could undo. + that hidden text could undo. **On MySQL the read-only session is NOT a boundary (#1042):** MySqlConnector + cannot disable multi-statement execution, so a statement that got past the guard runs as a batch in which a + later statement may re-enable writes for the session (or `COMMIT` out of the transaction). A MySQL / MariaDB + driver — read-only above all — must connect with a **`SELECT`-only login**; treat that grant, not the session + mode, as the only enforcement. - None of this replaces the grant: a non-transactional side effect (an e-mail procedure, a call out to another system, an autonomous transaction) is outside every layer — which is why a read-only driver **must** connect with a `SELECT`-only login (see [Database login](#database-login-required)). @@ -464,7 +468,7 @@ both and is rolled back (`BadConfigurationError`). |---|---| | Committed | `Good` | | `Update` (or a non-MySQL `Upsert`) touched no row — the key is absent; nothing is inserted | `BadNoData` | -| More rows than the mode allows — the key is not unique; rolled back. The count is the **target statement's own**: on SQL Server the driver reads `@@ROWCOUNT` right after it (an `OUTPUT` parameter), because SqlClient's command-level count also sums trigger DML — an audit trigger that inserts a history row used to make every single-row write "touch 2 rows" and roll back (#987). PostgreSQL, MySQL and Oracle already report the statement alone. Odbc reports whatever its backend's driver does (an ODBC link to SQL Server keeps the trigger-summed count). | `BadConfigurationError` | +| More rows than the mode allows — the key is not unique; rolled back. The count is the **target statement's own**: on SQL Server the driver reads `@@ROWCOUNT` right after it (an `OUTPUT` parameter), because SqlClient's command-level count also sums trigger DML — an audit trigger that inserts a history row used to make every single-row write "touch 2 rows" and roll back (#987). PostgreSQL, MySQL and Oracle already report the statement alone. Odbc reports whatever its backend's driver does (an ODBC link to SQL Server keeps the trigger-summed count, #1043 — the backend is unknown so the driver cannot append `@@ROWCOUNT`, and ODBC has no output parameters outside a procedure call; to write to SQL Server use the native `SqlServer` provider, or keep the trigger from counting with `SET NOCOUNT ON` as its first statement). | `BadConfigurationError` | | The provider could not report a row count; rolled back | `BadNotSupported` | | Unique / primary-key violation — e.g. an `Insert` of a key that exists (SQLSTATE 23505, SQL Server 2627/2601, MySQL 1062, ORA-00001) | `BadEntryExists` | | Another integrity rule — NOT NULL, foreign key, CHECK (SQLSTATE class 23, SQL Server 515/547, ORA-01400/02290/02291) — or a data exception: overflow, truncation, an unconvertible value (SQLSTATE class 22, SQL Server 8115/8152/245, ORA-01438/12899/01722) | `BadOutOfRange` | @@ -509,7 +513,8 @@ The driver's own guards are not a substitute for the database's grants: per-dialect keyword check plus an always-rolled-back (read-only where the provider has one) transaction; none of that can stop a **non-transactional** side effect — a function that sends mail or calls out, autonomous transactions — and on SQL Server and MySQL a statement that got past the guard would run as a - batch. Only the grant is a boundary. + batch. Only the grant is a boundary. This applies with particular force to **MySQL**, whose read-only + *session* is not a boundary either (MySqlConnector cannot disable multi-statement execution, #1042). - **A writable driver must connect with a login limited to its write targets** — `SELECT` as above, plus exactly what its modes need on exactly the tables / procedures its writable tags name: `UPDATE` (Update), `INSERT` (Insert), `INSERT` + `UPDATE` (Upsert; SQL Server's `MERGE` also needs