// That will set the correct length and perform truncation checks etc.
ResultColumn typeCol =
(ResultColumn) typeColumns.elementAt(index);
TypeId colTypeId = typeCol.getTypeId();
if (colTypeId.isStringTypeId()) {
if (colTypeId.getJDBCTypeId() != java.sql.Types.CHAR) {
int maxWidth = re.getTypeServices().getMaximumWidth();
re.setType(new DataTypeDescriptor(colTypeId, true, maxWidth));
}
}
else if (colTypeId.isBitTypeId()) {
if (colTypeId.getJDBCTypeId() == java.sql.Types.VARBINARY) {
// then we're trying to cast a char literal into a
// variable bit column. We can't change the base
// type of the table constructor's value from char
// to bit, so instead, we just change the base type
// of that value from char to varchar--that way,
// no padding will be added when we convert to
// bits later on (Beetle 5306).
TypeId tId = TypeId.getBuiltInTypeId(java.sql.Types.VARCHAR);
re.setType(new DataTypeDescriptor(tId, true));
typeColumns.setElementAt(typeCol, index);
}
else if (colTypeId.getJDBCTypeId() == java.sql.Types.LONGVARBINARY) {
TypeId tId = TypeId.getBuiltInTypeId(java.sql.Types.LONGVARCHAR);
re.setType(new DataTypeDescriptor(tId, true));
typeColumns.setElementAt(typeCol, index);
}
}
}
else if (re instanceof BitConstantNode)
{
ResultColumn typeCol =
(ResultColumn) typeColumns.elementAt(index);
TypeId colTypeId = typeCol.getTypeId();
if (colTypeId.isBitTypeId()) {
// NOTE: Don't bother doing this if the column type is BLOB,
// as we don't allow bit literals to be inserted into BLOB
// columns (they have to be explicitly casted first); beetle 5266.
if ((colTypeId.getJDBCTypeId() != java.sql.Types.BINARY) &&
(colTypeId.getJDBCTypeId() != java.sql.Types.BLOB)) {
int maxWidth = re.getTypeServices().getMaximumWidth();
re.setType(new DataTypeDescriptor(colTypeId, true, maxWidth));
}
}
else if (colTypeId.isStringTypeId()) {
if (colTypeId.getJDBCTypeId() == java.sql.Types.VARCHAR) {
// then we're trying to cast a bit literal into a
// variable char column. We can't change the base
// type of the table constructor's value from bit
// to char, so instead, we just change the base
// type of that value from bit to varbit--that way,
// no padding will be added when we convert to
// char later on.
TypeId tId = TypeId.getBuiltInTypeId(java.sql.Types.VARBINARY);
re.setType(new DataTypeDescriptor(tId, true));
typeColumns.setElementAt(typeCol, index);
}
else if (colTypeId.getJDBCTypeId() == java.sql.Types.LONGVARCHAR) {
TypeId tId = TypeId.getBuiltInTypeId(java.sql.Types.LONGVARBINARY);
re.setType(new DataTypeDescriptor(tId, true));
typeColumns.setElementAt(typeCol, index);
}
}
}