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