mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
improved sql parser, support pg udpate_from_clause. issue #1430
This commit is contained in:
@@ -27,6 +27,7 @@ public class SQLUpdateStatement extends SQLStatementImpl {
|
||||
|
||||
protected final List<SQLUpdateSetItem> items = new ArrayList<SQLUpdateSetItem>();
|
||||
protected SQLExpr where;
|
||||
protected SQLTableSource from;
|
||||
|
||||
protected SQLTableSource tableSource;
|
||||
|
||||
@@ -81,6 +82,17 @@ public class SQLUpdateStatement extends SQLStatementImpl {
|
||||
item.setParent(this);
|
||||
}
|
||||
|
||||
public SQLTableSource getFrom() {
|
||||
return from;
|
||||
}
|
||||
|
||||
public void setFrom(SQLTableSource from) {
|
||||
if (from != null) {
|
||||
from.setParent(this);
|
||||
}
|
||||
this.from = from;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void output(StringBuffer buf) {
|
||||
buf.append("UPDATE ");
|
||||
|
||||
+1
-9
@@ -34,20 +34,12 @@ public class PGUpdateStatement extends SQLUpdateStatement implements PGSQLStatem
|
||||
|
||||
private List<SQLExpr> returning = new ArrayList<SQLExpr>(2);
|
||||
|
||||
private SQLTableSource from;
|
||||
|
||||
|
||||
public PGUpdateStatement(){
|
||||
super (JdbcConstants.POSTGRESQL);
|
||||
}
|
||||
|
||||
public SQLTableSource getFrom() {
|
||||
return from;
|
||||
}
|
||||
|
||||
public void setFrom(SQLTableSource from) {
|
||||
this.from = from;
|
||||
}
|
||||
|
||||
public boolean isOnly() {
|
||||
return only;
|
||||
}
|
||||
|
||||
+9
-5
@@ -36,10 +36,7 @@ import com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGInsertStatement;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGSelectStatement;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGShowStatement;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGUpdateStatement;
|
||||
import com.alibaba.druid.sql.parser.Lexer;
|
||||
import com.alibaba.druid.sql.parser.ParserException;
|
||||
import com.alibaba.druid.sql.parser.SQLStatementParser;
|
||||
import com.alibaba.druid.sql.parser.Token;
|
||||
import com.alibaba.druid.sql.parser.*;
|
||||
|
||||
public class PGSQLStatementParser extends SQLStatementParser {
|
||||
|
||||
@@ -60,11 +57,18 @@ public class PGSQLStatementParser extends SQLStatementParser {
|
||||
|
||||
PGUpdateStatement udpateStatement = new PGUpdateStatement();
|
||||
|
||||
SQLTableSource tableSource = this.exprParser.createSelectParser().parseTableSource();
|
||||
SQLSelectParser selectParser = this.exprParser.createSelectParser();
|
||||
SQLTableSource tableSource = selectParser.parseTableSource();
|
||||
udpateStatement.setTableSource(tableSource);
|
||||
|
||||
parseUpdateSet(udpateStatement);
|
||||
|
||||
if (lexer.token() == Token.FROM) {
|
||||
lexer.nextToken();
|
||||
SQLTableSource from = selectParser.parseTableSource();
|
||||
udpateStatement.setFrom(from);
|
||||
}
|
||||
|
||||
if (lexer.token() == (Token.WHERE)) {
|
||||
lexer.nextToken();
|
||||
udpateStatement.setWhere(this.exprParser.expr());
|
||||
|
||||
+2
@@ -239,6 +239,8 @@ public class PGSchemaStatVisitor extends SchemaStatVisitor implements PGASTVisit
|
||||
TableStat stat = getTableStat(ident);
|
||||
stat.incrementUpdateCount();
|
||||
|
||||
accept(x.getFrom());
|
||||
|
||||
Map<String, String> aliasMap = getAliasMap();
|
||||
aliasMap.put(ident, ident);
|
||||
|
||||
|
||||
-9
@@ -27,7 +27,6 @@ import com.alibaba.druid.util.JdbcConstants;
|
||||
public class SQLServerUpdateStatement extends SQLUpdateStatement implements SQLServerStatement {
|
||||
|
||||
private SQLServerTop top;
|
||||
private SQLTableSource from;
|
||||
private SQLServerOutput output;
|
||||
|
||||
public SQLServerUpdateStatement(){
|
||||
@@ -42,14 +41,6 @@ public class SQLServerUpdateStatement extends SQLUpdateStatement implements SQLS
|
||||
this.top = top;
|
||||
}
|
||||
|
||||
public SQLTableSource getFrom() {
|
||||
return from;
|
||||
}
|
||||
|
||||
public void setFrom(SQLTableSource from) {
|
||||
this.from = from;
|
||||
}
|
||||
|
||||
public SQLServerOutput getOutput() {
|
||||
return output;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user