mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
add test resource.
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
package com.alibaba.druid.demo.sql;
|
||||
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLUnionQuery;
|
||||
import com.alibaba.druid.sql.dialect.db2.ast.stmt.DB2SelectQueryBlock;
|
||||
import com.alibaba.druid.sql.dialect.db2.visitor.DB2ASTVisitorAdapter;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Issue2038 extends TestCase {
|
||||
public void test_for_demo() throws Exception {
|
||||
String sql = "select * from (select * from t union all select * from t1 union all select * from t3) xx";
|
||||
|
||||
List<SQLStatement> stmtList = SQLUtils.parseStatements(sql, JdbcConstants.DB2);
|
||||
|
||||
|
||||
SQLASTVisitor visitor = new DB2ASTVisitorAdapter() {
|
||||
public boolean visit(SQLUnionQuery x) {
|
||||
System.out.println("union");
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean visit(DB2SelectQueryBlock x) {
|
||||
System.out.println("select");
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
for (SQLStatement stmt : stmtList) {
|
||||
stmt.accept(visitor);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.alibaba.druid.demo.sql;
|
||||
|
||||
import com.alibaba.druid.sql.dialect.oracle.parser.OracleLexer;
|
||||
import com.alibaba.druid.sql.parser.Token;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class OracleCompatibleTest extends TestCase {
|
||||
public void test_compatibleTest() throws Exception {
|
||||
String sql = "select * from t where rownum < 10"; //oracle ppas
|
||||
OracleLexer lexer = new OracleLexer(sql);
|
||||
for (;;) {
|
||||
lexer.nextToken();
|
||||
Token token = lexer.token();
|
||||
if (token == Token.EOF) {
|
||||
break;
|
||||
}
|
||||
if (token == Token.IDENTIFIER) {
|
||||
|
||||
System.out.println(lexer.stringVal());
|
||||
} else if (token == Token.LITERAL_CHARS
|
||||
|| token == Token.LITERAL_INT
|
||||
|| token == Token.LITERAL_ALIAS) {
|
||||
// skip
|
||||
}
|
||||
System.out.println(token);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user