feat(sql): Odbc provider — ANSI SQL:2008 profile over System.Data.Odbc (lmxopcua#753)

SqlProvider.Odbc is now constructed; every enum member is a working backend.

- OdbcDialect: System.Data.Odbc 10.0.14 (no vulnerable packages), ANSI double-
  quote quoting, positional `?` markers, INFORMATION_SCHEMA catalog (system
  schemas of the common backends excluded by name — the live gate caught
  psqlODBC listing pg_catalog), FETCH FIRST n ROWS ONLY limits, a conservative
  1000-parameter chunk. Positional binding is safe because every caller adds
  parameters in marker order (planner IN list, catalog schema-then-table).
- Named queries on a positional provider are checked by `?` count against the
  declared params (literals/comments ignored), since there is no name to match.
- Supported backends are those whose SQL accepts that profile (PostgreSQL via
  psqlODBC proven, Snowflake-like); SQL Server/MySQL/DB2 should use their native
  provider. The host needs the ODBC driver manager + vendor driver.
- Reserved-provider controls in factory/probe/browser tests now use an
  undeclared ordinal (99); the AdminUI form offers Odbc and a test pins the
  dropdown theory to SqlDialects.Supported.
- Tests: OdbcDialectTests (unit, any host). OdbcReadTests + Docker/odbc/
  run-odbc-gate.sh run the built suite in a throwaway Linux SDK container with
  unixODBC + psqlODBC against a throwaway seeded PostgreSQL: KV IN-list
  positional binding, where-pair, topByTimestamp via FETCH FIRST, a two-
  parameter named query, and the browse walk. macOS has no vendor ODBC driver,
  so there the suite skips.

(lmxopcua#753)

Claude-Session: https://claude.ai/code/session_01GT67AEHd2Acv1YPwGfXEoV
This commit is contained in:
Joseph Doherty
2026-11-09 17:13:47 -05:00
parent 63372e757a
commit 3c9ab4b668
16 changed files with 606 additions and 39 deletions
@@ -223,6 +223,18 @@ public static class SqlReadOnlyStatement
return null;
}
/// <summary>The marker a positional provider (ODBC) spells every parameter with.</summary>
public const string PositionalMarker = "?";
/// <summary>Counts the positional <c>?</c> markers outside literals and comments.</summary>
/// <param name="sql">The statement.</param>
/// <returns>The marker count.</returns>
public static int CountPositionalMarkers(string sql)
{
ArgumentNullException.ThrowIfNull(sql);
return StripLiteralsAndComments(sql).Count(ch => ch == '?');
}
/// <summary>
/// True when <paramref name="marker"/> appears in <paramref name="sql"/> as a parameter token — outside
/// literals and comments, and not as the prefix of a longer name (<c>@line</c> inside <c>@lineId</c>).
@@ -1,9 +1,9 @@
namespace ZB.MOM.WW.OtOpcUa.Driver.Sql.Contracts;
/// <summary>
/// Which ADO.NET provider/dialect backs a Sql driver instance. <b>Constructed:</b> SqlServer, Postgres,
/// Oracle — each over a fully managed provider package, no native client install. <b>Reserved:</b> MySql
/// and Odbc are declared names only; authoring one fails at driver construction and at browse.
/// Which ADO.NET provider/dialect backs a Sql driver instance. Every member is constructed: SqlServer,
/// Postgres, Oracle and MySql over fully managed provider packages, and Odbc over <c>System.Data.Odbc</c>
/// (which also needs the host's ODBC driver manager and the vendor driver).
/// </summary>
public enum SqlProvider
{
@@ -13,10 +13,13 @@ public enum SqlProvider
/// <summary>PostgreSQL via the managed <c>Npgsql</c> provider.</summary>
Postgres,
/// <summary>MySQL / MariaDB — reserved; no dialect ships, so this is not constructed.</summary>
/// <summary>MySQL / MariaDB via the fully managed <c>MySqlConnector</c> provider.</summary>
MySql,
/// <summary>Generic ODBC — reserved; no dialect ships, so this is not constructed.</summary>
/// <summary>
/// Generic ODBC via <c>System.Data.Odbc</c>, speaking the ANSI SQL:2008 profile (<c>INFORMATION_SCHEMA</c>,
/// <c>FETCH FIRST</c>, positional <c>?</c>) — see <c>OdbcDialect</c> for which backends that fits.
/// </summary>
Odbc,
/// <summary>Oracle Database via the fully managed <c>Oracle.ManagedDataAccess.Core</c> provider.</summary>