Search in sources :

Example 1 with StringProvider

use of net.sf.jsqlparser.parser.StringProvider in project herddb by diennea.

the class JSQLParserPlanner method parseStatement.

private net.sf.jsqlparser.statement.Statement parseStatement(String query) throws StatementExecutionException {
    net.sf.jsqlparser.statement.Statement stmt;
    CCJSqlParser parser = new CCJSqlParser(new StringProvider(query));
    // parser.setErrorRecovery(true);
    try {
        return parser.Statement();
    } catch (ParseException err) {
        throw new StatementExecutionException("unable to parse query " + query, err);
    }
}
Also used : StringProvider(net.sf.jsqlparser.parser.StringProvider) CCJSqlParser(net.sf.jsqlparser.parser.CCJSqlParser) ParseException(net.sf.jsqlparser.parser.ParseException) StatementExecutionException(herddb.model.StatementExecutionException)

Example 2 with StringProvider

use of net.sf.jsqlparser.parser.StringProvider in project JSqlParser by JSQLParser.

the class StatementsTest method testStatementsErrorRecovery3.

@Test
public void testStatementsErrorRecovery3() throws JSQLParserException, ParseException {
    String sqls = "select * from mytable; select * from;select * from mytable2";
    CCJSqlParser parser = new CCJSqlParser(new StringProvider(sqls));
    parser.setErrorRecovery(true);
    Statements parseStatements = parser.Statements();
    assertEquals(2, parseStatements.getStatements().size());
    assertTrue(parseStatements.getStatements().get(0) instanceof Select);
    assertNull(parseStatements.getStatements().get(1));
    assertEquals(2, parser.getParseErrors().size());
}
Also used : StringProvider(net.sf.jsqlparser.parser.StringProvider) Select(net.sf.jsqlparser.statement.select.Select) CCJSqlParser(net.sf.jsqlparser.parser.CCJSqlParser) Test(org.junit.Test)

Example 3 with StringProvider

use of net.sf.jsqlparser.parser.StringProvider in project JSqlParser by JSQLParser.

the class StatementsTest method testStatementsErrorRecovery2.

@Test
public void testStatementsErrorRecovery2() throws JSQLParserException, ParseException {
    String sqls = "select * from1 table;";
    CCJSqlParser parser = new CCJSqlParser(new StringProvider(sqls));
    parser.setErrorRecovery(true);
    Statements parseStatements = parser.Statements();
    assertEquals(1, parseStatements.getStatements().size());
    assertTrue(parseStatements.getStatements().get(0) instanceof Select);
    assertEquals(1, parser.getParseErrors().size());
}
Also used : StringProvider(net.sf.jsqlparser.parser.StringProvider) Select(net.sf.jsqlparser.statement.select.Select) CCJSqlParser(net.sf.jsqlparser.parser.CCJSqlParser) Test(org.junit.Test)

Example 4 with StringProvider

use of net.sf.jsqlparser.parser.StringProvider in project JSqlParser by JSQLParser.

the class StatementsTest method testStatementsErrorRecovery.

@Test
public void testStatementsErrorRecovery() throws JSQLParserException, ParseException {
    String sqls = "select * from mytable; select * from;";
    CCJSqlParser parser = new CCJSqlParser(new StringProvider(sqls));
    parser.setErrorRecovery(true);
    Statements parseStatements = parser.Statements();
    assertEquals(2, parseStatements.getStatements().size());
    assertTrue(parseStatements.getStatements().get(0) instanceof Select);
    assertNull(parseStatements.getStatements().get(1));
}
Also used : StringProvider(net.sf.jsqlparser.parser.StringProvider) Select(net.sf.jsqlparser.statement.select.Select) CCJSqlParser(net.sf.jsqlparser.parser.CCJSqlParser) Test(org.junit.Test)

Aggregations

CCJSqlParser (net.sf.jsqlparser.parser.CCJSqlParser)4 StringProvider (net.sf.jsqlparser.parser.StringProvider)4 Select (net.sf.jsqlparser.statement.select.Select)3 Test (org.junit.Test)3 StatementExecutionException (herddb.model.StatementExecutionException)1 ParseException (net.sf.jsqlparser.parser.ParseException)1