Link Search Menu Expand Document

Db2StatementBuilder


This class is the BaseStatementBuilder-derived implementation for Db2. It targets Db2 for Linux, UNIX, and Windows (LUW) 10.5 and later, and is automatically registered by Db2Bootstrap — you do not need to instantiate it directly under normal use.

Constructors

public Db2StatementBuilder(IDbSetting dbSetting)
public Db2StatementBuilder(IDbSetting dbSetting,
    IResolver<Field, IDbSetting, string> convertFieldResolver = null,
    IResolver<Type, Type> averageableClientTypeResolver = null)

convertFieldResolver defaults to Db2ConvertFieldResolver, used to render CAST(...) expressions for typed fields.

Db2-specific generation notes

  • Paging uses OFFSET ... ROWS FETCH NEXT ... ROWS ONLY for BatchQuery/skip-take queries, and a trailing FETCH FIRST n ROWS ONLY for Exists and top-N Query — Db2 has no TOP keyword.
  • Insert/InsertAll read back a generated key via SELECT <key> FROM FINAL TABLE (INSERT INTO ...), an ANSI-adjacent construct that surfaces the post-insert row as an ordinary result set.
  • Merge/MergeAll are generated as MERGE INTO t USING (SELECT ... FROM SYSIBM.SYSDUMMY1) s ON (...) WHEN MATCHED THEN UPDATE ... WHEN NOT MATCHED THEN INSERT ..., since Db2 has no native upsert statement equivalent. SYSIBM.SYSDUMMY1 (Db2’s single-row dummy table) is required because MERGE’s USING source needs a FROM even when only selecting bind variables. Because Db2 LUW’s MERGE does not support FINAL TABLE, the generated key is instead retrieved via a follow-up SELECT appended to the same command text.
  • Truncate always appends the IMMEDIATE keyword (TRUNCATE TABLE t IMMEDIATE), which older Db2 versions (pre-11.5 Mod Pack 2) require.
  • Every generated statement omits the trailing ; that BaseStatementBuilder normally appends, since the IBM Data Server .NET Provider rejects a trailing statement terminator on a plain (non-compound-statement) command.

Usability

Use StatementBuilderMapper to override it with a custom implementation.

StatementBuilderMapper.Add(typeof(DB2Connection), new MyCustomDb2StatementBuilder(dbSetting), true);