This commit is contained in:
温少
2012-03-15 13:04:56 +08:00
parent 5a6c377a50
commit 123385f74a
7 changed files with 31 additions and 17 deletions
@@ -24,34 +24,46 @@ import com.alibaba.druid.sql.visitor.SQLASTVisitor;
public class SQLDropTableStatement extends SQLStatementImpl {
private static final long serialVersionUID = 1L;
private static final long serialVersionUID = 1L;
protected List<SQLName> tableNames = new ArrayList<SQLName>();
protected List<SQLExprTableSource> tableSources = new ArrayList<SQLExprTableSource>();
public SQLDropTableStatement(){
}
public SQLDropTableStatement(SQLName name){
tableNames.add(name);
this(new SQLExprTableSource(name));
}
public List<SQLName> getTableNames() {
return tableNames;
public SQLDropTableStatement(SQLExprTableSource tableSource){
this.tableSources.add(tableSource);
}
public void setTableNames(List<SQLName> tableNames) {
this.tableNames = tableNames;
public List<SQLExprTableSource> getTableSources() {
return tableSources;
}
public void setTableSources(List<SQLExprTableSource> tableSources) {
this.tableSources = tableSources;
}
public void setName(SQLName name) {
tableNames.add(name);
this.addTableSource(new SQLExprTableSource(name));
}
public void addTableSource(SQLName name) {
this.addTableSource(new SQLExprTableSource(name));
}
public void addTableSource(SQLExprTableSource tableSource) {
tableSources.add(tableSource);
}
@Override
protected void accept0(SQLASTVisitor visitor) {
if (visitor.visit(this)) {
this.acceptChild(visitor, tableNames);
this.acceptChild(visitor, tableSources);
}
visitor.endVisit(this);
}
@@ -21,7 +21,7 @@ public class MySqlDropTableStatement extends SQLDropTableStatement implements My
public void accept0(MySqlASTVisitor visitor) {
if (visitor.visit(this)) {
this.acceptChild(visitor, tableNames);
this.acceptChild(visitor, tableSources);
}
visitor.endVisit(this);
}
@@ -1030,7 +1030,7 @@ public class MySqlStatementParser extends SQLStatementParser {
for (;;) {
SQLName name = this.exprParser.name();
stmt.getTableNames().add(name);
stmt.addTableSource(name);
if (lexer.token() == Token.COMMA) {
lexer.nextToken();
continue;
@@ -1322,7 +1322,7 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
print("IF EXISTS ");
}
printAndAccept(x.getTableNames(), ", ");
printAndAccept(x.getTableSources(), ", ");
return false;
}
@@ -29,6 +29,7 @@ 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.SQLDropTableStatement;
import com.alibaba.druid.sql.ast.statement.SQLExprTableSource;
import com.alibaba.druid.sql.ast.statement.SQLInsertInto;
import com.alibaba.druid.sql.ast.statement.SQLInsertStatement;
import com.alibaba.druid.sql.ast.statement.SQLSelectStatement;
@@ -158,7 +159,7 @@ public class SQLStatementParser extends SQLParser {
for (;;) {
SQLName name = this.exprParser.name();
stmt.getTableNames().add(name);
stmt.getTableSources().add(new SQLExprTableSource(name));
if (lexer.token() == Token.COMMA) {
lexer.nextToken();
continue;
@@ -594,7 +594,7 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter {
public boolean visit(SQLDropTableStatement x) {
print("DROP TABLE ");
printAndAccept(x.getTableNames(), ", ");
printAndAccept(x.getTableSources(), ", ");
return false;
}
@@ -358,7 +358,7 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
if (table != null) {
return new Column(table, column);
}
if (variants.containsKey(column)) {
return null;
}
@@ -402,7 +402,8 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
String originalTable = getCurrentTable();
for (SQLName name : x.getTableNames()) {
for (SQLExprTableSource tableSource : x.getTableSources()) {
SQLName name = (SQLName) tableSource.getExpr();
String ident = name.toString();
setCurrentTable(ident);
x.putAttribute("_old_local_", originalTable);
@@ -868,7 +869,7 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
public boolean visit(SQLCommentStatement x) {
return false;
}
public boolean visit(SQLCurrentOfCursorExpr x) {
return false;
}