mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
improve sql parser
This commit is contained in:
@@ -96,7 +96,10 @@ import com.alibaba.druid.sql.ast.statement.SQLCreateIndexStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLCreateTableStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLDeleteStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLDropIndexStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLDropSequenceStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLDropTableStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLDropTriggerStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLDropUserStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLDropViewStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLExprHint;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLExprTableSource;
|
||||
@@ -786,14 +789,49 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
}
|
||||
|
||||
public boolean visit(SQLDropTableStatement x) {
|
||||
print("DROP TABLE ");
|
||||
if (x.isTemporary()) {
|
||||
print("DROP TEMPORARY TABLE ");
|
||||
} else {
|
||||
print("DROP TABLE ");
|
||||
}
|
||||
|
||||
if (x.isIfExists()) {
|
||||
print("IF EXISTS ");
|
||||
}
|
||||
|
||||
printAndAccept(x.getTableSources(), ", ");
|
||||
|
||||
if (x.isCascade()) {
|
||||
printCascade();
|
||||
}
|
||||
|
||||
if (x.isRestrict()) {
|
||||
print(" RESTRICT");
|
||||
}
|
||||
|
||||
if (x.isPurge()) {
|
||||
print(" PURGE");
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
protected void printCascade() {
|
||||
print(" CASCADE");
|
||||
}
|
||||
|
||||
public boolean visit(SQLDropViewStatement x) {
|
||||
print("DROP VIEW ");
|
||||
|
||||
if (x.isIfExists()) {
|
||||
print("IF EXISTS ");
|
||||
}
|
||||
|
||||
printAndAccept(x.getTableSources(), ", ");
|
||||
|
||||
if (x.isCascade()) {
|
||||
printCascade();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1636,4 +1674,35 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
print(")");
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLDropSequenceStatement x) {
|
||||
print("DROP SEQUENCE ");
|
||||
x.getName().accept(this);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(SQLDropSequenceStatement x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLDropTriggerStatement x) {
|
||||
print("DROP TRIGGER ");
|
||||
x.getName().accept(this);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(SQLDropUserStatement x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLDropUserStatement x) {
|
||||
print("DROP USER ");
|
||||
printAndAccept(x.getUsers(), ", ");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,7 +80,10 @@ import com.alibaba.druid.sql.ast.statement.SQLCreateTableStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLCreateViewStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLDeleteStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLDropIndexStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLDropSequenceStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLDropTableStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLDropTriggerStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLDropUserStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLDropViewStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLExprHint;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLExprTableSource;
|
||||
@@ -396,9 +399,9 @@ public interface SQLASTVisitor {
|
||||
void endVisit(SQLColumnPrimaryKey x);
|
||||
|
||||
boolean visit(SQLColumnPrimaryKey x);
|
||||
|
||||
|
||||
boolean visit(SQLColumnUniqueKey x);
|
||||
|
||||
|
||||
void endVisit(SQLColumnUniqueKey x);
|
||||
|
||||
void endVisit(SQLWithSubqueryClause x);
|
||||
@@ -472,16 +475,28 @@ public interface SQLASTVisitor {
|
||||
boolean visit(SQLCreateIndexStatement x);
|
||||
|
||||
void endVisit(SQLCreateIndexStatement x);
|
||||
|
||||
|
||||
boolean visit(SQLAlterTableRenameColumn x);
|
||||
|
||||
|
||||
void endVisit(SQLAlterTableRenameColumn x);
|
||||
|
||||
|
||||
boolean visit(SQLColumnReference x);
|
||||
|
||||
|
||||
void endVisit(SQLColumnReference x);
|
||||
|
||||
|
||||
boolean visit(SQLForeignKeyImpl x);
|
||||
|
||||
|
||||
void endVisit(SQLForeignKeyImpl x);
|
||||
|
||||
boolean visit(SQLDropSequenceStatement x);
|
||||
|
||||
void endVisit(SQLDropSequenceStatement x);
|
||||
|
||||
boolean visit(SQLDropTriggerStatement x);
|
||||
|
||||
void endVisit(SQLDropTriggerStatement x);
|
||||
|
||||
void endVisit(SQLDropUserStatement x);
|
||||
|
||||
boolean visit(SQLDropUserStatement x);
|
||||
}
|
||||
|
||||
@@ -81,7 +81,10 @@ import com.alibaba.druid.sql.ast.statement.SQLCreateTableStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLCreateViewStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLDeleteStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLDropIndexStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLDropSequenceStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLDropTableStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLDropTriggerStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLDropUserStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLDropViewStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLExprHint;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLExprTableSource;
|
||||
@@ -700,12 +703,12 @@ public class SQLASTVisitorAdapter implements SQLASTVisitor {
|
||||
public boolean visit(SQLColumnPrimaryKey x) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void endVisit(SQLColumnUniqueKey x) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLColumnUniqueKey x) {
|
||||
return true;
|
||||
@@ -879,7 +882,7 @@ public class SQLASTVisitorAdapter implements SQLASTVisitor {
|
||||
|
||||
@Override
|
||||
public void endVisit(SQLUnique x) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -889,7 +892,7 @@ public class SQLASTVisitorAdapter implements SQLASTVisitor {
|
||||
|
||||
@Override
|
||||
public void endVisit(SQLCreateIndexStatement x) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -899,7 +902,7 @@ public class SQLASTVisitorAdapter implements SQLASTVisitor {
|
||||
|
||||
@Override
|
||||
public void endVisit(SQLPrimaryKeyImpl x) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -909,26 +912,56 @@ public class SQLASTVisitorAdapter implements SQLASTVisitor {
|
||||
|
||||
@Override
|
||||
public void endVisit(SQLAlterTableRenameColumn x) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLColumnReference x) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void endVisit(SQLColumnReference x) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLForeignKeyImpl x) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void endVisit(SQLForeignKeyImpl x) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLDropSequenceStatement x) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(SQLDropSequenceStatement x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLDropTriggerStatement x) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(SQLDropTriggerStatement x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(SQLDropUserStatement x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLDropUserStatement x) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,7 +53,11 @@ import com.alibaba.druid.sql.ast.statement.SQLCreateTableStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLCreateViewStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLDeleteStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLDropIndexStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLDropSequenceStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLDropTableStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLDropTriggerStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLDropUserStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLDropViewStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLExprTableSource;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLForeignKeyImpl;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLInsertStatement;
|
||||
@@ -516,6 +520,12 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLDropViewStatement x) {
|
||||
setMode(x, Mode.Drop);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLDropTableStatement x) {
|
||||
setMode(x, Mode.Insert);
|
||||
@@ -1213,14 +1223,14 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLForeignKeyImpl x) {
|
||||
|
||||
|
||||
for (SQLName column : x.getReferencedColumns()) {
|
||||
column.accept(this);
|
||||
}
|
||||
|
||||
|
||||
String table = x.getReferencedTableName().getSimleName();
|
||||
setCurrentTable(table);
|
||||
|
||||
@@ -1230,7 +1240,27 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
|
||||
String columnName = column.getSimleName();
|
||||
addColumn(table, columnName);
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLDropSequenceStatement x) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLDropTriggerStatement x) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(SQLDropUserStatement x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLDropUserStatement x) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user