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));
}
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());
}
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
}
}
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());
}
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);
}
Aggregations