mysql

package
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 11, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package mysql implements the MySQL dialect driver (Tier 2). This file is the lexer profile: token boundaries only, no SQL understanding. Lexing assumes the default sql_mode — double quotes delimit strings (not ANSI_QUOTES) and backslash escapes are active (not NO_BACKSLASH_ESCAPES).

Index

Constants

View Source
const (
	// FlagUnsigned marks UNSIGNED integer/decimal columns.
	FlagUnsigned uint32 = 1 << 8
	// FlagBinary marks binary-charset string/blob columns ([]byte, not
	// string).
	FlagBinary uint32 = 1 << 9
)

MySQL has no OIDs; dialect.TypeRef.OID carries the wire-protocol type code (MYSQL_TYPE_*) plus the two flag bits below. The encoding is stable — it is what the committed cache stores.

View Source
const CatalogSchemaName = "sqletch"

CatalogSchemaName is the schema name stamped on natively-built catalogs. It matches the devdb container database (devdb/mysql.go's WithDatabase), which is what every server-captured cache and corpus case records — byte-identity across oracle backends (design 15 §3) depends on the two never diverging.

Variables

This section is empty.

Functions

func BuildCatalog

func BuildCatalog(schema []cache.SchemaFile) (*cache.Catalog, error)

BuildCatalog parses the ordered schema inputs into a catalog byte-identical to Snapshot over a server that ran the same DDL: table OIDs 1-based in table-name order, column att numbers are definition ordinals, type names are information_schema COLUMN_TYPE spellings, HasDefault mirrors the snapshot query's predicate (non-NULL default, auto_increment, or generated default).

v1 subset: CREATE TABLE, DROP TABLE, and no-op SET statements.

Types

type Frontend

type Frontend struct{}

Frontend is the TiDB-parser-backed grammar frontend for MySQL.

Unlike pg_query, the TiDB AST carries byte offsets on expression nodes but NOT on relation nodes (TableName/TableSource). Relation locations are recovered lexically: in MySQL a relation name in FROM position is always preceded by FROM/JOIN/','/'('/'.'/INTO/UPDATE, so a monotonic token scan that skips subqueries pins each relation to its name token. See locateRelations.

func (Frontend) Parse

func (Frontend) Parse(sql string) (dialect.Tree, error)

func (Frontend) ProbeExpr

func (f Frontend) ProbeExpr(expr string) error

ProbeExpr checks that expr forms exactly one boolean-position expression: it must parse when parenthesized as a WHERE condition and contribute nothing beyond it. Parenthesis balance is the rules' (lexer-level) concern.

func (Frontend) ProbeGroupBy

func (f Frontend) ProbeGroupBy(clause string) error

ProbeGroupBy checks that clause is exactly one statement-level GROUP BY clause and nothing more.

func (Frontend) ProbeInsertValue

func (f Frontend) ProbeInsertValue(expr string) error

ProbeInsertValue checks that expr is exactly one VALUES row item (including the DEFAULT keyword, which is only legal there).

func (Frontend) ProbeJoinItem

func (f Frontend) ProbeJoinItem(item string) error

ProbeJoinItem checks that item is a join item attachable to a preceding FROM entry.

func (Frontend) ProbeOrderBy

func (f Frontend) ProbeOrderBy(clause string) error

ProbeOrderBy checks that clause is exactly one statement-level ORDER BY clause and nothing more.

func (Frontend) ProbeOrderByKey

func (f Frontend) ProbeOrderByKey(expr string) error

ProbeOrderByKey checks that expr is exactly one sort key.

func (Frontend) ProbeSetItem

func (f Frontend) ProbeSetItem(item string) error

ProbeSetItem checks that item is exactly one UPDATE SET assignment.

type NativeOracle

type NativeOracle struct {
	// contains filtered or unexported fields
}

NativeOracle is the native-inference oracle backend (design 15): Describe answered by sqletch's own name resolution over a DDL-built catalog plus the Tier 2 annotations, with no server anywhere. It is strict and fail-closed — anything outside the modeled subset is a NativeUnsupportedError (SQLETCH214), never a guess — and its answers must be byte-identical to the server backend's for every input it accepts (the corpus gate pins this).

v1 subset: single top-level SELECT/INSERT/UPDATE/DELETE statements over catalog tables. No derived tables and no subqueries (except the dialect's own arity-0 @in emission); expression result columns need an AS alias and a `-- @column` annotation (D3/D4); ENUM/SET result columns are refused (their wire form differs from their catalog form).

func NewNativeOracle

func NewNativeOracle(schema []cache.SchemaFile, serverVersion string) (*NativeOracle, error)

NewNativeOracle builds the backend from the ordered schema inputs and the pinned server version (which it reports verbatim — under a native backend the pin IS the modeled engine).

func (*NativeOracle) Describe

func (o *NativeOracle) Describe(ctx context.Context, sql string) (dialect.Desc, error)

func (*NativeOracle) Plan

func (o *NativeOracle) Plan(ctx context.Context, sql string) error

Plan validates like Describe and claims nothing more: there is no planner here (design 15 D2). check --exhaustive under the native backend prints that EXPLAIN coverage needs a server-backed run.

func (*NativeOracle) ServerVersion

func (o *NativeOracle) ServerVersion(context.Context) (string, error)

func (*NativeOracle) Snapshot

func (o *NativeOracle) Snapshot(ctx context.Context) (*cache.Catalog, error)

type Oracle

type Oracle struct {
	// contains filtered or unexported fields
}

Oracle is the COM_STMT_PREPARE-backed type oracle. Preparing never executes; result-column metadata (name, type, source table/column) is reliable, while parameter metadata is not typed by the protocol — Desc.Params entries stay zero and the pipeline fills them from the mandatory `-- @param` annotations.

Plan prepares `EXPLAIN <sql>` and executes it with every parameter bound to NULL: executing an EXPLAIN plans the statement without touching data, which surfaces optimizer-stage errors that a bare prepare cannot see.

func NewOracle

func NewOracle(conn *client.Conn) *Oracle

func (*Oracle) Describe

func (o *Oracle) Describe(ctx context.Context, sql string) (dialect.Desc, error)

func (*Oracle) Plan

func (o *Oracle) Plan(ctx context.Context, sql string) error

func (*Oracle) PlanText

func (o *Oracle) PlanText(ctx context.Context, sql string) (string, error)

PlanText returns the EXPLAIN FORMAT=TREE output for explain --analyze, parameters bound to NULL.

func (*Oracle) ServerVersion

func (o *Oracle) ServerVersion(ctx context.Context) (string, error)

func (*Oracle) Snapshot

func (o *Oracle) Snapshot(ctx context.Context) (*cache.Catalog, error)

Snapshot dumps the current database's columns. MySQL has no OIDs; tables get stable synthetic ones (1-based in table-name order, the query's ORDER BY), and column att numbers are ordinal positions.

The ORDER BY sorts table_name as BINARY (raw byte order) rather than under information_schema's default case-insensitive collation. That makes the synthetic OID assignment byte-identical to the native catalog builder (internal/dialect/mysql/nativecatalog.go), which orders names with Go's sort.Strings — a byte-wise comparison. Under the collation default the two backends assigned different OIDs to mixed-case schemas (e.g. "Zebra" vs "apple": collation → apple, Zebra; bytes → Zebra, apple), silently violating the hard byte-identity-across-backends invariant (design 15 §3). BINARY is used instead of a COLLATE clause because table_name may be utf8mb3 on some servers, for which a utf8mb4 collation name is rejected.

type Profile

type Profile struct{}

func (Profile) CaseInsensitiveIdents

func (Profile) CaseInsensitiveIdents() bool

CaseInsensitiveIdents reports that MySQL resolves aliases and column references case-insensitively, so R3/R2 name matching must fold.

func (Profile) InEmptySQL

func (Profile) InEmptySQL() string

InEmptySQL is the arity-0 @in emission (FALSE even for NULL operands; MySQL needs FROM DUAL to attach a WHERE).

func (Profile) NextToken

func (Profile) NextToken(src []byte, pos int) (dialect.Token, error)

func (Profile) PlaceholderStyle

func (Profile) PlaceholderStyle() dialect.PlaceholderStyle

PlaceholderStyle declares MySQL's '?' per-occurrence binding.

type TypeMap

type TypeMap struct{}

TypeMap maps encoded MySQL type refs to Go types for generated code. Deliberately conservative: unmapped types are a compile error with the type name in the message — never a silent guess.

func (TypeMap) GoType

func (TypeMap) GoType(oid uint32) (dialect.GoTypeRef, bool)

func (TypeMap) TypeByName

func (TypeMap) TypeByName(name string) (dialect.TypeRef, bool)

TypeByName resolves a SQL type name from a `-- @param` hint. "bigint unsigned" style modifiers fold into the flag bits.

type UnsupportedDDLError

type UnsupportedDDLError struct {
	File string // schema input path as given
	Pos  int    // byte offset of the offending statement in that file
	Msg  string
}

UnsupportedDDLError reports a schema statement outside the native catalog builder's modeled subset (design 15 §5.1, decision D5). The CLI maps it to SQLETCH215 with a span into the schema file. Fail closed: anything the builder does not fully model is refused, never approximated.

func (*UnsupportedDDLError) Error

func (e *UnsupportedDDLError) Error() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL