Search in sources :

Example 46 with ParserException

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

the class MySqlSelectTest_171_multi_error method test_0.

public void test_0() throws Exception {
    String sql = "select 1 select 2";
    Exception error = null;
    try {
        SQLUtils.parseStatements(sql, JdbcConstants.MYSQL);
    } catch (ParserException e) {
        error = e;
    }
    assertNotNull(error);
}
Also used : ParserException(com.alibaba.druid.sql.parser.ParserException) ParserException(com.alibaba.druid.sql.parser.ParserException)

Example 47 with ParserException

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

the class MySqlSelectTest_94_error method test_0.

public void test_0() throws Exception {
    String sql = "select * from ttt where exist (select max(id) from ttt);";
    Exception error = null;
    try {
        MySqlStatementParser parser = new MySqlStatementParser(sql);
        List<SQLStatement> statementList = parser.parseStatementList();
    } catch (ParserException ex) {
        error = ex;
    }
    assertNotNull(error);
}
Also used : ParserException(com.alibaba.druid.sql.parser.ParserException) MySqlStatementParser(com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement) ParserException(com.alibaba.druid.sql.parser.ParserException)

Example 48 with ParserException

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

the class OracleCreateTableParser method parseOrganization.

private void parseOrganization(OracleCreateTableStatement stmt) {
    OracleCreateTableStatement.Organization organization = new OracleCreateTableStatement.Organization();
    acceptIdentifier("ORGANIZATION");
    if (lexer.token() == Token.INDEX) {
        lexer.nextToken();
        organization.setType("INDEX");
        this.getExprParser().parseSegmentAttributes(organization);
        // index_org_table_clause http://docs.oracle.com/cd/B19306_01/server.102/b14200/statements_7002.htm#i2129638
        if (lexer.identifierEquals(FnvHash.Constants.PCTTHRESHOLD)) {
            lexer.nextToken();
            if (lexer.token() == Token.LITERAL_INT) {
                int pctthreshold = ((SQLNumericLiteralExpr) this.exprParser.primary()).getNumber().intValue();
                organization.setPctthreshold(pctthreshold);
            }
        }
    } else if (lexer.identifierEquals("HEAP")) {
        lexer.nextToken();
        organization.setType("HEAP");
        this.getExprParser().parseSegmentAttributes(organization);
    } else if (lexer.identifierEquals("EXTERNAL")) {
        lexer.nextToken();
        organization.setType("EXTERNAL");
        accept(Token.LPAREN);
        if (lexer.identifierEquals("TYPE")) {
            lexer.nextToken();
            organization.setExternalType(this.exprParser.name());
        }
        accept(Token.DEFAULT);
        acceptIdentifier("DIRECTORY");
        organization.setExternalDirectory(this.exprParser.expr());
        if (lexer.identifierEquals("ACCESS")) {
            lexer.nextToken();
            acceptIdentifier("PARAMETERS");
            if (lexer.token() == Token.LPAREN) {
                lexer.nextToken();
                SQLExternalRecordFormat recordFormat = new SQLExternalRecordFormat();
                if (lexer.identifierEquals("RECORDS")) {
                    lexer.nextToken();
                    if (lexer.identifierEquals("DELIMITED")) {
                        lexer.nextToken();
                        accept(Token.BY);
                        if (lexer.identifierEquals("NEWLINE")) {
                            lexer.nextToken();
                            recordFormat.setDelimitedBy(new SQLIdentifierExpr("NEWLINE"));
                        } else {
                            throw new ParserException("TODO " + lexer.info());
                        }
                        if (lexer.identifierEquals(FnvHash.Constants.NOLOGFILE)) {
                            lexer.nextToken();
                            recordFormat.setLogfile(false);
                        }
                        if (lexer.identifierEquals(FnvHash.Constants.NOBADFILE)) {
                            lexer.nextToken();
                            recordFormat.setBadfile(false);
                        }
                    } else {
                        throw new ParserException("TODO " + lexer.info());
                    }
                }
                if (lexer.identifierEquals(FnvHash.Constants.FIELDS)) {
                    lexer.nextToken();
                    if (lexer.identifierEquals(FnvHash.Constants.TERMINATED)) {
                        lexer.nextToken();
                        accept(Token.BY);
                        recordFormat.setTerminatedBy(this.exprParser.primary());
                    } else {
                        throw new ParserException("TODO " + lexer.info());
                    }
                    if (lexer.identifierEquals(FnvHash.Constants.LTRIM)) {
                        lexer.nextToken();
                        recordFormat.setLtrim(true);
                    }
                }
                if (lexer.identifierEquals(FnvHash.Constants.MISSING)) {
                    lexer.nextToken();
                    acceptIdentifier("FIELD");
                    accept(Token.VALUES);
                    acceptIdentifier("ARE");
                    accept(Token.NULL);
                    recordFormat.setMissingFieldValuesAreNull(true);
                }
                if (lexer.token() == Token.REJECT) {
                    lexer.nextToken();
                    acceptIdentifier("ROWS");
                    accept(Token.WITH);
                    accept(Token.ALL);
                    accept(Token.NULL);
                    acceptIdentifier("FIELDS");
                    recordFormat.setRejectRowsWithAllNullFields(true);
                }
                organization.setExternalDirectoryRecordFormat(recordFormat);
                accept(Token.RPAREN);
            } else if (lexer.token() == Token.USING) {
                lexer.nextToken();
                acceptIdentifier("CLOB");
                throw new ParserException("TODO " + lexer.info());
            }
        }
        acceptIdentifier("LOCATION");
        accept(Token.LPAREN);
        this.exprParser.exprList(organization.getExternalDirectoryLocation(), organization);
        accept(Token.RPAREN);
        accept(Token.RPAREN);
        if (lexer.token() == Token.REJECT) {
            lexer.nextToken();
            accept(Token.LIMIT);
            organization.setExternalRejectLimit(this.exprParser.primary());
        }
    // 
    } else {
        throw new ParserException("TODO " + lexer.info());
    }
    stmt.setOrganization(organization);
}
Also used : ParserException(com.alibaba.druid.sql.parser.ParserException) SQLExternalRecordFormat(com.alibaba.druid.sql.ast.statement.SQLExternalRecordFormat) SQLIdentifierExpr(com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr)

