* @return a <code>Table</code> object describing the
* system-defined SQL types supported as table columns
*/
final Table SYSTEM_TYPEINFO(Session session) {
Table t = sysTables[SYSTEM_TYPEINFO];
if (t == null) {
t = createBlankTable(sysTableHsqlNames[SYSTEM_TYPEINFO]);
//-------------------------------------------
// required by JDBC:
// ------------------------------------------
addColumn(t, "TYPE_NAME", SQL_IDENTIFIER);
addColumn(t, "DATA_TYPE", Type.SQL_SMALLINT);
addColumn(t, "PRECISION", Type.SQL_INTEGER);
addColumn(t, "LITERAL_PREFIX", CHARACTER_DATA);
addColumn(t, "LITERAL_SUFFIX", CHARACTER_DATA);
addColumn(t, "CREATE_PARAMS", CHARACTER_DATA);
addColumn(t, "NULLABLE", Type.SQL_SMALLINT);
addColumn(t, "CASE_SENSITIVE", Type.SQL_BOOLEAN);
addColumn(t, "SEARCHABLE", Type.SQL_INTEGER);
addColumn(t, "UNSIGNED_ATTRIBUTE", Type.SQL_BOOLEAN);
addColumn(t, "FIXED_PREC_SCALE", Type.SQL_BOOLEAN);
addColumn(t, "AUTO_INCREMENT", Type.SQL_BOOLEAN);
addColumn(t, "LOCAL_TYPE_NAME", SQL_IDENTIFIER);
addColumn(t, "MINIMUM_SCALE", Type.SQL_SMALLINT);
addColumn(t, "MAXIMUM_SCALE", Type.SQL_SMALLINT);
addColumn(t, "SQL_DATA_TYPE", Type.SQL_INTEGER);
addColumn(t, "SQL_DATETIME_SUB", Type.SQL_INTEGER);
addColumn(t, "NUM_PREC_RADIX", Type.SQL_INTEGER);
//-------------------------------------------
// SQL CLI / ODBC - not in JDBC spec
// ------------------------------------------
addColumn(t, "INTERVAL_PRECISION", Type.SQL_INTEGER);
// order: DATA_TYPE, TYPE_NAME
// true primary key
HsqlName name = HsqlNameManager.newInfoSchemaObjectName(
sysTableHsqlNames[SYSTEM_TYPEINFO].name, false,
SchemaObject.INDEX);
t.createPrimaryKeyConstraint(name, new int[] {
1, 0
}, true);
return t;
}
//-----------------------------------------
// Same as SYSTEM_TYPEINFO
//-----------------------------------------
final int itype_name = 0;
final int idata_type = 1;
final int iprecision = 2;
final int iliteral_prefix = 3;
final int iliteral_suffix = 4;
final int icreate_params = 5;
final int inullable = 6;
final int icase_sensitive = 7;
final int isearchable = 8;
final int iunsigned_attribute = 9;
final int ifixed_prec_scale = 10;
final int iauto_increment = 11;
final int ilocal_type_name = 12;
final int iminimum_scale = 13;
final int imaximum_scale = 14;
final int isql_data_type = 15;
final int isql_datetime_sub = 16;
final int inum_prec_radix = 17;
//------------------------------------------
// Extensions
//------------------------------------------
// not in JDBC, but in SQL CLI SQLDA / ODBC
//------------------------------------------
final int iinterval_precision = 18;
PersistentStore store = session.sessionData.getRowStore(t);
Object[] row;
Iterator it = Type.typeNames.keySet().iterator();
boolean translateDTI = database.getProperties().isPropertyTrue(
HsqlDatabaseProperties.jdbc_translate_dti_types);
while (it.hasNext()) {
String typeName = (String) it.next();
int typeCode = Type.typeNames.get(typeName);
Type type = Type.getDefaultType(typeCode);
if (type == null) {
continue;
}
if (translateDTI) {
if (type.isIntervalType()) {
type = CharacterType.getCharacterType(Types.SQL_VARCHAR,
type.displaySize());
} else if (type.isDateTimeTypeWithZone()) {
type = ((DateTimeType) type).getDateTimeTypeWithoutZone();
}
}
row = t.getEmptyRowData();
row[itype_name] = typeName;
row[idata_type] = ValuePool.getInt(type.getJDBCTypeCode());
long maxPrecision = type.getMaxPrecision();
row[iprecision] = maxPrecision > Integer.MAX_VALUE
? ValuePool.INTEGER_MAX
: ValuePool.getInt((int) maxPrecision);
if (type.isBinaryType() || type.isCharacterType()
|| type.isDateTimeType() || type.isIntervalType()) {
row[iliteral_prefix] = "\'";
row[iliteral_suffix] = "\'";
}
if (type.acceptsPrecision() && type.acceptsScale()) {
row[icreate_params] = "PRECISION,SCALE";
} else if (type.acceptsPrecision()) {
row[icreate_params] = type.isNumberType() ? "PRECISION"
: "LENGTH";
} else if (type.acceptsScale()) {
row[icreate_params] = "SCALE";
}
row[inullable] = ValuePool.INTEGER_1;
row[icase_sensitive] =
type.isCharacterType()
&& type.typeCode != Types.VARCHAR_IGNORECASE ? Boolean.TRUE
: Boolean.FALSE;
if (type.isLobType()) {
row[isearchable] = ValuePool.INTEGER_0;
} else if (type.isCharacterType()
|| (type.isBinaryType() && !type.isBitType())) {
row[isearchable] = ValuePool.getInt(3);
} else {
row[isearchable] = ValuePool.getInt(2);
}
row[iunsigned_attribute] = Boolean.FALSE;
row[ifixed_prec_scale] =
type.typeCode == Types.SQL_NUMERIC
|| type.typeCode == Types.SQL_DECIMAL ? Boolean.TRUE
: Boolean.FALSE;
row[iauto_increment] = type.isIntegralType() ? Boolean.TRUE
: Boolean.FALSE;
row[ilocal_type_name] = null;
row[iminimum_scale] = ValuePool.INTEGER_0;
row[imaximum_scale] = ValuePool.getInt(type.getMaxScale());
row[isql_data_type] = null;
row[isql_datetime_sub] = null;
row[inum_prec_radix] = ValuePool.getInt(type.getPrecisionRadix());
//------------------------------------------
if (type.isIntervalType()) {
row[iinterval_precision] = null;
}
t.insertSys(store, row);
}
row = t.getEmptyRowData();
row[itype_name] = "DISTINCT";
row[idata_type] = ValuePool.getInt(Types.DISTINCT);
return t;
}