mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
bug fixed for pg sql parser
This commit is contained in:
@@ -59,24 +59,24 @@ public class PGSelectParser extends SQLSelectParser {
|
||||
accept(Token.RPAREN);
|
||||
return queryRest(valuesQuery);
|
||||
}
|
||||
|
||||
|
||||
if (lexer.token() == Token.LPAREN) {
|
||||
lexer.nextToken();
|
||||
|
||||
SQLSelectQuery select = query();
|
||||
if (select instanceof SQLSelectQueryBlock) {
|
||||
((SQLSelectQueryBlock) select).setParenthesized(true);
|
||||
}
|
||||
if (select instanceof SQLSelectQueryBlock) {
|
||||
((SQLSelectQueryBlock) select).setParenthesized(true);
|
||||
}
|
||||
accept(Token.RPAREN);
|
||||
|
||||
return queryRest(select);
|
||||
}
|
||||
|
||||
|
||||
PGSelectQueryBlock queryBlock = new PGSelectQueryBlock();
|
||||
|
||||
if (lexer.token() == Token.SELECT) {
|
||||
lexer.nextToken();
|
||||
|
||||
|
||||
if (lexer.token() == Token.COMMENT) {
|
||||
lexer.nextToken();
|
||||
}
|
||||
@@ -160,7 +160,7 @@ public class PGSelectParser extends SQLSelectParser {
|
||||
for (;;) {
|
||||
if (lexer.token() == Token.LIMIT) {
|
||||
PGLimit limit = new PGLimit();
|
||||
|
||||
|
||||
lexer.nextToken();
|
||||
if (lexer.token() == Token.ALL) {
|
||||
limit.setRowCount(new SQLIdentifierExpr("ALL"));
|
||||
@@ -168,7 +168,7 @@ public class PGSelectParser extends SQLSelectParser {
|
||||
} else {
|
||||
limit.setRowCount(expr());
|
||||
}
|
||||
|
||||
|
||||
queryBlock.setLimit(limit);
|
||||
} else if (lexer.token() == Token.OFFSET) {
|
||||
PGLimit limit = queryBlock.getLimit();
|
||||
@@ -259,13 +259,22 @@ public class PGSelectParser extends SQLSelectParser {
|
||||
|
||||
protected SQLTableSource parseTableSourceRest(SQLTableSource tableSource) {
|
||||
if (lexer.token() == Token.AS && tableSource instanceof SQLExprTableSource) {
|
||||
lexer.nextToken();
|
||||
|
||||
String alias = null;
|
||||
if (lexer.token() == Token.IDENTIFIER) {
|
||||
alias = lexer.stringVal();
|
||||
lexer.nextToken();
|
||||
}
|
||||
|
||||
if (lexer.token() == Token.LPAREN) {
|
||||
SQLExprTableSource exprTableSource = (SQLExprTableSource) tableSource;
|
||||
|
||||
String alias = this.as();
|
||||
PGFunctionTableSource functionTableSource = new PGFunctionTableSource(exprTableSource.getExpr());
|
||||
functionTableSource.setAlias(alias);
|
||||
|
||||
if (alias != null) {
|
||||
functionTableSource.setAlias(alias);
|
||||
}
|
||||
|
||||
lexer.nextToken();
|
||||
parserParameters(functionTableSource.getParameters());
|
||||
accept(Token.RPAREN);
|
||||
|
||||
+3
-1
@@ -97,6 +97,8 @@ public class PGSchemaStatVisitor extends SchemaStatVisitor implements PGASTVisit
|
||||
|
||||
@Override
|
||||
public boolean visit(PGWithQuery x) {
|
||||
x.getQuery().accept(this);
|
||||
|
||||
Map<String, String> aliasMap = getAliasMap();
|
||||
if (aliasMap != null) {
|
||||
String alias = null;
|
||||
@@ -109,7 +111,7 @@ public class PGSchemaStatVisitor extends SchemaStatVisitor implements PGASTVisit
|
||||
subQueryMap.put(alias, x.getQuery());
|
||||
}
|
||||
}
|
||||
x.getQuery().accept(this);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@ import com.alibaba.druid.sql.ast.SQLOrderBy;
|
||||
import com.alibaba.druid.sql.ast.SQLOrderingSpecification;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLAggregateExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLAllColumnExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLArrayExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLCurrentOfCursorExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr;
|
||||
@@ -103,20 +104,20 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
|
||||
protected final List<Column> orderByColumns = new ArrayList<Column>();
|
||||
protected final Set<Column> groupByColumns = new LinkedHashSet<Column>();
|
||||
|
||||
protected final Map<String, SQLObject> subQueryMap = new LinkedHashMap<String, SQLObject>();
|
||||
protected final Map<String, SQLObject> subQueryMap = new LinkedHashMap<String, SQLObject>();
|
||||
|
||||
protected final Map<String, SQLObject> variants = new LinkedHashMap<String, SQLObject>();
|
||||
protected final Map<String, SQLObject> variants = new LinkedHashMap<String, SQLObject>();
|
||||
|
||||
protected Map<String, String> aliasMap = new HashMap<String, String>();
|
||||
protected Map<String, String> aliasMap = new HashMap<String, String>();
|
||||
|
||||
protected String currentTable;
|
||||
protected String currentTable;
|
||||
|
||||
public final static String ATTR_TABLE = "_table_";
|
||||
public final static String ATTR_COLUMN = "_column_";
|
||||
public final static String ATTR_TABLE = "_table_";
|
||||
public final static String ATTR_COLUMN = "_column_";
|
||||
|
||||
private List<Object> parameters;
|
||||
private List<Object> parameters;
|
||||
|
||||
private Mode mode;
|
||||
private Mode mode;
|
||||
|
||||
public SchemaStatVisitor(){
|
||||
this(new ArrayList<Object>());
|
||||
@@ -739,7 +740,7 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
|
||||
if (!item.getClass().equals(SQLSelectItem.class)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
String itemAlias = item.getAlias();
|
||||
SQLExpr itemExpr = item.getExpr();
|
||||
if (itemAlias == null) {
|
||||
@@ -880,7 +881,7 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
|
||||
|
||||
public void endVisit(SQLSelectStatement x) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLWithSubqueryClause.Entry x) {
|
||||
String alias = x.getName().toString();
|
||||
@@ -888,22 +889,22 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
|
||||
SQLWithSubqueryClause with = (SQLWithSubqueryClause) x.getParent();
|
||||
|
||||
if (Boolean.TRUE == with.getRecursive()) {
|
||||
|
||||
|
||||
if (aliasMap != null && alias != null) {
|
||||
aliasMap.put(alias, null);
|
||||
subQueryMap.put(alias, x.getSubQuery().getQuery());
|
||||
}
|
||||
|
||||
|
||||
x.getSubQuery().accept(this);
|
||||
} else {
|
||||
x.getSubQuery().accept(this);
|
||||
|
||||
|
||||
if (aliasMap != null && alias != null) {
|
||||
aliasMap.put(alias, null);
|
||||
subQueryMap.put(alias, x.getSubQuery().getQuery());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1069,7 +1070,7 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public boolean visit(SQLInListExpr x) {
|
||||
if (x.isNot()) {
|
||||
handleCondition(x.getExpr(), "NOT IN", x.getTargetList());
|
||||
@@ -1111,7 +1112,7 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
|
||||
accept(x.getTableElementList());
|
||||
|
||||
restoreCurrentTable(x);
|
||||
|
||||
|
||||
if (x.getInherits() != null) {
|
||||
x.getInherits().accept(this);
|
||||
}
|
||||
@@ -1317,7 +1318,7 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLRevokeStatement x) {
|
||||
if (x.getOn() != null) {
|
||||
@@ -1325,12 +1326,12 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLDropDatabaseStatement x) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLAlterTableAddIndex x) {
|
||||
for (SQLSelectOrderByItem item : x.getItems()) {
|
||||
@@ -1338,30 +1339,44 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public boolean visit(SQLCheck x) {
|
||||
x.getExpr().accept(this);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public boolean visit(SQLCreateTriggerStatement x) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public boolean visit(SQLDropFunctionStatement x) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public boolean visit(SQLDropTableSpaceStatement x) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public boolean visit(SQLDropProcedureStatement x) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLAlterTableRename x) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLArrayExpr x) {
|
||||
accept(x.getValues());
|
||||
|
||||
SQLExpr exp = x.getExpr();
|
||||
if (exp instanceof SQLIdentifierExpr) {
|
||||
if (((SQLIdentifierExpr) exp).getName().equals("ARRAY")) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
exp.accept(this);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user