use of com.alibaba.druid.sql.dialect.oracle.ast.OracleDataTypeTimestamp in project druid by alibaba.
the class OracleExprParser method parseDataType.
public SQLDataType parseDataType() {
if (lexer.token() == Token.CONSTRAINT || lexer.token() == Token.COMMA) {
return null;
}
if (lexer.token() == Token.DEFAULT || lexer.token() == Token.NOT || lexer.token() == Token.NULL) {
return null;
}
if (lexer.token() == Token.INTERVAL) {
lexer.nextToken();
if (identifierEquals("YEAR")) {
lexer.nextToken();
OracleDataTypeIntervalYear interval = new OracleDataTypeIntervalYear();
if (lexer.token() == Token.LPAREN) {
lexer.nextToken();
interval.addArgument(this.expr());
accept(Token.RPAREN);
}
accept(Token.TO);
acceptIdentifier("MONTH");
return interval;
} else {
acceptIdentifier("DAY");
OracleDataTypeIntervalDay interval = new OracleDataTypeIntervalDay();
if (lexer.token() == Token.LPAREN) {
lexer.nextToken();
interval.addArgument(this.expr());
accept(Token.RPAREN);
}
accept(Token.TO);
acceptIdentifier("SECOND");
if (lexer.token() == Token.LPAREN) {
lexer.nextToken();
interval.getFractionalSeconds().add(this.expr());
accept(Token.RPAREN);
}
return interval;
}
}
String typeName;
if (identifierEquals("LONG")) {
lexer.nextToken();
acceptIdentifier("RAW");
typeName = "LONG RAW";
} else {
SQLName typeExpr = name();
typeName = typeExpr.toString();
}
if ("TIMESTAMP".equalsIgnoreCase(typeName)) {
OracleDataTypeTimestamp timestamp = new OracleDataTypeTimestamp();
if (lexer.token() == Token.LPAREN) {
lexer.nextToken();
timestamp.addArgument(this.expr());
accept(Token.RPAREN);
}
if (lexer.token() == Token.WITH) {
lexer.nextToken();
if (identifierEquals("LOCAL")) {
lexer.nextToken();
timestamp.setWithLocalTimeZone(true);
} else {
timestamp.setWithTimeZone(true);
}
acceptIdentifier("TIME");
acceptIdentifier("ZONE");
}
return timestamp;
}
if (isCharType(typeName)) {
SQLCharacterDataType charType = new SQLCharacterDataType(typeName);
if (lexer.token() == Token.LPAREN) {
lexer.nextToken();
charType.addArgument(this.expr());
if (identifierEquals("CHAR")) {
lexer.nextToken();
charType.setCharType(SQLCharacterDataType.CHAR_TYPE_CHAR);
} else if (identifierEquals("BYTE")) {
lexer.nextToken();
charType.setCharType(SQLCharacterDataType.CHAR_TYPE_BYTE);
}
accept(Token.RPAREN);
}
return parseCharTypeRest(charType);
}
if (lexer.token() == Token.PERCENT) {
lexer.nextToken();
if (identifierEquals("TYPE")) {
lexer.nextToken();
typeName += "%TYPE";
} else if (identifierEquals("ROWTYPE")) {
lexer.nextToken();
typeName += "%ROWTYPE";
} else {
throw new ParserException("syntax error : " + lexer.token() + " " + lexer.stringVal());
}
}
SQLDataType dataType = new SQLDataTypeImpl(typeName);
return parseDataTypeRest(dataType);
}
Aggregations