File tree Expand file tree Collapse file tree
main/jjtree/net/sf/jsqlparser/parser
test/java/net/sf/jsqlparser/expression Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -11410,12 +11410,14 @@ ColDataType DataType():
1141011410 ( tk=<K_DATETIMELITERAL> | tk=<DT_ZONE> | tk = <DATA_TYPE> | tk = <K_SIGNED> | tk = <K_UNSIGNED>
1141111411 | tk=<K_CHARACTER> | tk=<K_BIT> | tk=<K_BYTES> | tk=<K_BINARY> | tk=<K_BOOLEAN>
1141211412 | tk=<K_CHAR> | tk=<K_JSON> | tk=<K_STRING> ) { type = tk.image; }
11413- [
11414- // MySQL seems to allow: INT UNSIGNED
11415- LOOKAHEAD(2) ( LOOKAHEAD(2) ( tk = <DATA_TYPE> | tk = <K_SIGNED> | tk = <K_UNSIGNED>
11416- | tk=<K_CHARACTER> | tk=<K_BIT> | tk=<K_BYTES> | tk=<K_BINARY> | tk=<K_BOOLEAN>
11417- | tk=<K_CHAR> | tk=<K_JSON> | tk=<K_STRING> ) { type += " " + tk.image; } )+
11418- ]
11413+ (
11414+ // MySQL seems to allow: INT UNSIGNED. Do not consume CHARACTER when it starts
11415+ // the trailing CHARACTER SET clause of a character type.
11416+ LOOKAHEAD(2, { getToken(1).kind != K_CHARACTER || getToken(2).kind != K_SET })
11417+ ( tk = <DATA_TYPE> | tk = <K_SIGNED> | tk = <K_UNSIGNED>
11418+ | tk=<K_CHARACTER> | tk=<K_BIT> | tk=<K_BYTES> | tk=<K_BINARY> | tk=<K_BOOLEAN>
11419+ | tk=<K_CHAR> | tk=<K_JSON> | tk=<K_STRING> ) { type += " " + tk.image; }
11420+ )*
1141911421 [
1142011422 LOOKAHEAD(2) "(" ( tk=<S_LONG> { precision = Integer.valueOf(tk.image); } | tk=<K_MAX> { precision = Integer.MAX_VALUE; } )
1142111423 [ <K_BYTE> | <K_CHAR> ]
Original file line number Diff line number Diff line change @@ -68,6 +68,21 @@ void testImplicitCastDoublePrecisionIssue1344() throws JSQLParserException {
6868 Assertions .assertTrue (select .getSelectItem (0 ).getExpression () instanceof CastExpression );
6969 }
7070
71+ @ Test
72+ void testCastCharWithCharacterSet () throws JSQLParserException {
73+ String sqlStr = "SELECT CAST('abc' AS CHAR CHARACTER SET utf8mb4)" ;
74+ PlainSelect select = (PlainSelect ) assertSqlCanBeParsedAndDeparsed (sqlStr , true );
75+ CastExpression castExpression = Assertions .assertInstanceOf (CastExpression .class ,
76+ select .getSelectItem (0 ).getExpression ());
77+
78+ Assertions .assertEquals ("CHAR" , castExpression .getColDataType ().getDataType ());
79+ Assertions .assertEquals ("utf8mb4" , castExpression .getColDataType ().getCharacterSet ());
80+
81+ assertSqlCanBeParsedAndDeparsed (
82+ "SELECT CAST('abc' AS CHAR(10) CHARACTER SET utf8mb4)" , true );
83+ assertSqlCanBeParsedAndDeparsed ("SELECT CAST('abc' AS CHARACTER VARYING)" , true );
84+ }
85+
7186
7287 @ Test
7388 public void testCastToSigned () throws JSQLParserException {
You can’t perform that action at this time.
0 commit comments