Example 49 with ParserException

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

the class MySqlAlterTableTest54 method test_5.

public void test_5() throws Exception {
    String sql = "alter table event_log hot_partition_count = '10';";
    MySqlStatementParser parser = new MySqlStatementParser(sql);
    try {
        SQLStatement stmt = parser.parseStatementList().get(0);
        fail();
    } catch (ParserException e) {
    // do nothing
    }
}
Also used : ParserException(com.alibaba.druid.sql.parser.ParserException) MySqlStatementParser(com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement)

Example 50 with ParserException

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

the class MySqlSelectTest_298 method test_x1.

public void test_x1() throws Exception {
    String sql = "`default`.`row_number`() OVER (PARTITION BY `field` ORDER BY `field` ASC)";
    SQLExprParser parser = SQLParserUtils.createExprParser(sql, DbType.mysql);
    parser.config(SQLParserFeature.KeepNameQuotes, true);
    parser.config(SQLParserFeature.PipesAsConcat, true);
    parser.config(SQLParserFeature.EnableSQLBinaryOpExprGroup, true);
    SQLExpr expr = parser.expr();
    if (parser.getLexer().token() != com.alibaba.druid.sql.parser.Token.EOF) {
        throw new ParserException("illegal sql expr : " + sql + ", " + parser.getLexer().info());
    }
}
Also used : ParserException(com.alibaba.druid.sql.parser.ParserException) SQLExprParser(com.alibaba.druid.sql.parser.SQLExprParser) SQLExpr(com.alibaba.druid.sql.ast.SQLExpr)

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