Link Search Menu Expand Document

MySqlStatementBuilder


This class is the BaseStatementBuilder-derived implementation for MySql.Data. It is automatically registered by MySqlBootstrap — 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. InsertAll composes a single multi-row INSERT ... VALUES ROW(...), ROW(...), ... statement.

Merge and MergeAll are compiled as INSERT ... ON DUPLICATE KEY UPDATE ... (MySQL’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.

No convertFieldResolver is supplied to the base constructor, so unlike SQL Server/Oracle/PostgreSQL, a Field with an explicit .Type is not rendered as a CAST/CONVERT expression for MySQL.

Constructors

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

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

Usability

Use StatementBuilderMapper to override it with a custom implementation.

StatementBuilderMapper.Add(typeof(MySqlConnection), new MyCustomMySqlStatementBuilder(dbSetting), true);