mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
bug fixed for oracle sql parser.
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
package com.alibaba.druid.sql.dialect.oracle.parser;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.sql.Savepoint;
|
||||
|
||||
import com.alibaba.druid.sql.ast.*;
|
||||
import com.alibaba.druid.sql.ast.SQLKeep.DenseRank;
|
||||
@@ -599,19 +600,19 @@ public class OracleExprParser extends SQLExprParser {
|
||||
}
|
||||
|
||||
if (identifierEquals("DAY") || identifierEquals("YEAR")) {
|
||||
lexer.mark();
|
||||
Lexer.SavePoint savePoint = lexer.mark();
|
||||
|
||||
String name = lexer.stringVal();
|
||||
lexer.nextToken();
|
||||
|
||||
if (lexer.token() == Token.COMMA) {
|
||||
lexer.reset();
|
||||
lexer.reset(savePoint);
|
||||
return expr;
|
||||
}
|
||||
|
||||
OracleIntervalExpr interval = new OracleIntervalExpr();
|
||||
interval.setValue(expr);
|
||||
OracleIntervalType type = OracleIntervalType.valueOf(name);
|
||||
OracleIntervalType type = OracleIntervalType.valueOf(name.toUpperCase());
|
||||
interval.setType(type);
|
||||
|
||||
if (lexer.token() == Token.LPAREN) {
|
||||
@@ -623,8 +624,14 @@ public class OracleExprParser extends SQLExprParser {
|
||||
lexer.nextToken();
|
||||
accept(Token.RPAREN);
|
||||
}
|
||||
|
||||
accept(Token.TO);
|
||||
|
||||
if (lexer.token() == Token.TO) {
|
||||
lexer.nextToken();
|
||||
} else {
|
||||
lexer.reset(savePoint);
|
||||
return expr;
|
||||
}
|
||||
|
||||
if (identifierEquals("SECOND")) {
|
||||
lexer.nextToken();
|
||||
interval.setToType(OracleIntervalType.SECOND);
|
||||
|
||||
@@ -115,6 +115,10 @@ public class OracleLexer extends Lexer {
|
||||
map.put("TABLESPACE", Token.TABLESPACE);
|
||||
map.put("PARTITION", Token.PARTITION);
|
||||
|
||||
map.put(",", Token.COMMA);
|
||||
map.put("(", Token.LPAREN);
|
||||
map.put(")", Token.RPAREN);
|
||||
|
||||
DEFAULT_ORACLE_KEYWORDS = new Keywords(map);
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -767,7 +767,7 @@ public class OracleStatementParser extends SQLStatementParser {
|
||||
}
|
||||
|
||||
accept(Token.RETURN);
|
||||
SQLDataType returnDataType = this.exprParser.parseDataType();
|
||||
SQLDataType returnDataType = this.exprParser.parseDataType(false);
|
||||
stmt.setReturnDataType(returnDataType);
|
||||
|
||||
if (identifierEquals("AUTHID")) {
|
||||
@@ -2192,7 +2192,7 @@ public class OracleStatementParser extends SQLStatementParser {
|
||||
SQLName name = this.exprParser.name();
|
||||
varItem.setName(name);
|
||||
|
||||
varItem.setDataType(this.exprParser.parseDataType());
|
||||
varItem.setDataType(this.exprParser.parseDataType(false));
|
||||
varItem.setParent(varDecl);
|
||||
|
||||
varDecl.getItems().add(varItem);
|
||||
|
||||
@@ -168,35 +168,41 @@ public class Lexer {
|
||||
return ++varIndex;
|
||||
}
|
||||
|
||||
private static class SavePoint {
|
||||
|
||||
public static class SavePoint {
|
||||
int bp;
|
||||
int sp;
|
||||
int np;
|
||||
char ch;
|
||||
Token token;
|
||||
String stringVal;
|
||||
}
|
||||
|
||||
public Keywords getKeywods() {
|
||||
return keywods;
|
||||
}
|
||||
|
||||
public void mark() {
|
||||
public SavePoint mark() {
|
||||
SavePoint savePoint = new SavePoint();
|
||||
savePoint.bp = pos;
|
||||
savePoint.sp = bufPos;
|
||||
savePoint.np = mark;
|
||||
savePoint.ch = ch;
|
||||
savePoint.token = token;
|
||||
this.savePoint = savePoint;
|
||||
savePoint.stringVal = stringVal;
|
||||
return this.savePoint = savePoint;
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
public void reset(SavePoint savePoint) {
|
||||
this.pos = savePoint.bp;
|
||||
this.bufPos = savePoint.sp;
|
||||
this.mark = savePoint.np;
|
||||
this.ch = savePoint.ch;
|
||||
this.token = savePoint.token;
|
||||
this.stringVal = savePoint.stringVal;
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
this.reset(this.savePoint);
|
||||
}
|
||||
|
||||
public Lexer(String input, boolean skipComment){
|
||||
@@ -257,7 +263,7 @@ public class Lexer {
|
||||
return;
|
||||
}
|
||||
|
||||
if (ch == ')') {
|
||||
if (ch == ')' || ch == ')') {
|
||||
scanChar();
|
||||
token = RPAREN;
|
||||
return;
|
||||
@@ -271,7 +277,7 @@ public class Lexer {
|
||||
scanChar();
|
||||
}
|
||||
|
||||
if (ch == '(') {
|
||||
if (ch == '(' || ch == '(') {
|
||||
scanChar();
|
||||
token = LPAREN;
|
||||
return;
|
||||
@@ -378,10 +384,12 @@ public class Lexer {
|
||||
token = COMMA;
|
||||
return;
|
||||
case '(':
|
||||
case '(':
|
||||
scanChar();
|
||||
token = LPAREN;
|
||||
return;
|
||||
case ')':
|
||||
case ')':
|
||||
scanChar();
|
||||
token = RPAREN;
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user