Search in sources :

Example 91 with ParserException

use of com.alibaba.druid.sql.parser.ParserException in project druid by alibaba.

the class MySqlSelectTest_plus_sub_comment method test_6.

public void test_6() throws Exception {
    String sql = "select  1 ---++-- 1 ";
    try {
        MySqlStatementParser parser = new MySqlStatementParser(sql);
        List<SQLStatement> statementList = parser.parseStatementList();
        SQLSelectStatement stmt = (SQLSelectStatement) statementList.get(0);
        fail();
    } catch (Exception e) {
        assertTrue(e instanceof ParserException);
    }
}
Also used : ParserException(com.alibaba.druid.sql.parser.ParserException) SQLSelectStatement(com.alibaba.druid.sql.ast.statement.SQLSelectStatement) MySqlStatementParser(com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement) ParserException(com.alibaba.druid.sql.parser.ParserException)

Example 92 with ParserException

use of com.alibaba.druid.sql.parser.ParserException in project druid by alibaba.

the class MySqlSelectTest_plus_sub_comment method test_16.

public void test_16() throws Exception {
    String sql = "select max(id)  --+--  min(id) from test_tablesl";
    try {
        MySqlStatementParser parser = new MySqlStatementParser(sql);
        List<SQLStatement> statementList = parser.parseStatementList();
        SQLSelectStatement stmt = (SQLSelectStatement) statementList.get(0);
        fail();
    } catch (Exception e) {
        assertTrue(e instanceof ParserException);
    }
}
Also used : ParserException(com.alibaba.druid.sql.parser.ParserException) SQLSelectStatement(com.alibaba.druid.sql.ast.statement.SQLSelectStatement) MySqlStatementParser(com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement) ParserException(com.alibaba.druid.sql.parser.ParserException)

Example 93 with ParserException

use of com.alibaba.druid.sql.parser.ParserException in project druid by alibaba.

the class MySqlSelectTest_plus_sub_comment method test_13.

public void test_13() throws Exception {
    String sql = "select max(id) --- min(id) from test_tablesl";
    try {
        MySqlStatementParser parser = new MySqlStatementParser(sql);
        List<SQLStatement> statementList = parser.parseStatementList();
        SQLSelectStatement stmt = (SQLSelectStatement) statementList.get(0);
        fail();
    } catch (Exception e) {
        assertTrue(e instanceof ParserException);
    }
}
Also used : ParserException(com.alibaba.druid.sql.parser.ParserException) SQLSelectStatement(com.alibaba.druid.sql.ast.statement.SQLSelectStatement) MySqlStatementParser(com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement) ParserException(com.alibaba.druid.sql.parser.ParserException)

Example 94 with ParserException

use of com.alibaba.druid.sql.parser.ParserException in project druid by alibaba.

the class OdpsLexerTest method test_error_0.

public void test_error_0() throws Exception {
    String str = "1 `aaa\n${PN}_events";
    OdpsLexer lexer = new OdpsLexer(str);
    lexer.nextToken();
    assertEquals(Token.LITERAL_INT, lexer.token());
    int pos = lexer.pos();
    try {
        lexer.nextToken();
    } catch (ParserException error) {
        lexer.skipToNextLineOrParameter(pos);
        lexer.nextToken();
    }
    assertEquals(Token.IDENTIFIER, lexer.token());
    assertEquals("${PN}_events", lexer.stringVal());
}
Also used : ParserException(com.alibaba.druid.sql.parser.ParserException) OdpsLexer(com.alibaba.druid.sql.dialect.odps.parser.OdpsLexer)

Example 95 with ParserException

use of com.alibaba.druid.sql.parser.ParserException in project druid by alibaba.

the class AntlrExamplesTest method test_for_antlr_examples.

public void test_for_antlr_examples() throws Exception {
    String path = "bvt/parser/antlr_grammers_v4_plsql/examples/";
    URL resource = Thread.currentThread().getContextClassLoader().getResource(path);
    File dir = new File(resource.getFile());
    for (File file : dir.listFiles()) {
        System.out.println(file);
        String sql = FileUtils.readFileToString(file);
        try {
            SQLUtils.parseStatements(sql, JdbcConstants.ORACLE);
        } catch (ParserException ex) {
            System.out.println(sql);
            throw ex;
        }
    }
}
Also used : ParserException(com.alibaba.druid.sql.parser.ParserException) File(java.io.File) URL(java.net.URL)

Aggregations

ParserException (com.alibaba.druid.sql.parser.ParserException)98 SQLExpr (com.alibaba.druid.sql.ast.SQLExpr)25 SQLStatement (com.alibaba.druid.sql.ast.SQLStatement)18 SQLName (com.alibaba.druid.sql.ast.SQLName)16 MySqlStatementParser (com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser)12 SQLIdentifierExpr (com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr)10 SQLSelectStatement (com.alibaba.druid.sql.ast.statement.SQLSelectStatement)9 Token (com.alibaba.druid.sql.parser.Token)9 SQLCommentHint (com.alibaba.druid.sql.ast.SQLCommentHint)5 SQLCharExpr (com.alibaba.druid.sql.ast.expr.SQLCharExpr)5 SQLIntegerExpr (com.alibaba.druid.sql.ast.expr.SQLIntegerExpr)5 SQLSelect (com.alibaba.druid.sql.ast.statement.SQLSelect)5 SQLOrderBy (com.alibaba.druid.sql.ast.SQLOrderBy)4 SQLBinaryOpExpr (com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr)4 SQLVariantRefExpr (com.alibaba.druid.sql.ast.expr.SQLVariantRefExpr)4 MySqlSelectQueryBlock (com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock)4 OracleConstraint (com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleConstraint)4 DbType (com.alibaba.druid.DbType)3 SQLDeclareItem (com.alibaba.druid.sql.ast.SQLDeclareItem)3 SQLPartitionByHash (com.alibaba.druid.sql.ast.SQLPartitionByHash)3