Skip to content

fix: parse every MySQL character set form of ALTER TABLE CONVERT TO - #2882

Merged
manticore-projects merged 1 commit into
JSQLParser:masterfrom
minleejae:fix/mysql-convert-to-charset-20261031
Oct 31, 2026
Merged

manticore-projects merged 1 commit into
JSQLParser:masterfrom
minleejae:fix/mysql-convert-to-charset-20261031

Conversation

@minleejae

Copy link
Copy Markdown
Contributor

ALTER TABLE … CONVERT TO accepted only CHARACTER SET followed by an unquoted name, and COLLATE only an unquoted name. MySQL accepts the CHARSET abbreviation, CHARACTER SET DEFAULT, the binary character set and quoted names there, and column types already parse the same names, but ALTER TABLE t CONVERT TO CHARSET utf8mb4, … CONVERT TO CHARACTER SET DEFAULT, … CONVERT TO CHARACTER SET binary and … COLLATE 'utf8mb4_bin' failed, with and without the MySQL dialect.

CONVERT TO now reads its character set and collation with the name rule of column types (TypeCharacterSet), which the new CharacterSetName production shares, and also accepts DEFAULT. The new AlterExpression.isUseCharsetKeyword() keeps the CHARSET spelling, as ColDataType.isUseCharsetKeyword() does for columns. CONVERT TO CHARSET, and the DEFAULT CHARSET and CHARSET table options, which parsed before, now print as written instead of as CHARACTER SET.

Public method signatures are retained.

Syntax reference: MySQL 8.4 ALTER TABLE (CONVERT TO), Specifying Character Sets and Collations.

Validation:

  • MySqlConvertToCharacterSetTest adds 12 statements. Each is parsed with and without the MySQL dialect, checked against toString() and the deparser, and parsed inside a script. Further tests check the CHARSET spelling, the character set and collation values, and 4 rejected forms. On master dd03d6ff1, 10 of the 12 fail, and the other 2 (DEFAULT CHARSET utf8mb4, CHARSET = utf8mb4 COLLATE = utf8mb4_bin) print CHARACTER SET.
  • MySQL 8.4.11 accepts all 12 statements and rejects the 4 rejected forms with syntax errors.
  • Java 17 Gradle check: 12,338 tests, 0 failures, 25 skipped. Grammar ambiguity, formatting (Spotless ratchet against upstream/master), Checkstyle, PMD, SpotBugs and JaCoCo pass.

AI assistance: prepared with Claude Code.

CONVERT TO accepted only CHARACTER SET followed by an unquoted name, and
COLLATE only an unquoted name. CONVERT TO CHARSET, CHARACTER SET DEFAULT,
the binary character set and quoted names failed, although MySQL accepts
them all and column types already took the same names.

CONVERT TO now reads its character set and collation with the name rule
of column types, which the new CharacterSetName production shares, and
also accepts DEFAULT. AlterExpression.isUseCharsetKeyword() keeps the
CHARSET spelling, so CONVERT TO CHARSET, DEFAULT CHARSET and CHARSET
table options print as written instead of as CHARACTER SET.

Signed-off-by: minleejae <[email protected]>
@manticore-projects
manticore-projects merged commit 0a5d312 into JSQLParser:master Oct 31, 2026
10 checks passed
@manticore-projects

Copy link
Copy Markdown
Contributor

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants