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:
+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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user