Repository navigation
feat(mysql): FROM DUAL, index hints, locking reads, unbounded LIMIT, option-only ALTER - #56
Merged
Merged
Conversation
…option-only ALTER
MySQL statement shapes PHP applications use that SQLite rejects as written:
- `... FROM DUAL` drops the FROM, so `INSERT ... SELECT ... FROM DUAL WHERE
NOT EXISTS (...)` works and reports 0 affected rows when suppressed.
- Index hints (FORCE/USE/IGNORE INDEX|KEY [FOR ...]) are removed, never
mapped to INDEXED BY (which fails on a missing index).
- Locking reads (FOR UPDATE / FOR SHARE / NOWAIT / SKIP LOCKED, and the
unparseable LOCK IN SHARE MODE) are removed; single-writer semantics
documented.
- LIMIT literals >= 2^63 (MySQL's 18446744073709551615 "no limit") become
LIMIT -1.
- ALTER TABLE with only table options (ROW_FORMAT, ENGINE, CHARSET,
COLLATE, AUTO_INCREMENT, COMMENT, CONVERT TO CHARACTER SET,
ENABLE/DISABLE KEYS, FORCE, ...) is a no-op.
- LEAST/GREATEST -> multi-arg min/max, CHAR_LENGTH -> length.
Fixes the DDL display-width and SELECT-hint pre-passes, which re-encoded
each byte of multi-byte UTF-8 ('café' -> 'café') and ended a string at a
backslash-escaped quote.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
MySQL statement shapes that PHP apps (Sendy among them) send and that SQLite rejects as written. Each was verified over the MySQL wire against rusqlite and Turso:
crates/litewire/tests/mysql_compat_statements.rschecks results and affected-row counts, not the emitted SQL.INSERT ... SELECT ... FROM DUAL WHERE NOT EXISTS (...)FROM DUALdropped. 1 affected row when inserted, 0 when suppressed (mysqli_affected_rowsis branched on). A quoted or aliaseddualis kept as a user tableFORCE/USE/IGNORE INDEX|KEY [FOR JOIN|ORDER BY|GROUP BY] (...)INDEXED BY, which errors when the index is missingFOR UPDATE,FOR SHARE,NOWAIT,SKIP LOCKED,LOCK IN SHARE MODELOCK IN SHARE MODEis stripped before parsing because sqlparser cannot parse it. Single-writer semantics are documented: a double "claim" fails at the second write rather than blockingLIMIT 18446744073709551615 [OFFSET n]/LIMIT n, 18446744073709551615(any literal ≥ 2^63)LIMIT -1ALTER TABLE t ROW_FORMAT=… / ENGINE=… / [DEFAULT] CHARSET … / COLLATE … / AUTO_INCREMENT=… / COMMENT … / CONVERT TO CHARACTER SET … / ENABLE|DISABLE KEYS / FORCE / ALGORITHM= / LOCK=(options only, comma- or space-separated)LEAST/GREATEST/CHAR_LENGTH/CHARACTER_LENGTHmin/max(multi-arg, NULL if any NULL) /lengthFix: the DDL display-width pre-pass and the SELECT-hint pre-pass pushed every byte as a
char, so multi-byte UTF-8 was re-encoded (DEFAULT 'café'was stored as'café', and the same happened to strings in aSELECT SQL_NO_CACHE ...). They also ended a string at a backslash-escaped quote. Both pre-passes now copy byte spans through a shared quote scanner that understands escapes.Docs:
docs/sql-translation.md(MySQL dialect + "what does not work"), CHANGELOG.Local: clippy (default and all features),
+1.88check,cargo test --workspace --all-features. The only failure is the Windows-onlysingle_tenant_attachpath test, which fails onmaintoo.