Search in sources :

Example 41 with ParserException

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

the class SqlParams method evaluate.

public String evaluate(String sql, String dbTypeName, boolean throwError) {
    try {
        DbType dbType = dbTypeName == null ? null : DbType.valueOf(dbTypeName);
        List<Object> outParameters = new ArrayList<Object>();
        ParameterizedOutputVisitorUtils.parameterize(sql, dbType, outParameters);
        return JSONUtils.toJSONString(outParameters);
    } catch (ParserException ex) {
        if (throwError) {
            throw new IllegalArgumentException("error sql : \n" + sql, ex);
        }
        return null;
    }
}
Also used : ParserException(com.alibaba.druid.sql.parser.ParserException) ArrayList(java.util.ArrayList) DbType(com.alibaba.druid.DbType)

Example 42 with ParserException

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

the class SqlSyntaxCheck method evaluate.

public Boolean evaluate(String sql, String dbTypeName, boolean throwError) {
    if (sql == null || sql.length() == 0) {
        return null;
    }
    DbType dbType = dbTypeName == null ? null : DbType.valueOf(dbTypeName);
    try {
        SQLStatementParser parser = SQLParserUtils.createSQLStatementParser(sql, dbType);
        List<SQLStatement> statementList = parser.parseStatementList();
        return true;
    } catch (ParserException ex) {
        if (throwError) {
            throw new IllegalArgumentException("error sql : \n" + sql, ex);
        }
        return false;
    }
}
Also used : ParserException(com.alibaba.druid.sql.parser.ParserException) SQLStatementParser(com.alibaba.druid.sql.parser.SQLStatementParser) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement) DbType(com.alibaba.druid.DbType)

Example 43 with ParserException

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

the class MySqlGrantTest_36 method test_error.

public void test_error() throws Exception {
    String sql = "GRANT DELETE, CREATE, DROP ON *.* TO 'oa_2'@% with grant option";
    Exception error = null;
    try {
        SQLUtils.parseSingleMysqlStatement(sql);
    } catch (ParserException ex) {
        error = ex;
    }
    assertNotNull(error);
}
Also used : ParserException(com.alibaba.druid.sql.parser.ParserException) ParserException(com.alibaba.druid.sql.parser.ParserException)

Example 44 with ParserException

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

the class MySqlGrantTest_36 method test_error_2.

public void test_error_2() throws Exception {
    String sql = "GRANT DELETE, CREATE, DROP ON *.* TO 'oa_2'@127.0.0.1 with grant option";
    Exception error = null;
    try {
        SQLUtils.parseSingleMysqlStatement(sql);
    } catch (ParserException ex) {
        error = ex;
    }
    assertNotNull(error);
}
Also used : ParserException(com.alibaba.druid.sql.parser.ParserException) ParserException(com.alibaba.druid.sql.parser.ParserException)

Example 45 with ParserException

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

the class MySqlGrantTest_36 method test_error_1.

public void test_error_1() throws Exception {
    String sql = "GRANT DELETE, CREATE, DROP ON *.* TO 'oa_2'@@ with grant option";
    Exception error = null;
    try {
        SQLUtils.parseSingleMysqlStatement(sql);
    } catch (ParserException ex) {
        error = ex;
    }
    assertNotNull(error);
}
Also used : ParserException(com.alibaba.druid.sql.parser.ParserException) ParserException(com.alibaba.druid.sql.parser.ParserException)

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