fix(plugin-mysql): spell string literals for sessions with NO_BACKSLASH_ESCAPES - #3090
Merged
Merged
Conversation
datlechin
force-pushed
the
fix/mysql-null-column-default
branch
from
September 23, 2026 15:35
5520511 to
9f1c9ad
Compare
datlechin
force-pushed
the
fix/mysql-no-backslash-escapes
branch
from
September 23, 2026 15:35
3abeac4 to
765d484
Compare
datlechin
force-pushed
the
fix/mysql-no-backslash-escapes
branch
from
September 23, 2026 15:37
765d484 to
4a30d97
Compare
datlechin
changed the base branch from
fix/mysql-null-column-default
to
main
September 23, 2026 15:37
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.
Problem
The MySQL plugin quoted every string literal as if the session read backslash escapes. A session whose
sql_modeholdsNO_BACKSLASH_ESCAPESreads a backslash as an ordinary character. That mode can come from the server's global setting, from a connection's startup SQL, or from aSETrun in the editor. In such a session every statement the plugin wrote came out wrong:MODIFY COLUMNrestates the whole column, so an edit to one attribute re-sent the default, the comment and the enum members. Every save doubled each backslash and turned each line break into the two characters\n, and did it again on the next save. On MariaDB an expression default holding a quote failed withERROR 1064.u\\vfor a default ofu\v.A second, separate defect: the plugin and the SQL export wrote a form feed as
\f. MySQL and MariaDB have no such escape and read it as the letterf, in any mode.Measured
MySQL 8.4.11 and MariaDB 13.0.2, both modes, every value checked by
HEX():NO_BACKSLASH_ESCAPES'x\\y'storesx\yx\\y'a\nb'storesa, newline,ba\nb'...''it''s'it'sit's'p\fq'pfqp\fqCOMMENT X'5C'ERROR 1064ERROR 1064No spelling of a backslash reads the same both ways, and
COMMENTtakes no hex literal. So the literal has to be spelled for the session.The server prints SQL with backslash escapes whatever the session's mode: in
SHOW CREATE TABLE, in a column's type (ENUM and SET members), in check clauses, in generation expressions, and in MariaDB'sINFORMATION_SCHEMAdefaults.Fix
MySQLLiteralSpellingre-spells a statement for a session that has turned escapes off. It decodes each single-quoted literal the way the server reads it and writes it back with doubled quotes only. Identifiers, double-quoted text and comments are copied unchanged. libmariadb'smysql_real_escape_stringmakes the same choice from the sameSERVER_STATUS_NO_BACKSLASH_ESCAPESflag.execute(ownStatement:)SHOW CREATE TABLE.mysqlEscapeStringLiteraland in the export dialect's escaper. A raw form feed is valid in every dialect that escaper serves.Before / after
A harness compiled the plugin's own sources against both servers in a
NO_BACKSLASH_ESCAPESsession. It re-ran an unchangedMODIFYfor every column, as an edit to another attribute does, then comparedHEX()of what was stored.x\ytox\\y, newline to\n, enuma\btoa\\b, expression doubledERROR 1064`we\ird`, status and row countu\v, commentw\x+ newlineu\\v,w\\x\nyCREATE USERwith passwordp\w'd, then log inERROR 1045f+ form feed +f, default modefffKnown limit
MySQL 8.4 re-parses its own stored text in the session's mode. On a table with an expression default that holds an escaped quote, such as
concat('it''s', ...), the server itself failsSHOW CREATE TABLEand everyALTER TABLEwithERROR 1064underNO_BACKSLASH_ESCAPES, from the stockmysqlclient too. The column read already falls back to the catalog for that table (#3067). Nothing client-side can make theALTERrun. MariaDB is not affected.Tests
MySQLLiteralSpellingTests:\%and\_keeping their backslash%,_and non-ASCIISQLExportDialectTests.mysqlEscaperMatchesTheDriverpinned\ffor a form feed. That was the defect, measured above, so it now expects the raw character.MySQLLiteralSpellingTestsran locally in a scratch package against the plugin files: 11 tests, 24 cases, all pass.TableProTestsdid not run locally. The shared build was stuck behind a stalled package download, so CI is its first run.SQLExportDialectTests.swiftare already onmain.Not changed
The app-side callers of
escapeStringLiteral(SQL export, MCP, the foreign key row lookup) still use the default spelling. An export file has to stay portable, so it cannot follow the session that wrote it. The foreign key lookup runs on the session and would need its own spelling. Reported separately rather than folded in here.