QueryParserImpl extends SQLParserBaseListener implements QueryParser, SelectQueryAware { @Override public void parse(String sql) throws SQLSyntaxErrorException { try { CharStream input = new CaseInsensitiveInputStream(sql); ANTLRErrorListener errorListener = new InternalErrorListener(); SQLLexer sqlLexer = new SQLLexer(input); sqlLexer.removeErrorListeners(); sqlLexer.addErrorListener(errorListener); CommonTokenStream commonTokenStream = new CommonTokenStream(sqlLexer); SQLParser sqlParser = new SQLParser(commonTokenStream); sqlParser.removeErrorListeners(); sqlParser.addErrorListener(errorListener); ParseTree parseTree = sqlParser.query(); ParseTreeWalker walker = new ParseTreeWalker(); walker.walk(this, parseTree); } catch (ParseException e) { errors.add(e.getMessage()); } if (!errors.isEmpty()) { String message = errors.stream().collect(Collectors.joining("; ")); throw new SQLSyntaxErrorException(message); } } @Autowired  QueryParserImpl(TablesAware tablesAware); @Override void parse(String sql); @Override SelectQueryAware getSelectQueryAware(); @Override QueryType getQueryType(); @Override void exitExplain_query(SQLParser.Explain_queryContext ctx); @Override void exitSelect_clause(SQLParser.Select_clauseContext ctx); @Override void exitFrom_clause(SQLParser.From_clauseContext ctx); @Override void exitWhere_clause(SQLParser.Where_clauseContext ctx); @Override void exitQuery(SQLParser.QueryContext ctx); @Override void exitHaving_clause(SQLParser.Having_clauseContext ctx); @Override void exitGroup_clause(SQLParser.Group_clauseContext ctx); @Override void exitOrder_clause(SQLParser.Order_clauseContext ctx); @Override void exitLimit_clause(SQLParser.Limit_clauseContext ctx); @Override Map<String, Object> getSelectionMap(); @Override Optional<DataSource> getDataSource(); @Override Map<String, String> getTableAliases(); @Override Map<String, List<String>> getAvailableColumns(); @Override Optional<BooleanExpression> getWhereExpression(); @Override List<Object> getGroupByExpressions(); @Override List<OrderExpression> getOrderByExpressions(); @Override Optional<BooleanExpression> getHavingExpression(); @Override Optional<Integer> getLimitCount(); @Override Optional<Integer> getLimitOffset();  }
@Test(expected = SQLSyntaxErrorException.class) public void testWeirdStuff() throws Exception { parse("some weird stuff"); }
@Test(expected = SQLSyntaxErrorException.class) public void testWrongLimit() throws Exception { parse("select * from instances limit -1"); }
@Test(expected = SQLSyntaxErrorException.class) public void testWrongOffset() throws Exception { parse("select * from instances limit -1, 5"); }
@Test(expected = SQLSyntaxErrorException.class) public void testMissingTableAliasInColumnName() throws Exception { parse("select missing.id from instances"); }
@Test(expected = SQLSyntaxErrorException.class) public void testDuplicateTableAlias() throws Exception { parse("select * from instances as i, projects as i"); }
@Test(expected = SQLSyntaxErrorException.class) public void testMissingColumn() throws Exception { parse("select missing_column from instances"); }
@Test(expected = SQLSyntaxErrorException.class) public void testMissingTable() throws Exception { parse("select name from missing_table"); }
@Test(expected = SQLSyntaxErrorException.class) public void testMissingAliasesColumn() throws Exception { parse("select i.missing_column from instances as i"); }
@Test(expected = SQLSyntaxErrorException.class) public void testAmbiguousColumn() throws Exception { parse("select id from instances, projects"); }
@Test(expected = SQLSyntaxErrorException.class) public void testInvalidSelectAllFromTable() throws Exception { parse("select id from instances where instances.* = 'test'"); }
@Test(expected = SQLSyntaxErrorException.class) public void testInvalidSelectAll() throws Exception { parse("select id from instances where * = 'test'"); }