for (int index = 1; index <= numColumns; index++)
{
boolean nullableResult =
(rsmd.isNullable(index) != ResultSetMetaData.columnNoNulls);
TypeId cti;
int jdbcColumnType = rsmd.getColumnType(index);
switch (jdbcColumnType) {
case Types.JAVA_OBJECT:
case Types.OTHER:
{
cti = TypeId.getUserDefinedTypeId(rsmd.getColumnTypeName(index), false);
break;
}
default:
{
cti = TypeId.getBuiltInTypeId(jdbcColumnType);
break;
}
}
// Handle the case where a VTI returns a bad column type
if (cti == null)
{
throw StandardException.newException(SQLState.LANG_BAD_J_D_B_C_TYPE_INFO, Integer.toString(index));
}
// Get the maximum byte storage for this column
int maxWidth;
/* Get maximum byte storage from rsmd for variable
* width types, set it to MAXINT for the long types,
* otherwise get it from the TypeId
*/
if (cti.variableLength())
{
maxWidth = rsmd.getColumnDisplaySize(index);
}
else if (jdbcColumnType == Types.LONGVARCHAR ||
jdbcColumnType == Types.LONGVARBINARY)
{
maxWidth = Integer.MAX_VALUE;
}
else
{
maxWidth = 0;
}
int precision = cti.isDecimalTypeId() ? rsmd.getPrecision(index) : 0;
int scale = cti.isDecimalTypeId() ? rsmd.getScale(index) : 0;
DataTypeDescriptor dts = new DataTypeDescriptor(cti,
precision,
scale,
nullableResult,
maxWidth);