|
36 | 36 | import net.sf.jsqlparser.expression.Alias; |
37 | 37 | import net.sf.jsqlparser.expression.AllValue; |
38 | 38 | import net.sf.jsqlparser.expression.BinaryExpression; |
| 39 | +import net.sf.jsqlparser.expression.CollateExpression; |
39 | 40 | import net.sf.jsqlparser.expression.DoubleValue; |
40 | 41 | import net.sf.jsqlparser.expression.Expression; |
41 | 42 | import net.sf.jsqlparser.expression.Function; |
@@ -4183,6 +4184,38 @@ public void testEscaped() throws JSQLParserException { |
4183 | 4184 | assertSqlCanBeParsedAndDeparsed("SELECT _utf8'testvalue'"); |
4184 | 4185 | } |
4185 | 4186 |
|
| 4187 | + @ParameterizedTest |
| 4188 | + @ValueSource(strings = {"_utf8mb4'testvalue'", "_utf8mb4 'testvalue'", |
| 4189 | + "_utf8 'testvalue'", "_latin1'testvalue'", "_binary'testvalue'", |
| 4190 | + "_ISO8859_1 'testvalue'"}) |
| 4191 | + public void testCharacterSetIntroducedString(String expression) throws JSQLParserException { |
| 4192 | + Select select = (Select) CCJSqlParserUtil.parse("SELECT " + expression); |
| 4193 | + SelectItem<?> selectItem = select.getPlainSelect().getSelectItem(0); |
| 4194 | + StringValue stringValue = assertInstanceOf(StringValue.class, selectItem.getExpression()); |
| 4195 | + |
| 4196 | + assertEquals(expression.substring(0, expression.indexOf('\'')).trim(), |
| 4197 | + stringValue.getPrefix()); |
| 4198 | + assertEquals("testvalue", stringValue.getValue()); |
| 4199 | + assertNull(selectItem.getAlias()); |
| 4200 | + } |
| 4201 | + |
| 4202 | + @Test |
| 4203 | + public void testCharacterSetIntroducedStringWithCollate() throws JSQLParserException { |
| 4204 | + String sql = "SELECT _utf8mb4'some text' COLLATE utf8mb4_unicode_ci AS custom_string"; |
| 4205 | + Select select = (Select) CCJSqlParserUtil.parse(sql); |
| 4206 | + SelectItem<?> selectItem = select.getPlainSelect().getSelectItem(0); |
| 4207 | + CollateExpression collateExpression = |
| 4208 | + assertInstanceOf(CollateExpression.class, selectItem.getExpression()); |
| 4209 | + StringValue stringValue = assertInstanceOf(StringValue.class, |
| 4210 | + collateExpression.getLeftExpression()); |
| 4211 | + |
| 4212 | + assertEquals("_utf8mb4", stringValue.getPrefix()); |
| 4213 | + assertEquals("some text", stringValue.getValue()); |
| 4214 | + assertEquals("utf8mb4_unicode_ci", collateExpression.getCollate()); |
| 4215 | + assertEquals("custom_string", selectItem.getAlias().getName()); |
| 4216 | + assertEquals(sql, select.toString()); |
| 4217 | + } |
| 4218 | + |
4186 | 4219 | @Test |
4187 | 4220 | public void testIssue563MultiSubJoin() throws JSQLParserException { |
4188 | 4221 | assertSqlCanBeParsedAndDeparsed( |
|
0 commit comments