Skip to content

feat: support MySQL ASCII and UNICODE character set shorthands - #2684

Open
minleejae wants to merge 1 commit into
JSQLParser:masterfrom
minleejae:feat/mysql-character-set-shorthands
Open

minleejae wants to merge 1 commit into
JSQLParser:masterfrom
minleejae:feat/mysql-character-set-shorthands

Conversation

@minleejae

@minleejae minleejae commented Sep 23, 2026

Copy link
Copy Markdown
Contributor

MySQL accepts CAST('ab' AS CHAR(10) ASCII) and JSON_VALUE(j, '$.v' RETURNING CHAR(10) UNICODE), including generated-column expressions. These currently fail in ColDataType. Recognize the shorthand attributes when Dialect.MYSQL is selected, without reserving new keywords.

Refactor character-set spelling into ColDataType.CharacterSetSyntax (CHARACTER_SET, CHARSET, ASCII, UNICODE), retaining the existing isUseCharsetKeyword()/setUseCharsetKeyword() API. getCharacterSet() exposes latin1 for ASCII and ucs2 for UNICODE, while rendering preserves the shorthand. Updating the character set switches a shorthand to an explicit clause; equality and hashing include the spelling.

Example:

ColDataType type = new ColDataType("CHAR").addArgumentsStringList("10")
        .withCharacterSetSyntax(ColDataType.CharacterSetSyntax.ASCII);
// type.getCharacterSet() is "latin1"; type.toString() is "CHAR (10) ASCII"
type.setCharacterSet("utf8mb4"); // renders CHAR (10) CHARACTER SET utf8mb4

Validation: ./gradlew check passed. Tests cover CAST, JSON_VALUE, generated and ordinary columns, construction and edits, equality, dialect boundaries, legacy CHARSET methods, both renderers and reparsing. Ten reproductions were executed on MySQL 8.4.11 before and after rendering, with identical results.

Reference: MySQL character-set shorthand in CAST.

Combined validation with #2682, #2683, #2684, #2685 and #2686: all five changes merge without conflicts; the integrated ./gradlew check passes (8,190 tests, 25 skipped). All 254 MySQL 8.4.11 fixtures parse, render and reparse, and execute with results identical to the original SQL.

Signed-off-by: minleejae <mmj9808@gmail.com>

This branch has not been deployed

No deployments
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.

1 participant