Documentation
¶
Overview ¶
Package mysql is the MySQL dialect: how MySQL 8 writes a bound parameter and quotes an identifier, and which optional capabilities it has.
Like every dialect here it imports the render layer and nothing else, which is exactly what a dialect from another repository imports. The constructs only MySQL has live in github.com/ubgo/sqlb/mysql.
Until 2026-09-22 MySQL was a reference engine only: the universality rule named it and nothing here could render for it, so that quarter of the rule was checked by reading its documentation. This package and contrib/driver-mysql, which runs the conformance suite on a real MySQL 8.4, replace the reading with a measurement.
Index ¶
- Constants
- type Dialect
- func (Dialect) Name() string
- func (Dialect) NumericParam(placeholder string, v any) string
- func (Dialect) Placeholder(int) string
- func (Dialect) QuoteIdent(ident string) string
- func (Dialect) QuoteLiteral(v any) (string, error)
- func (Dialect) SupportsCombinedAlter() bool
- func (Dialect) SupportsLikeEscape() bool
- func (Dialect) SupportsUnrestrictedAddColumn() bool
Constants ¶
const Name = render.DialectMySQL
Name is the engine name this dialect reports.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Dialect ¶
type Dialect struct{}
Dialect renders ? placeholders and backquoted identifiers.
func (Dialect) NumericParam ¶
NumericParam casts an integer parameter to SIGNED, or an unsigned one to UNSIGNED, so a DECIMAL beside it in COALESCE or arithmetic does not widen the result to DECIMAL(65,30). See render.NumericParameters for the measurement.
It reads the kind rather than switching on types, so a named integer type (type Age int64) is cast like int64. A nil pointer and every non-integer value are left alone: a NULL has no type to give, and a float or a string was measured not to widen.
func (Dialect) Placeholder ¶
Placeholder renders ?. MySQL's placeholders are positional and unnumbered, so a value used twice is bound twice.
func (Dialect) QuoteIdent ¶
QuoteIdent backquotes an identifier, doubling any embedded backquote. It is not the double quote the other engines use: a double-quoted token is a string in MySQL unless the ANSI_QUOTES mode is on, and a builder cannot depend on a server's mode.
func (Dialect) QuoteLiteral ¶
QuoteLiteral writes v as a MySQL literal that reads back as exactly v, whatever the server's sql_mode.
The mode is the difficulty, as standard_conforming_strings is on Postgres. With NO_BACKSLASH_ESCAPES off, the default, a backslash in a string literal is an escape; with it on, it is a character. A string without a backslash, quotes doubled, reads the same under both, measured on MySQL 8.4. A string with one has no spelling that does: the hex form _utf8mb4 X'...' reads correctly in a query, but MySQL stores an expression default as printed text and re-parses it under the session's mode, so a DEFAULT of that form holding the three characters a\b read back as four with NO_BACKSLASH_ESCAPES on. A string containing a backslash is therefore ErrNotInlinable, not a best guess; bind it where a parameter is allowed, which is everywhere but DDL.
The value set is otherwise the Postgres one: strings, bools, every integer and float kind, []byte, time.Time (in UTC, for a DATETIME), nil, pointers and named types over those. A NUL, a NaN and an infinity are refused.
func (Dialect) SupportsCombinedAlter ¶
SupportsCombinedAlter reports true: MySQL applies several ALTER TABLE actions in one statement.
func (Dialect) SupportsLikeEscape ¶
SupportsLikeEscape reports true: MySQL accepts an ESCAPE clause on LIKE.
func (Dialect) SupportsUnrestrictedAddColumn ¶
SupportsUnrestrictedAddColumn reports true: MySQL's ADD COLUMN takes any column CREATE TABLE would, filling existing rows with the column's implicit default when it is NOT NULL.