本文整理汇总了Java中com.alibaba.druid.sql.parser.SQLStatementParser.parseStatementList方法的典型用法代码示例。如果您正苦于以下问题:Java SQLStatementParser.parseStatementList方法的具体用法?Java SQLStatementParser.parseStatementList怎么用?Java SQLStatementParser.parseStatementList使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.alibaba.druid.sql.parser.SQLStatementParser
的用法示例。
在下文中一共展示了SQLStatementParser.parseStatementList方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parserSQL
import com.alibaba.druid.sql.parser.SQLStatementParser; //导入方法依赖的package包/类
@Override
public SQLStatement parserSQL(String originSql) throws SQLSyntaxErrorException {
SQLStatementParser parser = new MySqlStatementParser(originSql);
/**
* thrown SQL SyntaxError if parser error
*/
try {
List<SQLStatement> list = parser.parseStatementList();
if (list.size() > 1) {
throw new SQLSyntaxErrorException("MultiQueries is not supported,use single query instead ");
}
return list.get(0);
} catch (Exception t) {
LOGGER.info("routeNormalSqlWithAST", t);
if (t.getMessage() != null) {
throw new SQLSyntaxErrorException(t.getMessage());
} else {
throw new SQLSyntaxErrorException(t);
}
}
}
示例2: getCountSql
import com.alibaba.druid.sql.parser.SQLStatementParser; //导入方法依赖的package包/类
@Override
public String getCountSql(String sql) {
SQLStatementParser parser = new MySqlStatementParser(sql);
List<SQLStatement> stmtList = parser.parseStatementList();
// 将AST通过visitor输出
StringBuilder out = new StringBuilder();
MysqlCountOutputVisitor visitor = new MysqlCountOutputVisitor(out);
for (SQLStatement stmt : stmtList) {
if (stmt instanceof SQLSelectStatement) {
stmt.accept(visitor);
out.append(";");
}
}
return out.toString();
}
示例3: oracleValidationQueryCheck
import com.alibaba.druid.sql.parser.SQLStatementParser; //导入方法依赖的package包/类
private void oracleValidationQueryCheck() {
if (validationQuery == null) {
return;
}
if (validationQuery.length() == 0) {
return;
}
SQLStatementParser sqlStmtParser = SQLParserUtils.createSQLStatementParser(validationQuery, this.dbType);
List<SQLStatement> stmtList = sqlStmtParser.parseStatementList();
if (stmtList.size() != 1) {
return;
}
SQLStatement stmt = stmtList.get(0);
if (!(stmt instanceof SQLSelectStatement)) {
return;
}
SQLSelectQuery query = ((SQLSelectStatement) stmt).getSelect().getQuery();
if (query instanceof SQLSelectQueryBlock) {
if (((SQLSelectQueryBlock) query).getFrom() == null) {
LOG.error("invalid oracle validationQuery. " + validationQuery + ", may should be : " + validationQuery
+ " FROM DUAL");
}
}
}
示例4: db2ValidationQueryCheck
import com.alibaba.druid.sql.parser.SQLStatementParser; //导入方法依赖的package包/类
private void db2ValidationQueryCheck() {
if (validationQuery == null) {
return;
}
if (validationQuery.length() == 0) {
return;
}
SQLStatementParser sqlStmtParser = SQLParserUtils.createSQLStatementParser(validationQuery, this.dbType);
List<SQLStatement> stmtList = sqlStmtParser.parseStatementList();
if (stmtList.size() != 1) {
return;
}
SQLStatement stmt = stmtList.get(0);
if (!(stmt instanceof SQLSelectStatement)) {
return;
}
SQLSelectQuery query = ((SQLSelectStatement) stmt).getSelect().getQuery();
if (query instanceof SQLSelectQueryBlock) {
if (((SQLSelectQueryBlock) query).getFrom() == null) {
LOG.error("invalid db2 validationQuery. " + validationQuery + ", may should be : " + validationQuery
+ " FROM SYSDUMMY");
}
}
}
示例5: parseSql
import com.alibaba.druid.sql.parser.SQLStatementParser; //导入方法依赖的package包/类
private static SQLStatement parseSql(String sql) {
String convertSql = trimPattern.matcher(sql).replaceAll("xtrim");
SQLStatementParser parser = new OracleStatementParser(convertSql);
List<SQLStatement> stmtList;
try {
stmtList = parser.parseStatementList();
} catch (ParserException exception) {
exception.printStackTrace();
throw new RuntimeException(sql + " is invalid, detail " + exception.getMessage());
}
return stmtList.get(0);
}
示例6: sqlValid
import com.alibaba.druid.sql.parser.SQLStatementParser; //导入方法依赖的package包/类
public static void sqlValid(String sql, DataBaseType dataBaseType){
SQLStatementParser statementParser = SQLParserUtils.createSQLStatementParser(sql,dataBaseType.getTypeName());
statementParser.parseStatementList();
}
示例7: testTrimxResult
import com.alibaba.druid.sql.parser.SQLStatementParser; //导入方法依赖的package包/类
@Test
public void testTrimxResult() {
SQLStatementParser parser = new OracleStatementParser(trimxSql);
parser.parseStatementList();
}
示例8: testTrimResultBug
import com.alibaba.druid.sql.parser.SQLStatementParser; //导入方法依赖的package包/类
@Test//(expected = ParserException.class)
// ParserException: syntax error, expect FROM, actual RPAREN CERT_CHECK_RSP_CODE
public void testTrimResultBug() {
SQLStatementParser parser = new OracleStatementParser(trimSql);
parser.parseStatementList();
}