Files
lmxopcua/src/Drivers/ZB.MOM.WW.OtOpcUa.Driver.Sql.Dialect/SqlDialects.cs
T
Joseph Doherty 3c9ab4b668 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
2026-11-09 17:30:31 -05:00

48 lines
2.3 KiB
C#

using ZB.MOM.WW.OtOpcUa.Driver.Sql.Contracts;
namespace ZB.MOM.WW.OtOpcUa.Driver.Sql;
/// <summary>
/// The one map from an authored <see cref="SqlProvider"/> to the dialect this build constructs for it —
/// shared by the runtime factory, the AdminUI Test Connect probe and the browse picker.
/// <para><b>Why one map.</b> Each of those three carried its own switch, and they drifted: when the factory
/// and browser were widened to Postgres + Oracle the probe's switch stayed SqlServer-only, so a config that
/// deployed and browsed fine failed Test Connect. Every arm returns that provider's OWN dialect — there is
/// no fallback arm, because a default that resolved to T-SQL would construct happily and then speak the
/// wrong SQL at the server.</para>
/// </summary>
public static class SqlDialects
{
/// <summary>The providers this build constructs, in enum order.</summary>
public static IReadOnlyList<SqlProvider> Supported { get; } =
[.. Enum.GetValues<SqlProvider>().Where(p => TryCreate(p) is not null)];
/// <summary>Constructs the dialect for <paramref name="provider"/>, or null when this build does not carry it.</summary>
/// <param name="provider">The authored provider.</param>
/// <returns>A fresh dialect, or null.</returns>
public static ISqlDialect? TryCreate(SqlProvider provider) => provider switch
{
SqlProvider.SqlServer => new SqlServerDialect(),
SqlProvider.Postgres => new PostgresDialect(),
SqlProvider.Oracle => new OracleDialect(),
SqlProvider.MySql => new MySqlDialect(),
SqlProvider.Odbc => new OdbcDialect(),
_ => null,
};
/// <summary>
/// An operator-facing sentence naming the providers this build constructs and the ones it reserves, for
/// the "not available in this build" refusals.
/// </summary>
/// <returns>The sentence.</returns>
public static string DescribeAvailability()
{
var reserved = Enum.GetValues<SqlProvider>().Except(Supported).ToArray();
var text = "Supported: " + string.Join(", ", Supported.Select(p => $"'{p}'")) + ".";
return reserved.Length == 0
? text
: text + " Reserved (declared on the enum but not implemented): "
+ string.Join(", ", reserved.Select(p => $"'{p}'")) + ".";
}
}