mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
refactor sql parser about the desc and explain parts of the code
This commit is contained in:
@@ -3929,4 +3929,23 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean visit(SQLDescribeStatement x) {
|
||||
print0(ucase ? "DESC " : "desc ");
|
||||
if (x.getObjectType() != null) {
|
||||
print0(x.getObjectType().name());
|
||||
print(' ');
|
||||
}
|
||||
|
||||
if(x.getObject() != null) {
|
||||
x.getObject().accept(this);
|
||||
}
|
||||
|
||||
if (x.getPartition().size() > 0) {
|
||||
print0(ucase ? " PARTITION (" : " partition (");
|
||||
printAndAccept(x.getPartition(), ", ");
|
||||
print(')');
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -685,4 +685,7 @@ public interface SQLASTVisitor {
|
||||
|
||||
void endVisit(SQLStartTransactionStatement x);
|
||||
boolean visit(SQLStartTransactionStatement x);
|
||||
|
||||
void endVisit(SQLDescribeStatement x);
|
||||
boolean visit(SQLDescribeStatement x);
|
||||
}
|
||||
|
||||
@@ -1555,7 +1555,6 @@ public class SQLASTVisitorAdapter implements SQLASTVisitor {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void endVisit(SQLStartTransactionStatement x) {
|
||||
|
||||
@@ -1565,4 +1564,14 @@ public class SQLASTVisitorAdapter implements SQLASTVisitor {
|
||||
public boolean visit(SQLStartTransactionStatement x) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(SQLDescribeStatement x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLDescribeStatement x) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,6 +53,7 @@ import com.alibaba.druid.sql.ast.expr.SQLPropertyExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLSequenceExpr;
|
||||
import com.alibaba.druid.sql.ast.statement.*;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlExpr;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlExplainStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlASTVisitorAdapter;
|
||||
import com.alibaba.druid.sql.dialect.odps.ast.OdpsValuesTableSource;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.expr.OracleExpr;
|
||||
@@ -1941,5 +1942,29 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
|
||||
tableStat.incrementDropIndexCount();
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLDescribeStatement x) {
|
||||
String tableName = x.getObject().toString();
|
||||
|
||||
TableStat tableStat = this.getTableStat(tableName);
|
||||
tableStat.incrementDropIndexCount();
|
||||
|
||||
SQLName column = x.getColumn();
|
||||
if (column != null) {
|
||||
String columnName = column.toString();
|
||||
this.addColumn(tableName, columnName);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean visit(SQLExplainStatement x) {
|
||||
if (x.getStatement() != null) {
|
||||
accept(x.getStatement());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
//
|
||||
//
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user