mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
improved sql parsre.
This commit is contained in:
@@ -33,7 +33,12 @@ public class PGTypeCastExpr extends SQLCastExpr implements PGExpr {
|
||||
|
||||
@Override
|
||||
protected void accept0(SQLASTVisitor visitor) {
|
||||
accept0((PGASTVisitor) visitor);
|
||||
if (visitor instanceof PGASTVisitor) {
|
||||
accept0((PGASTVisitor) visitor);
|
||||
return;
|
||||
}
|
||||
|
||||
super.accept0(visitor);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
|
||||
+6
-1
@@ -38,7 +38,12 @@ public class PGUpdateStatement extends SQLUpdateStatement implements PGSQLStatem
|
||||
}
|
||||
|
||||
protected void accept0(SQLASTVisitor visitor) {
|
||||
accept0((PGASTVisitor) visitor);
|
||||
if (visitor instanceof PGASTVisitor) {
|
||||
accept0((PGASTVisitor) visitor);
|
||||
return;
|
||||
}
|
||||
|
||||
super.accept0(visitor);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+74
@@ -31,6 +31,8 @@ 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.util.FnvHash;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -393,5 +395,77 @@ public class PGSQLStatementParser extends SQLStatementParser {
|
||||
return stmt;
|
||||
}
|
||||
|
||||
public SQLCreateSequenceStatement parseCreateSequence(boolean acceptCreate) {
|
||||
if (acceptCreate) {
|
||||
accept(Token.CREATE);
|
||||
}
|
||||
|
||||
accept(Token.SEQUENCE);
|
||||
|
||||
SQLCreateSequenceStatement stmt = new SQLCreateSequenceStatement();
|
||||
stmt.setDbType(dbType);
|
||||
stmt.setName(this.exprParser.name());
|
||||
|
||||
for (;;) {
|
||||
if (lexer.token() == Token.START) {
|
||||
lexer.nextToken();
|
||||
accept(Token.WITH);
|
||||
stmt.setStartWith(this.exprParser.expr());
|
||||
continue;
|
||||
} else if (lexer.identifierEquals("INCREMENT")) {
|
||||
lexer.nextToken();
|
||||
accept(Token.BY);
|
||||
stmt.setIncrementBy(this.exprParser.expr());
|
||||
continue;
|
||||
} else if (lexer.token() == Token.CACHE || lexer.identifierEquals(FnvHash.Constants.CACHE)) {
|
||||
lexer.nextToken();
|
||||
stmt.setCache(Boolean.TRUE);
|
||||
|
||||
if (lexer.token() == Token.LITERAL_INT) {
|
||||
stmt.setCacheValue(this.exprParser.primary());
|
||||
}
|
||||
continue;
|
||||
} else if (lexer.token() == Token.NOCACHE) {
|
||||
lexer.nextToken();
|
||||
stmt.setCache(Boolean.FALSE);
|
||||
continue;
|
||||
} else if (lexer.token() == Token.ORDER) {
|
||||
lexer.nextToken();
|
||||
stmt.setOrder(Boolean.TRUE);
|
||||
continue;
|
||||
} else if (lexer.identifierEquals("NOORDER")) {
|
||||
lexer.nextToken();
|
||||
stmt.setOrder(Boolean.FALSE);
|
||||
continue;
|
||||
} else if (lexer.identifierEquals("CYCLE")) {
|
||||
lexer.nextToken();
|
||||
stmt.setCycle(Boolean.TRUE);
|
||||
continue;
|
||||
} else if (lexer.identifierEquals("NOCYCLE")) {
|
||||
lexer.nextToken();
|
||||
stmt.setCycle(Boolean.FALSE);
|
||||
continue;
|
||||
} else if (lexer.identifierEquals("MINVALUE")) {
|
||||
lexer.nextToken();
|
||||
stmt.setMinValue(this.exprParser.expr());
|
||||
continue;
|
||||
} else if (lexer.identifierEquals("MAXVALUE")) {
|
||||
lexer.nextToken();
|
||||
stmt.setMaxValue(this.exprParser.expr());
|
||||
continue;
|
||||
} else if (lexer.identifierEquals("NOMAXVALUE")) {
|
||||
lexer.nextToken();
|
||||
stmt.setNoMaxValue(true);
|
||||
continue;
|
||||
} else if (lexer.identifierEquals("NOMINVALUE")) {
|
||||
lexer.nextToken();
|
||||
stmt.setNoMinValue(true);
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return stmt;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+27
-2
@@ -1082,7 +1082,7 @@ public class PGOutputVisitor extends SQLASTOutputVisitor implements PGASTVisitor
|
||||
|
||||
if (x.getPrecision() != null) {
|
||||
print('(');
|
||||
print(x.getPrecision().intValue());
|
||||
printExpr(x.getPrecision());
|
||||
if (x.getFactionalSecondsPrecision() != null) {
|
||||
print0(", ");
|
||||
print(x.getFactionalSecondsPrecision().intValue());
|
||||
@@ -1095,7 +1095,7 @@ public class PGOutputVisitor extends SQLASTOutputVisitor implements PGASTVisitor
|
||||
print0(x.getToType().name());
|
||||
if (x.getToFactionalSecondsPrecision() != null) {
|
||||
print('(');
|
||||
print(x.getToFactionalSecondsPrecision().intValue());
|
||||
printExpr(x.getToFactionalSecondsPrecision());
|
||||
print(')');
|
||||
}
|
||||
}
|
||||
@@ -2770,4 +2770,29 @@ public class PGOutputVisitor extends SQLASTOutputVisitor implements PGASTVisitor
|
||||
x.getExpr().accept(this);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(OracleIsOfTypeExpr x) {
|
||||
printExpr(x.getExpr());
|
||||
print0(ucase ? " IS OF TYPE (" : " is of type (");
|
||||
|
||||
List<SQLExpr> types = x.getTypes();
|
||||
for (int i = 0, size = types.size(); i < size; ++i) {
|
||||
if (i != 0) {
|
||||
print0(", ");
|
||||
}
|
||||
SQLExpr type = types.get(i);
|
||||
if (Boolean.TRUE == type.getAttribute("ONLY")) {
|
||||
print0(ucase ? "ONLY " : "only ");
|
||||
}
|
||||
type.accept(this);
|
||||
}
|
||||
|
||||
print(')');
|
||||
return false;
|
||||
}
|
||||
|
||||
public void endVisit(OracleIsOfTypeExpr x) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user