Search in sources :

Example 86 with ParserException

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

the class PagerUtilsTest_Limit_mysql_question_placeholder method testQuestionLimitPlaceholderInternal.

private void testQuestionLimitPlaceholderInternal(String sql) {
    List<SQLStatement> statements;
    try {
        statements = SQLUtils.parseStatements(sql, JdbcConstants.MYSQL);
    } catch (ParserException e) {
        Assert.fail(e.getMessage());
        return;
    }
    if (statements == null || statements.size() == 0) {
        Assert.fail("no sql found!");
        return;
    }
    if (statements.size() != 1) {
        Assert.fail("sql not support count : " + sql);
        return;
    }
    SQLSelectStatement statement = (SQLSelectStatement) statements.get(0);
    if (!(statement instanceof SQLSelectStatement)) {
        Assert.fail("sql not support count : " + sql);
        return;
    }
    SQLSelect select = statement.getSelect();
    PagerUtils.limit(select, JdbcConstants.MYSQL, 0, 200, true);
    SQLUtils.FormatOption options = new SQLUtils.FormatOption();
    options.setPrettyFormat(false);
    options.setUppCase(false);
    assertEquals(sql, SQLUtils.toSQLString(select, JdbcConstants.MYSQL, options));
}
Also used : ParserException(com.alibaba.druid.sql.parser.ParserException) SQLSelect(com.alibaba.druid.sql.ast.statement.SQLSelect) SQLSelectStatement(com.alibaba.druid.sql.ast.statement.SQLSelectStatement) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement) SQLUtils(com.alibaba.druid.sql.SQLUtils)

Example 87 with ParserException

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

the class HiveCreateTableTest_24 method test_1_error.

public void test_1_error() throws Exception {
    // 
    String sql = "create table aliyun_cdm.test_905_table \n" + // 
    "(col1 BIGINT,col2 STRING,col3 BOOLEAN,col4 DOUBLE,col5 DATETIME) row format delimited field terminated by \"\\\\001\"\n";
    Exception error = null;
    try {
        SQLUtils.toStatementList(sql, JdbcConstants.HIVE);
    } catch (ParserException ex) {
        error = ex;
    }
    assertNotNull(error);
    assertEquals("syntax error, expect FIELDS, pos 131, line 2, column 88, token IDENTIFIER field", error.getMessage());
}
Also used : ParserException(com.alibaba.druid.sql.parser.ParserException) ParserException(com.alibaba.druid.sql.parser.ParserException)

Example 88 with ParserException

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

the class MySqlAlterTableTest54 method test_4.

public void test_4() throws Exception {
    String sql = "alter table event_log hot_partition_count = 'abc';";
    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 89 with ParserException

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

the class MySqlCreateTableTest108_error method test_0.

public void test_0() throws Exception {
    String sql = "create table t (\n" + "f0 int,\n" + "delete int" + ");";
    Exception error = null;
    try {
        SQLUtils.parseStatements(sql, DbType.mysql);
    } catch (ParserException ex) {
        error = ex;
    }
    assertNotNull(error);
    assertEquals("illegal name, pos 31, line 3, column 2, token DELETE", error.getMessage());
}
Also used : ParserException(com.alibaba.druid.sql.parser.ParserException) ParserException(com.alibaba.druid.sql.parser.ParserException)

Example 90 with ParserException

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

the class MySqlSelectTest_95_error_orderBy method test_0.

public void test_0() throws Exception {
    String sql = "select * from xx ordor by name desc";
    Exception error = null;
    try {
        MySqlStatementParser parser = new MySqlStatementParser(sql);
        List<SQLStatement> statementList = parser.parseStatementList();
    } catch (ParserException ex) {
        error = ex;
        ex.printStackTrace();
    }
    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)

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