use of com.alibaba.druid.sql.ast.statement.SQLCharacterDataType in project dble by actiontech.
the class GlobalTableUtil method createCheckColumn.
public static SQLColumnDefinition createCheckColumn() {
SQLColumnDefinition column = new SQLColumnDefinition();
column.setDataType(new SQLCharacterDataType("bigint"));
column.setName(new SQLIdentifierExpr(GLOBAL_TABLE_CHECK_COLUMN));
column.setComment(new SQLCharExpr("field for checking consistency"));
return column;
}
use of com.alibaba.druid.sql.ast.statement.SQLCharacterDataType in project Mycat-Server by MyCATApache.
the class GlobalTableUtil method addColumnIfCreate.
static String addColumnIfCreate(String sql, SQLStatement statement) {
if (isCreate(statement) && sql.trim().toUpperCase().startsWith("CREATE TABLE ") && !hasGlobalColumn(statement)) {
SQLColumnDefinition column = new SQLColumnDefinition();
column.setDataType(new SQLCharacterDataType("bigint"));
column.setName(new SQLIdentifierExpr(GLOBAL_TABLE_MYCAT_COLUMN));
column.setComment(new SQLCharExpr("全局表保存修改时间戳的字段名"));
((SQLCreateTableStatement) statement).getTableElementList().add(column);
}
return statement.toString();
}
use of com.alibaba.druid.sql.ast.statement.SQLCharacterDataType in project druid by alibaba.
the class SQLTransformUtils method transformOracleToAliyunAds.
public static SQLDataType transformOracleToAliyunAds(SQLDataType x) {
final String dataTypeName = x.getName().toLowerCase();
SQLDataType dataType;
if (dataTypeName.equals("varchar2") || dataTypeName.equals("varchar") || dataTypeName.equals("char") || dataTypeName.equals("nchar") || dataTypeName.equals("nvarchar") || dataTypeName.equals("nvarchar2") || dataTypeName.equals("clob") || dataTypeName.equals("nclob") || dataTypeName.equals("blob") || dataTypeName.equals("long") || dataTypeName.equals("long raw") || dataTypeName.equals("raw")) {
dataType = new SQLCharacterDataType("varchar");
} else if (dataTypeName.equals("number") || dataTypeName.equals("decimal") || dataTypeName.equals("dec") || dataTypeName.equals("numeric")) {
int scale = 0;
if (x.getArguments().size() > 1) {
scale = ((SQLIntegerExpr) x.getArguments().get(1)).getNumber().intValue();
}
if (scale == 0) {
dataType = new SQLDataTypeImpl("bigint");
} else {
dataType = new SQLDataTypeImpl("double");
}
} else if (dataTypeName.equals("date") || dataTypeName.equals("datetime") || dataTypeName.equals("timestamp")) {
dataType = new SQLDataTypeImpl("timestamp");
} else if (dataTypeName.equals("float") || dataTypeName.equals("binary_float")) {
dataType = new SQLDataTypeImpl("float");
} else if (dataTypeName.equals("double") || dataTypeName.equals("binary_double")) {
dataType = new SQLDataTypeImpl("double");
} else {
dataType = x;
}
if (dataType != x) {
dataType.setParent(x.getParent());
}
return dataType;
}
use of com.alibaba.druid.sql.ast.statement.SQLCharacterDataType in project druid by alibaba.
the class SQLExprParser method parseDataType.
public SQLDataType parseDataType() {
if (lexer.token() == Token.DEFAULT || lexer.token() == Token.NOT || lexer.token() == Token.NULL) {
return null;
}
SQLName typeExpr = name();
String typeName = typeExpr.toString();
if (//
"long".equalsIgnoreCase(typeName) && //
identifierEquals("byte") && //
JdbcConstants.MYSQL.equals(getDbType())) {
typeName += (' ' + lexer.stringVal());
lexer.nextToken();
} else if ("double".equalsIgnoreCase(typeName) && //
JdbcConstants.POSTGRESQL.equals(getDbType())) {
typeName += (' ' + lexer.stringVal());
lexer.nextToken();
}
if (isCharType(typeName)) {
SQLCharacterDataType charType = new SQLCharacterDataType(typeName);
if (lexer.token() == Token.LPAREN) {
lexer.nextToken();
SQLExpr arg = this.expr();
arg.setParent(charType);
charType.addArgument(arg);
accept(Token.RPAREN);
}
return parseCharTypeRest(charType);
}
if ("character".equalsIgnoreCase(typeName) && "varying".equalsIgnoreCase(lexer.stringVal())) {
typeName += ' ' + lexer.stringVal();
lexer.nextToken();
}
SQLDataType dataType = new SQLDataTypeImpl(typeName);
return parseDataTypeRest(dataType);
}
use of com.alibaba.druid.sql.ast.statement.SQLCharacterDataType 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