Validation with SQL with Brackets #1294
-
Hi all, Is there a possibility to validate the SQL also with brackets? I was trying this, but it´s not working:
Any suggestions? |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 1 reply
-
Greetings. please double check your I would expected, that all your set DatabaseTypes would not validate that statement. |
Beta Was this translation helpful? Give feedback.
-
Thanks for your quick reply. I´m not 100% sure what you mean: I´ve got the same error message. |
Beta Was this translation helpful? Give feedback.
-
A correct validation for your example would look like this String expression = "Select year([x.test]) FROM x";
Statement statement =
CCJSqlParserUtil.parse(expression, parser -> parser.withSquareBracketQuotation(true));
Select selectStatement = (Select) statement;
// validate statement if it's valid for all given databases.
Validation validation =
new Validation(Arrays.asList(DatabaseType.SQLSERVER), selectStatement.toString());
List<ValidationError> errors = validation.validate();
assertEquals(0, errors.size()); Pay attention to the Although this still fails. @wumpz would you please like to clarify how this is supposed to work correctly? |
Beta Was this translation helpful? Give feedback.
-
This works: @Test
public void test() throws JSQLParserException {
String sqlStr = "Select year([x].[test]) FROM x";
FeatureConfiguration features = new FeatureConfiguration();
features.setValue(Feature.allowSquareBracketQuotation, true);
Validation validation =
new Validation(features, Arrays.asList(DatabaseType.SQLSERVER), sqlStr);
List<ValidationError> errors = validation.validate();
assertEquals(0, errors.size());
} |
Beta Was this translation helpful? Give feedback.
-
oh, great. Thank you so much |
Beta Was this translation helpful? Give feedback.
This works: