mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
improved sql parser. issue #1416
This commit is contained in:
@@ -25,6 +25,7 @@ public class SQLDeleteStatement extends SQLStatementImpl {
|
||||
|
||||
protected SQLTableSource tableSource;
|
||||
protected SQLExpr where;
|
||||
protected SQLTableSource from;
|
||||
|
||||
public SQLDeleteStatement(){
|
||||
|
||||
@@ -110,4 +111,14 @@ public class SQLDeleteStatement extends SQLStatementImpl {
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
|
||||
public SQLTableSource getFrom() {
|
||||
return from;
|
||||
}
|
||||
|
||||
public void setFrom(SQLTableSource from) {
|
||||
if (from != null) {
|
||||
from.setParent(this);
|
||||
}
|
||||
this.from = from;
|
||||
}
|
||||
}
|
||||
|
||||
-9
@@ -34,7 +34,6 @@ public class MySqlDeleteStatement extends SQLDeleteStatement {
|
||||
private boolean quick = false;
|
||||
private boolean ignore = false;
|
||||
|
||||
private SQLTableSource from;
|
||||
private SQLTableSource using;
|
||||
private SQLOrderBy orderBy;
|
||||
private Limit limit;
|
||||
@@ -84,10 +83,6 @@ public class MySqlDeleteStatement extends SQLDeleteStatement {
|
||||
this.ignore = ignore;
|
||||
}
|
||||
|
||||
public SQLTableSource getFrom() {
|
||||
return from;
|
||||
}
|
||||
|
||||
public SQLTableSource getUsing() {
|
||||
return using;
|
||||
}
|
||||
@@ -96,10 +91,6 @@ public class MySqlDeleteStatement extends SQLDeleteStatement {
|
||||
this.using = using;
|
||||
}
|
||||
|
||||
public void setFrom(SQLTableSource from) {
|
||||
this.from = from;
|
||||
}
|
||||
|
||||
public SQLOrderBy getOrderBy() {
|
||||
return orderBy;
|
||||
}
|
||||
|
||||
@@ -330,7 +330,8 @@ public class SQLSelectParser extends SQLParser {
|
||||
groupBy.setWithRollUp(true);
|
||||
}
|
||||
|
||||
if(JdbcConstants.MYSQL.equals(getDbType()) && lexer.token() == Token.DESC) {
|
||||
if(JdbcConstants.MYSQL.equals(getDbType())
|
||||
&& lexer.token() == Token.DESC) {
|
||||
lexer.nextToken(); // skip
|
||||
}
|
||||
|
||||
|
||||
@@ -1934,6 +1934,12 @@ public class SQLStatementParser extends SQLParser {
|
||||
SQLName tableName = exprParser.name();
|
||||
|
||||
deleteStatement.setTableName(tableName);
|
||||
|
||||
if (lexer.token() == Token.FROM) {
|
||||
lexer.nextToken();
|
||||
SQLTableSource tableSource = createSQLSelectParser().parseTableSource();
|
||||
deleteStatement.setFrom(tableSource);
|
||||
}
|
||||
}
|
||||
|
||||
if (lexer.token() == (Token.WHERE)) {
|
||||
|
||||
@@ -1035,9 +1035,17 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
}
|
||||
|
||||
public boolean visit(SQLDeleteStatement x) {
|
||||
print0(ucase ? "DELETE FROM " : "delete from ");
|
||||
SQLTableSource from = x.getFrom();
|
||||
|
||||
x.getTableName().accept(this);
|
||||
if (from == null) {
|
||||
print0(ucase ? "DELETE FROM " : "delete from ");
|
||||
x.getTableName().accept(this);
|
||||
} else {
|
||||
print0(ucase ? "DELETE " : "delete ");
|
||||
x.getTableName().accept(this);
|
||||
print0(ucase ? " FROM " : " from ");
|
||||
from.accept(this);
|
||||
}
|
||||
|
||||
if (x.getWhere() != null) {
|
||||
println();
|
||||
|
||||
Reference in New Issue
Block a user