mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
bug fixed for oracle sql parser schemastat visitor
This commit is contained in:
@@ -512,7 +512,11 @@ public class OracleExprParser extends SQLExprParser {
|
||||
if (lexer.token() != Token.FROM) {
|
||||
SQLExpr trim_character = this.primary();
|
||||
trim_character.setParent(methodExpr);
|
||||
methodExpr.putAttribute("trim_character", trim_character);
|
||||
if (trim_character instanceof SQLCharExpr) {
|
||||
methodExpr.putAttribute("trim_character", trim_character);
|
||||
} else {
|
||||
methodExpr.getParameters().add(trim_character);
|
||||
}
|
||||
}
|
||||
|
||||
if (lexer.token() == Token.FROM) {
|
||||
|
||||
+1
-13
@@ -498,19 +498,7 @@ public class OracleSchemaStatVisitor extends SchemaStatVisitor implements Oracle
|
||||
|
||||
@Override
|
||||
public boolean visit(OracleSelectJoin x) {
|
||||
x.getLeft().accept(this);
|
||||
x.getRight().accept(this);
|
||||
|
||||
{
|
||||
String leftTable = (String) x.getLeft().getAttribute(ATTR_TABLE);
|
||||
String rightTable = (String) x.getRight().getAttribute(ATTR_TABLE);
|
||||
if (leftTable != null && leftTable.equals(rightTable)) {
|
||||
x.putAttribute(ATTR_TABLE, leftTable);
|
||||
}
|
||||
}
|
||||
if (x.getCondition() != null) {
|
||||
x.getCondition().accept(this);
|
||||
}
|
||||
super.visit(x);
|
||||
|
||||
for (SQLExpr item : x.getUsing()) {
|
||||
if (item instanceof SQLIdentifierExpr) {
|
||||
|
||||
@@ -736,8 +736,9 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
|
||||
public boolean visit(SQLJoinTableSource x) {
|
||||
x.getLeft().accept(this);
|
||||
x.getRight().accept(this);
|
||||
if (x.getCondition() != null) {
|
||||
x.getCondition().accept(this);
|
||||
SQLExpr condition = x.getCondition();
|
||||
if (condition != null) {
|
||||
condition.accept(this);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.alibaba.druid.bvt.sql.schemaStat;
|
||||
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.parser.SQLParserUtils;
|
||||
import com.alibaba.druid.sql.parser.SQLStatementParser;
|
||||
import com.alibaba.druid.sql.visitor.SchemaStatVisitor;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Assert;
|
||||
|
||||
public class SchemaStatTest8 extends TestCase {
|
||||
|
||||
public void test_schemaStat() throws Exception {
|
||||
String sql = "SELECT * FROM AQLQCAT " +
|
||||
"JOIN AQLQCATB " +
|
||||
" ON AQLQCAT.ZZ = AQLQCATB.RR " +
|
||||
" AND trim(AQLQCAT.BB) = AQLQCATB.DD " +
|
||||
"WHERE AQLQCAT.MANDT = 'A0' " +
|
||||
" AND AQLQCATB.NUM = 'A1'";
|
||||
|
||||
String dbType = JdbcConstants.ORACLE;
|
||||
SQLStatementParser parser = SQLParserUtils.createSQLStatementParser(sql, dbType);
|
||||
SQLStatement stmt = parser.parseStatementList().get(0);
|
||||
|
||||
SchemaStatVisitor statVisitor = SQLUtils.createSchemaStatVisitor(dbType);
|
||||
stmt.accept(statVisitor);
|
||||
|
||||
// System.out.println(statVisitor.getColumns());
|
||||
// System.out.println(statVisitor.getGroupByColumns()); // group by
|
||||
System.out.println("relationships : " + statVisitor.getRelationships()); // group by
|
||||
|
||||
Assert.assertEquals(6, statVisitor.getColumns().size());
|
||||
Assert.assertEquals(6, statVisitor.getConditions().size());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user