improved db2 & oracle parser.

This commit is contained in:
wenshao
2018-04-16 14:52:25 +08:00
parent b6cb168019
commit aff53dfb7c
5 changed files with 210 additions and 25 deletions
@@ -203,6 +203,8 @@ public class DB2ExprParser extends SQLExprParser {
column.setGeneratedAlawsAs(expr);
}
parseColumnRest(column);
}
return column;
@@ -212,33 +214,35 @@ public class DB2ExprParser extends SQLExprParser {
SQLColumnDefinition.Identity identity = new SQLColumnDefinition.Identity();
accept(Token.IDENTITY);
accept(Token.LPAREN);
if (lexer.token() == Token.LPAREN) {
accept(Token.LPAREN);
if (lexer.identifierEquals(FnvHash.Constants.START)) {
lexer.nextToken();
accept(Token.WITH);
if (lexer.token() == Token.LITERAL_INT) {
identity.setSeed((Integer) lexer.integerValue());
if (lexer.identifierEquals(FnvHash.Constants.START)) {
lexer.nextToken();
} else {
throw new ParserException("TODO " + lexer.info());
accept(Token.WITH);
if (lexer.token() == Token.LITERAL_INT) {
identity.setSeed((Integer) lexer.integerValue());
lexer.nextToken();
} else {
throw new ParserException("TODO " + lexer.info());
}
accept(Token.COMMA);
}
accept(Token.COMMA);
}
if (lexer.identifierEquals(FnvHash.Constants.INCREMENT)) {
lexer.nextToken();
accept(Token.BY);
if (lexer.token() == Token.LITERAL_INT) {
identity.setIncrement((Integer) lexer.integerValue());
if (lexer.identifierEquals(FnvHash.Constants.INCREMENT)) {
lexer.nextToken();
} else {
throw new ParserException("TODO " + lexer.info());
accept(Token.BY);
if (lexer.token() == Token.LITERAL_INT) {
identity.setIncrement((Integer) lexer.integerValue());
lexer.nextToken();
} else {
throw new ParserException("TODO " + lexer.info());
}
}
}
accept(Token.RPAREN);
accept(Token.RPAREN);
}
return identity;
}
@@ -170,18 +170,28 @@ public class DB2OutputVisitor extends SQLASTOutputVisitor implements DB2ASTVisit
}
public boolean visit(SQLColumnDefinition.Identity x) {
print0(ucase ? "GENERATED ALWAYS AS IDENTITY (" : "generated always as identity (");
print0(ucase ? "GENERATED ALWAYS AS IDENTITY" : "generated always as identity");
final Integer seed = x.getSeed();
final Integer increment = x.getIncrement();
if (seed != null || increment != null) {
print0(" (");
}
if (seed != null) {
print0(ucase ? "START WITH " : "start with ");
print(seed);
print0(", ");
if (increment != null) {
print0(", ");
}
}
print0(ucase ? "INCREMENT BY " : "increment by ");
print(x.getIncrement());
print(')');
if (increment != null) {
print0(ucase ? "INCREMENT BY " : "increment by ");
print(increment);
print(')');
}
return false;
}
@@ -1203,6 +1203,11 @@ public class SQLExprParser extends SQLParser {
}
accept(Token.RPAREN);
}
if (lexer.token == Token.OVER) {
over(methodInvokeExpr);
}
expr = methodInvokeExpr;
} else {
SQLMethodInvokeExpr methodInvokeExpr = new SQLMethodInvokeExpr(name);