mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
improved postgresql parser. bug fixed for issue #2153
This commit is contained in:
+53
@@ -519,4 +519,57 @@ public class PGSQLStatementParser extends SQLStatementParser {
|
||||
return stmt;
|
||||
}
|
||||
|
||||
public SQLStatement parseCreateIndex(boolean acceptCreate) {
|
||||
if (acceptCreate) {
|
||||
accept(Token.CREATE);
|
||||
}
|
||||
|
||||
SQLCreateIndexStatement stmt = new SQLCreateIndexStatement(getDbType());
|
||||
if (lexer.token() == Token.UNIQUE) {
|
||||
lexer.nextToken();
|
||||
if (lexer.identifierEquals("CLUSTERED")) {
|
||||
lexer.nextToken();
|
||||
stmt.setType("UNIQUE CLUSTERED");
|
||||
} else {
|
||||
stmt.setType("UNIQUE");
|
||||
}
|
||||
} else if (lexer.identifierEquals("FULLTEXT")) {
|
||||
stmt.setType("FULLTEXT");
|
||||
lexer.nextToken();
|
||||
} else if (lexer.identifierEquals("NONCLUSTERED")) {
|
||||
stmt.setType("NONCLUSTERED");
|
||||
lexer.nextToken();
|
||||
}
|
||||
|
||||
accept(Token.INDEX);
|
||||
|
||||
stmt.setName(this.exprParser.name());
|
||||
|
||||
accept(Token.ON);
|
||||
|
||||
stmt.setTable(this.exprParser.name());
|
||||
|
||||
if (lexer.token() == Token.USING) {
|
||||
lexer.nextToken();
|
||||
String using = lexer.stringVal();
|
||||
accept(Token.IDENTIFIER);
|
||||
stmt.setUsing(using);
|
||||
}
|
||||
|
||||
accept(Token.LPAREN);
|
||||
|
||||
for (;;) {
|
||||
SQLSelectOrderByItem item = this.exprParser.parseSelectOrderByItem();
|
||||
item.setParent(stmt);
|
||||
stmt.addItem(item);
|
||||
if (lexer.token() == Token.COMMA) {
|
||||
lexer.nextToken();
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
accept(Token.RPAREN);
|
||||
|
||||
return stmt;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2974,4 +2974,36 @@ public class PGOutputVisitor extends SQLASTOutputVisitor implements PGASTVisitor
|
||||
print0(ucase ? "END IF" : "end if");
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLCreateIndexStatement x) {
|
||||
print0(ucase ? "CREATE " : "create ");
|
||||
if (x.getType() != null) {
|
||||
print0(x.getType());
|
||||
print(' ');
|
||||
}
|
||||
|
||||
print0(ucase ? "INDEX " : "index ");
|
||||
|
||||
if (x.getUsing() != null) {
|
||||
print0(ucase ? " USING " : " using ");
|
||||
;
|
||||
print0(x.getUsing());
|
||||
}
|
||||
|
||||
x.getName().accept(this);
|
||||
print0(ucase ? " ON " : " on ");
|
||||
x.getTable().accept(this);
|
||||
print0(" (");
|
||||
printAndAccept(x.getItems(), ", ");
|
||||
print(')');
|
||||
|
||||
SQLExpr comment = x.getComment();
|
||||
if (comment != null) {
|
||||
print0(ucase ? " COMMENT " : " comment ");
|
||||
comment.accept(this);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user