if (typeNumber == Integer.MIN_VALUE) {
if (includeUserTypes) {
checkIsSchemaObjectName();
String schemaName = session.getSchemaName(token.namePrefix);
Type type = database.schemaManager.getDomain(token.tokenString,
schemaName, false);
if (type != null) {
getRecordedToken().setExpression(type);
compileContext.addSchemaObject(type);
read();
return type;
}
}
throw Error.error(ErrorCode.X_42509, token.tokenString);
}
read();
switch (typeNumber) {
case Types.SQL_CHAR :
if (token.tokenType == Tokens.VARYING) {
read();
typeNumber = Types.SQL_VARCHAR;
} else if (token.tokenType == Tokens.LARGE) {
readThis(Tokens.OBJECT);
read();
typeNumber = Types.SQL_CLOB;
}
break;
case Types.SQL_DOUBLE :
if (token.tokenType == Tokens.PRECISION) {
read();
}
break;
case Types.SQL_BINARY :
if (token.tokenType == Tokens.VARYING) {
read();
typeNumber = Types.SQL_VARBINARY;
} else if (token.tokenType == Tokens.LARGE) {
readThis(Tokens.OBJECT);
read();
typeNumber = Types.SQL_BLOB;
}
break;
case Types.SQL_BIT :
if (token.tokenType == Tokens.VARYING) {
read();
typeNumber = Types.SQL_BIT_VARYING;
}
break;
case Types.SQL_INTERVAL :
return readIntervalType(false);
default :
}
long length = typeNumber == Types.SQL_TIMESTAMP
? DTIType.defaultTimestampFractionPrecision
: 0;
int scale = 0;
if (Types.requiresPrecision(typeNumber)
&& token.tokenType != Tokens.OPENBRACKET
&& database.sqlEnforceSize && !session.isProcessingScript) {
throw Error.error(ErrorCode.X_42599,
Type.getDefaultType(typeNumber).getNameString());
}
if (Types.acceptsPrecision(typeNumber)) {
if (token.tokenType == Tokens.OPENBRACKET) {
int multiplier = 1;
read();
switch (token.tokenType) {
case Tokens.X_VALUE :
if (token.dataType.typeCode != Types.SQL_INTEGER
&& token.dataType.typeCode
!= Types.SQL_BIGINT) {
throw unexpectedToken();
}
break;
case Tokens.X_LOB_SIZE :
if (typeNumber == Types.SQL_BLOB
|| typeNumber == Types.SQL_CLOB) {
switch (token.lobMultiplierType) {
case Tokens.K :
multiplier = 1024;
break;
case Tokens.M :
multiplier = 1024 * 1024;
break;
case Tokens.G :
multiplier = 1024 * 1024 * 1024;
break;
case Tokens.P :
case Tokens.T :
default :
throw unexpectedToken();
}
break;
} else {
throw unexpectedToken(token.getFullString());
}
default :
throw unexpectedToken();
}
hasLength = true;
length = ((Number) token.tokenValue).longValue();
if (length < 0
|| (length == 0
&& !Types.acceptsZeroPrecision(typeNumber))) {
throw Error.error(ErrorCode.X_42592);
}
length *= multiplier;
read();
if (typeNumber == Types.SQL_CHAR
|| typeNumber == Types.SQL_VARCHAR
|| typeNumber == Types.SQL_CLOB) {
if (token.tokenType == Tokens.CHARACTERS) {
read();
} else if (token.tokenType == Tokens.OCTETS) {
read();
length /= 2;
}
}
if (Types.acceptsScaleCreateParam(typeNumber)
&& token.tokenType == Tokens.COMMA) {
read();
scale = readInteger();
if (scale < 0) {
throw Error.error(ErrorCode.X_42592);
}
hasScale = true;
}
readThis(Tokens.CLOSEBRACKET);
} else if (typeNumber == Types.SQL_BIT) {
length = 1;
} else if (typeNumber == Types.SQL_BLOB
|| typeNumber == Types.SQL_CLOB) {
length = BlobType.defaultBlobSize;
} else if (database.sqlEnforceSize) {
// BIT is always BIT(1), regardless of sqlEnforceSize
if (typeNumber == Types.SQL_CHAR
|| typeNumber == Types.SQL_BINARY) {
length = 1;
}
}
if (typeNumber == Types.SQL_TIMESTAMP
|| typeNumber == Types.SQL_TIME) {
if (length > DTIType.maxFractionPrecision) {
throw Error.error(ErrorCode.X_42592);
}
scale = (int) length;
length = 0;
if (token.tokenType == Tokens.WITH) {
read();
readThis(Tokens.TIME);
readThis(Tokens.ZONE);
if (typeNumber == Types.SQL_TIMESTAMP) {
typeNumber = Types.SQL_TIMESTAMP_WITH_TIME_ZONE;
} else {
typeNumber = Types.SQL_TIME_WITH_TIME_ZONE;
}
} else if (token.tokenType == Tokens.WITHOUT) {
read();
readThis(Tokens.TIME);
readThis(Tokens.ZONE);
}
}
}
switch (typeNumber) {
case Types.LONGVARCHAR : {
typeNumber = Types.SQL_VARCHAR;
if (!hasLength) {
length = 1024 * 1024;
}
break;
}
case Types.LONGVARBINARY : {
typeNumber = Types.SQL_VARBINARY;
if (!hasLength) {
length = 1024 * 1024;
}
break;
}
case Types.SQL_CHAR :
case Types.SQL_BINARY :
break;
case Types.SQL_VARCHAR :
case Types.SQL_VARBINARY :
if (!hasLength) {
length = 32 * 1024;
}
break;
case Types.SQL_DECIMAL :
case Types.SQL_NUMERIC :
if (!hasLength && !hasScale && !database.sqlEnforceSize) {
length = NumberType.defaultNumericPrecision;
scale = NumberType.defaultNumericScale;
}
break;
}
if (session.ignoreCase && typeNumber == Types.SQL_VARCHAR) {
typeNumber = Types.VARCHAR_IGNORECASE;
}
Type typeObject = Type.getType(typeNumber, 0, length, scale);
if (typeObject.isCharacterType()) {
if (token.tokenType == Tokens.CHARACTER) {
read();
readThis(Tokens.SET);
checkIsSchemaObjectName();
String schemaName = session.getSchemaName(token.namePrefix);
Charset charset =
(Charset) database.schemaManager.getSchemaObject(
token.tokenString, schemaName, SchemaObject.CHARSET);
read();
}
}
if (token.tokenType == Tokens.ARRAY) {
if (typeObject.isLobType()) {
throw unexpectedToken();
}
read();