Link Search Menu Expand Document

MariaDbStatementBuilder


This class is the BaseStatementBuilder-derived implementation for the MySqlConnector-based RepoDb.MariaDbConnector package. It is automatically registered by MariaDbBootstrap — you do not need to instantiate it directly under normal use.

It generates `table`-quoted, @-parameterized SQL, and uses LIMIT/OFFSET for BatchQuery and the internal skip/take query.

For Insert and InsertAll, the newly generated identity value is returned via LAST_INSERT_ID(); for a non-identity primary key it is echoed back from the supplied parameter instead.

Merge and MergeAll are compiled as INSERT ... ON DUPLICATE KEY UPDATE ... (MariaDB’s native upsert), returning COALESCE(<primary key parameter>, LAST_INSERT_ID()) so the result reflects either the supplied key or the identity value generated by the insert branch.

That COALESCE(...) expression is additionally wrapped in a CAST(... AS UNSIGNED)/CAST(... AS SIGNED), chosen from the key column’s CLR type (unsigned integer types cast to UNSIGNED, signed integer types cast to SIGNED, defaulting to UNSIGNED when there is no key column) — this avoids a type-mismatch error when combining a signed literal with an unsigned AUTO_INCREMENT value.

This builder also strips the extra space the base builder emits before the opening parenthesis of COUNT, MAX, MIN and SUM calls (e.g. COUNT ( becomes COUNT().

No convertFieldResolver is supplied to the base constructor, so — like MySQL — a Field with an explicit .Type is not rendered as a CAST/CONVERT expression for MariaDb.

Constructors

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

The parameterless constructor resolves dbSetting via DbSettingMapper.Get<MariaDbConnection>(), so it can only be used after MariaDbBootstrap has run.

Usability

Use StatementBuilderMapper to override it with a custom implementation.

StatementBuilderMapper.Add(typeof(MariaDbConnection), new MyCustomMariaDbStatementBuilder(dbSetting));