use of org.hsqldb_voltpatches.ColumnSchema in project voltdb by VoltDB.
the class DatabaseInformationFull method COLUMNS.
Table COLUMNS() {
Table t = sysTables[COLUMNS];
if (t == null) {
t = createBlankTable(sysTableHsqlNames[COLUMNS]);
//0
addColumn(t, "TABLE_CATALOG", SQL_IDENTIFIER);
addColumn(t, "TABLE_SCHEMA", SQL_IDENTIFIER);
addColumn(t, "TABLE_NAME", SQL_IDENTIFIER);
addColumn(t, "COLUMN_NAME", SQL_IDENTIFIER);
addColumn(t, "ORDINAL_POSITION", CARDINAL_NUMBER);
addColumn(t, "COLUMN_DEFAULT", CHARACTER_DATA);
addColumn(t, "IS_NULLABLE", YES_OR_NO);
addColumn(t, "DATA_TYPE", CHARACTER_DATA);
addColumn(t, "CHARACTER_MAXIMUM_LENGTH", CARDINAL_NUMBER);
addColumn(t, "CHARACTER_OCTET_LENGTH", CARDINAL_NUMBER);
//10
addColumn(t, "NUMERIC_PRECISION", CARDINAL_NUMBER);
addColumn(t, "NUMERIC_PRECISION_RADIX", CARDINAL_NUMBER);
addColumn(t, "NUMERIC_SCALE", CARDINAL_NUMBER);
addColumn(t, "DATETIME_PRECISION", CARDINAL_NUMBER);
addColumn(t, "INTERVAL_TYPE", CHARACTER_DATA);
addColumn(t, "INTERVAL_PRECISION", CARDINAL_NUMBER);
addColumn(t, "CHARACTER_SET_CATALOG", CHARACTER_DATA);
addColumn(t, "CHARACTER_SET_SCHEMA", SQL_IDENTIFIER);
addColumn(t, "CHARACTER_SET_NAME", SQL_IDENTIFIER);
addColumn(t, "COLLATION_CATALOG", SQL_IDENTIFIER);
//20
addColumn(t, "COLLATION_SCHEMA", SQL_IDENTIFIER);
addColumn(t, "COLLATION_NAME", SQL_IDENTIFIER);
addColumn(t, "DOMAIN_CATALOG", SQL_IDENTIFIER);
addColumn(t, "DOMAIN_SCHEMA", SQL_IDENTIFIER);
addColumn(t, "DOMAIN_NAME", SQL_IDENTIFIER);
addColumn(t, "UDT_CATALOG", SQL_IDENTIFIER);
addColumn(t, "UDT_SCHEMA", SQL_IDENTIFIER);
addColumn(t, "UDT_NAME", SQL_IDENTIFIER);
addColumn(t, "SCOPE_CATALOG", SQL_IDENTIFIER);
addColumn(t, "SCOPE_SCHEMA", SQL_IDENTIFIER);
//30
addColumn(t, "SCOPE_NAME", SQL_IDENTIFIER);
// NULL (only for array tyes)
addColumn(t, "MAXIMUM_CARDINALITY", CARDINAL_NUMBER);
addColumn(t, "DTD_IDENTIFIER", SQL_IDENTIFIER);
addColumn(t, "IS_SELF_REFERENCING", YES_OR_NO);
addColumn(t, "IS_IDENTITY", YES_OR_NO);
// ALLWAYS / BY DEFAULT
addColumn(t, "IDENTITY_GENERATION", CHARACTER_DATA);
addColumn(t, "IDENTITY_START", CHARACTER_DATA);
addColumn(t, "IDENTITY_INCREMENT", CHARACTER_DATA);
addColumn(t, "IDENTITY_MAXIMUM", CHARACTER_DATA);
addColumn(t, "IDENTITY_MINIMUM", CHARACTER_DATA);
//40
addColumn(t, "IDENTITY_CYCLE", YES_OR_NO);
// ALLWAYS / NEVER
addColumn(t, "IS_GENERATED", CHARACTER_DATA);
addColumn(t, "GENERATION_EXPRESSION", CHARACTER_DATA);
addColumn(t, "IS_UPDATABLE", YES_OR_NO);
addColumn(t, "DECLARED_DATA_TYPE", CHARACTER_DATA);
addColumn(t, "DECLARED_NUMERIC_PRECISION", CARDINAL_NUMBER);
addColumn(t, "DECLARED_NUMERIC_SCALE", CARDINAL_NUMBER);
// order: TABLE_SCHEM, TABLE_NAME, ORDINAL_POSITION
// added for unique: TABLE_CAT
// false PK, as TABLE_SCHEM and/or TABLE_CAT may be null
HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[COLUMNS].name, false, SchemaObject.INDEX);
t.createPrimaryKey(name, new int[] { 3, 2, 1, 4 }, false);
return t;
}
// column number mappings
final int table_cat = 0;
final int table_schem = 1;
final int table_name = 2;
final int column_name = 3;
final int ordinal_position = 4;
final int column_default = 5;
final int is_nullable = 6;
final int data_type = 7;
final int character_maximum_length = 8;
final int character_octet_length = 9;
final int numeric_precision = 10;
final int numeric_precision_radix = 11;
final int numeric_scale = 12;
final int datetime_precision = 13;
final int interval_type = 14;
final int interval_precision = 15;
final int character_set_catalog = 16;
final int character_set_schema = 17;
final int character_set_name = 18;
final int collation_catalog = 19;
final int collation_schema = 20;
final int collation_name = 21;
final int domain_catalog = 22;
final int domain_schema = 23;
final int domain_name = 24;
final int udt_catalog = 25;
final int udt_schema = 26;
final int udt_name = 27;
final int scope_catalog = 28;
final int scope_schema = 29;
final int scope_name = 30;
final int maximum_cardinality = 31;
final int dtd_identifier = 32;
final int is_self_referencing = 33;
final int is_identity = 34;
final int identity_generation = 35;
final int identity_start = 36;
final int identity_increment = 37;
final int identity_maximum = 38;
final int identity_minimum = 39;
final int identity_cycle = 40;
final int is_generated = 41;
final int generation_expression = 42;
final int is_updatable = 43;
final int declared_data_type = 44;
final int declared_numeric_precision = 45;
final int declared_numeric_scale = 46;
//
PersistentStore store = database.persistentStoreCollection.getStore(t);
// intermediate holders
int columnCount;
Iterator tables;
Table table;
Object[] row;
DITableInfo ti;
OrderedHashSet columnList;
Type type;
// Initialization
tables = allTables();
ti = new DITableInfo();
while (tables.hasNext()) {
table = (Table) tables.next();
columnList = session.getGrantee().getColumnsForAllPrivileges(table);
if (columnList.isEmpty()) {
continue;
}
ti.setTable(table);
columnCount = table.getColumnCount();
for (int i = 0; i < columnCount; i++) {
ColumnSchema column = table.getColumn(i);
type = column.getDataType();
if (!columnList.contains(column.getName())) {
continue;
}
row = t.getEmptyRowData();
row[table_cat] = table.getCatalogName().name;
row[table_schem] = table.getSchemaName().name;
row[table_name] = table.getName().name;
row[column_name] = column.getName().name;
row[ordinal_position] = ValuePool.getInt(i + 1);
row[column_default] = column.getDefaultSQL();
row[is_nullable] = column.isNullable() ? "YES" : "NO";
row[data_type] = type.getFullNameString();
if (type.isCharacterType()) {
row[character_maximum_length] = ValuePool.getLong(type.precision);
row[character_octet_length] = ValuePool.getLong(type.precision * 2);
row[character_set_catalog] = database.getCatalogName().name;
row[character_set_schema] = ((CharacterType) type).getCharacterSet().getSchemaName().name;
row[character_set_name] = ((CharacterType) type).getCharacterSet().getName().name;
row[collation_catalog] = database.getCatalogName().name;
row[collation_schema] = ((CharacterType) type).getCollation().getSchemaName().name;
row[collation_name] = ((CharacterType) type).getCollation().getName().name;
}
if (type.isBinaryType()) {
row[character_maximum_length] = ValuePool.getLong(type.precision);
row[character_octet_length] = ValuePool.getLong(type.precision);
}
if (type.isNumberType()) {
row[numeric_precision] = ValuePool.getLong(type.precision);
row[numeric_precision_radix] = ValuePool.getLong(((NumberType) type).getPrecisionRadix());
row[numeric_scale] = ValuePool.getLong(type.scale);
}
if (type.isDateTimeType()) {
row[datetime_precision] = ValuePool.getLong(type.scale);
}
if (type.isIntervalType()) {
row[interval_type] = IntervalType.getQualifier(type.typeCode);
row[interval_precision] = ValuePool.getLong(type.precision);
row[datetime_precision] = ValuePool.getLong(type.scale);
}
if (type.isDomainType()) {
row[domain_catalog] = database.getCatalogName().name;
row[domain_schema] = type.getSchemaName().name;
row[domain_name] = type.getName().name;
}
if (type.isDistinctType()) {
row[udt_catalog] = database.getCatalogName().name;
row[udt_schema] = type.getSchemaName().name;
row[udt_name] = type.getName().name;
}
row[scope_catalog] = null;
row[scope_schema] = null;
row[scope_name] = null;
row[maximum_cardinality] = null;
row[dtd_identifier] = null;
row[is_self_referencing] = null;
row[is_identity] = column.isIdentity() ? "YES" : "NO";
if (column.isIdentity()) {
NumberSequence sequence = column.getIdentitySequence();
row[identity_generation] = sequence.isAlways() ? "ALWAYS" : "BY DEFAULT";
row[identity_start] = Long.toString(sequence.getStartValue());
row[identity_increment] = Long.toString(sequence.getIncrement());
row[identity_maximum] = Long.toString(sequence.getMaxValue());
row[identity_minimum] = Long.toString(sequence.getMinValue());
row[identity_cycle] = sequence.isCycle() ? "YES" : "NO";
}
row[is_generated] = "NEVER";
row[generation_expression] = null;
row[is_updatable] = table.isWritable() ? "YES" : "NO";
row[declared_data_type] = row[data_type];
if (type.isNumberType()) {
row[declared_numeric_precision] = row[numeric_precision];
row[declared_numeric_scale] = row[numeric_scale];
}
t.insertSys(store, row);
}
}
return t;
}
use of org.hsqldb_voltpatches.ColumnSchema in project voltdb by VoltDB.
the class DITableInfo method getColSize.
/**
* Retrieves either the declared or maximum length/precision for
* the specified column, if its type allows a precision/length
* declaration, else null. <p>
*
* @param i zero-based column index
* @return the declared or maximum length/precision for
* the specified column
*/
Integer getColSize(int i) {
ColumnSchema column;
int type;
int size;
column = table.getColumn(i);
type = column.getDataType().getJDBCTypeCode();
if (!Types.acceptsPrecision(type)) {
return null;
}
size = column.getDataType().precision > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) column.getDataType().precision;
if (size > 0) {
return ValuePool.getInt(size);
} else {
ti.setTypeCode(type);
return ti.getPrecision();
}
}
use of org.hsqldb_voltpatches.ColumnSchema in project voltdb by VoltDB.
the class DatabaseInformationMain method SYSTEM_COLUMNS.
/**
* Retrieves a <code>Table</code> object describing the
* visible columns of all accessible tables defined
* within this database.<p>
*
* Each row is a column description with the following columns: <p>
*
* <pre class="SqlCodeExample">
* TABLE_CAT VARCHAR table catalog
* TABLE_SCHEM VARCHAR table schema
* TABLE_NAME VARCHAR table name
* COLUMN_NAME VARCHAR column name
* DATA_TYPE SMALLINT SQL type from DITypes
* TYPE_NAME VARCHAR canonical type name
* COLUMN_SIZE INTEGER column size (length/precision)
* BUFFER_LENGTH INTEGER transfer size in bytes, if definitely known
* DECIMAL_DIGITS INTEGER # of fractional digits (scale)
* NUM_PREC_RADIX INTEGER Radix
* NULLABLE INTEGER is NULL allowed? (from DatabaseMetaData)
* REMARKS VARCHAR comment describing column
* COLUMN_DEF VARCHAR default value (possibly expression) for the
* column, which should be interpreted as a
* string when the value is enclosed in quotes
* (may be <code>null</code>)
* SQL_DATA_TYPE VARCHAR type code as expected in the SQL CLI SQLDA
* SQL_DATETIME_SUB INTEGER the SQL CLI subtype for DATETIME types
* CHAR_OCTET_LENGTH INTEGER for char types, max # of bytes in column
* ORDINAL_POSITION INTEGER 1-based index of column in table
* IS_NULLABLE VARCHAR is column nullable? ("YES"|"NO"|""}
* SCOPE_CATLOG VARCHAR catalog of REF attribute scope table
* SCOPE_SCHEMA VARCHAR schema of REF attribute scope table
* SCOPE_TABLE VARCHAR name of REF attribute scope table
* SOURCE_DATA_TYPE VARCHAR source type of REF attribute
* TYPE_SUB INTEGER HSQLDB data subtype code
* </pre> <p>
*
* @return a <code>Table</code> object describing the
* visible columns of all accessible
* tables defined within this database.<p>
*/
final Table SYSTEM_COLUMNS() {
Table t = sysTables[SYSTEM_COLUMNS];
if (t == null) {
t = createBlankTable(sysTableHsqlNames[SYSTEM_COLUMNS]);
// 0
addColumn(t, "TABLE_CAT", SQL_IDENTIFIER);
// 1
addColumn(t, "TABLE_SCHEM", SQL_IDENTIFIER);
// not null
addColumn(t, "TABLE_NAME", SQL_IDENTIFIER);
// not null
addColumn(t, "COLUMN_NAME", SQL_IDENTIFIER);
// not null
addColumn(t, "DATA_TYPE", Type.SQL_SMALLINT);
// not null
addColumn(t, "TYPE_NAME", SQL_IDENTIFIER);
// 6
addColumn(t, "COLUMN_SIZE", Type.SQL_INTEGER);
// 7
addColumn(t, "BUFFER_LENGTH", Type.SQL_INTEGER);
// 8
addColumn(t, "DECIMAL_DIGITS", Type.SQL_INTEGER);
// 9
addColumn(t, "NUM_PREC_RADIX", Type.SQL_INTEGER);
// not null
addColumn(t, "NULLABLE", Type.SQL_INTEGER);
// 11
addColumn(t, "REMARKS", CHARACTER_DATA);
// 12
addColumn(t, "COLUMN_DEF", CHARACTER_DATA);
// 13
addColumn(t, "SQL_DATA_TYPE", Type.SQL_INTEGER);
// 14
addColumn(t, "SQL_DATETIME_SUB", Type.SQL_INTEGER);
// 15
addColumn(t, "CHAR_OCTET_LENGTH", Type.SQL_INTEGER);
// not null
addColumn(t, "ORDINAL_POSITION", Type.SQL_INTEGER);
// not null
addColumn(t, "IS_NULLABLE", YES_OR_NO);
// 18
addColumn(t, "SCOPE_CATLOG", SQL_IDENTIFIER);
// 19
addColumn(t, "SCOPE_SCHEMA", SQL_IDENTIFIER);
// 20
addColumn(t, "SCOPE_TABLE", SQL_IDENTIFIER);
// 21
addColumn(t, "SOURCE_DATA_TYPE", SQL_IDENTIFIER);
// ----------------------------------------------------------------
// JDBC 4.0 - added Mustang b86
// ----------------------------------------------------------------
// not null
addColumn(t, "IS_AUTOINCREMENT", Type.SQL_BOOLEAN);
// ----------------------------------------------------------------
// HSQLDB-specific
// ----------------------------------------------------------------
// not null
addColumn(t, "TYPE_SUB", Type.SQL_INTEGER);
// order: TABLE_SCHEM, TABLE_NAME, ORDINAL_POSITION
// added for unique: TABLE_CAT
// false PK, as TABLE_SCHEM and/or TABLE_CAT may be null
HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[SYSTEM_COLUMNS].name, false, SchemaObject.INDEX);
t.createPrimaryKey(name, new int[] { 0, 1, 2, 16 }, false);
return t;
}
PersistentStore store = database.persistentStoreCollection.getStore(t);
// calculated column values
String tableCatalog;
String tableSchema;
String tableName;
// intermediate holders
int columnCount;
Iterator tables;
Table table;
Object[] row;
DITableInfo ti;
// column number mappings
final int itable_cat = 0;
final int itable_schem = 1;
final int itable_name = 2;
final int icolumn_name = 3;
final int idata_type = 4;
final int itype_name = 5;
final int icolumn_size = 6;
final int ibuffer_length = 7;
final int idecimal_digits = 8;
final int inum_prec_radix = 9;
final int inullable = 10;
final int iremark = 11;
final int icolumn_def = 12;
final int isql_data_type = 13;
final int isql_datetime_sub = 14;
final int ichar_octet_length = 15;
final int iordinal_position = 16;
final int iis_nullable = 17;
final int iscope_cat = 18;
final int iscope_schem = 19;
final int iscope_table = 20;
final int isrc_data_type = 21;
// JDBC 4.0
final int iis_autoinc = 22;
// HSQLDB-specific
final int itype_sub = 23;
// Initialization
tables = allTables();
ti = new DITableInfo();
// Do it.
while (tables.hasNext()) {
table = (Table) tables.next();
/** @todo - requires access to the actual columns */
if (!isAccessibleTable(table)) {
continue;
}
ti.setTable(table);
tableCatalog = table.getCatalogName().name;
tableSchema = table.getSchemaName().name;
tableName = ti.getName();
columnCount = table.getColumnCount();
Type[] types = table.getColumnTypes();
for (int i = 0; i < columnCount; i++) {
ColumnSchema column = table.getColumn(i);
row = t.getEmptyRowData();
//
row[itable_cat] = tableCatalog;
row[itable_schem] = tableSchema;
row[itable_name] = tableName;
row[icolumn_name] = column.getName().name;
row[idata_type] = types[i].getJDBCTypeCode();
row[itype_name] = types[i].getNameString();
row[icolumn_size] = types[i].getJDBCPrecision();
row[ibuffer_length] = null;
row[idecimal_digits] = types[i].getJDBCScale();
row[inum_prec_radix] = ti.getColPrecRadix(i);
row[inullable] = column.getNullability();
row[iremark] = ti.getColRemarks(i);
row[icolumn_def] = column.getDefaultSQL();
row[isql_data_type] = types[i].getJDBCTypeCode();
row[isql_datetime_sub] = ti.getColSqlDateTimeSub(i);
row[ichar_octet_length] = ti.getColCharOctLen(i);
row[iordinal_position] = ValuePool.getInt(i + 1);
row[iis_nullable] = ti.getColIsNullable(i);
// JDBC 4.0
row[iis_autoinc] = ti.getColIsIdentity(i);
// HSQLDB-specific
row[itype_sub] = ti.getColDataTypeSub(i);
t.insertSys(store, row);
}
}
return t;
}
use of org.hsqldb_voltpatches.ColumnSchema in project voltdb by VoltDB.
the class DatabaseInformationMain method addColumn.
protected final void addColumn(Table t, String name, Type type) {
HsqlName cn;
ColumnSchema c;
cn = database.nameManager.newInfoSchemaColumnName(name, t.getName());
c = new ColumnSchema(cn, type, true, false, null);
t.addColumn(c);
}
use of org.hsqldb_voltpatches.ColumnSchema in project voltdb by VoltDB.
the class RowOutputBase method writeData.
/**
* This method is called directly to write data for a delete statement.
*/
public void writeData(int l, Type[] types, Object[] data, HashMappedList cols, int[] primaryKeys) {
boolean hasPK = primaryKeys != null && primaryKeys.length != 0;
int limit = hasPK ? primaryKeys.length : l;
for (int i = 0; i < limit; i++) {
int j = hasPK ? primaryKeys[i] : i;
Object o = data[j];
Type t = types[j];
if (cols != null) {
ColumnSchema col = (ColumnSchema) cols.get(j);
writeFieldPrefix();
writeString(col.getName().statementName);
}
if (o == null) {
writeNull(t);
continue;
}
writeFieldType(t);
switch(t.typeCode) {
case Types.SQL_ALL_TYPES:
throw Error.runtimeError(ErrorCode.U_S0500, "RowOutputBase");
case Types.SQL_CHAR:
case Types.SQL_VARCHAR:
case Types.VARCHAR_IGNORECASE:
writeChar((String) o, t);
break;
case Types.TINYINT:
case Types.SQL_SMALLINT:
writeSmallint((Number) o);
break;
case Types.SQL_INTEGER:
writeInteger((Number) o);
break;
case Types.SQL_BIGINT:
writeBigint((Number) o);
break;
case Types.SQL_REAL:
case Types.SQL_FLOAT:
case Types.SQL_DOUBLE:
writeReal((Double) o);
break;
case Types.SQL_NUMERIC:
case Types.SQL_DECIMAL:
writeDecimal((BigDecimal) o, t);
break;
case Types.SQL_BOOLEAN:
writeBoolean((Boolean) o);
break;
case Types.SQL_DATE:
writeDate((TimestampData) o, t);
break;
case Types.SQL_TIME:
case Types.SQL_TIME_WITH_TIME_ZONE:
writeTime((TimeData) o, t);
break;
case Types.SQL_TIMESTAMP:
case Types.SQL_TIMESTAMP_WITH_TIME_ZONE:
writeTimestamp((TimestampData) o, t);
break;
case Types.SQL_INTERVAL_YEAR:
case Types.SQL_INTERVAL_YEAR_TO_MONTH:
case Types.SQL_INTERVAL_MONTH:
writeYearMonthInterval((IntervalMonthData) o, t);
break;
case Types.SQL_INTERVAL_DAY:
case Types.SQL_INTERVAL_DAY_TO_HOUR:
case Types.SQL_INTERVAL_DAY_TO_MINUTE:
case Types.SQL_INTERVAL_DAY_TO_SECOND:
case Types.SQL_INTERVAL_HOUR:
case Types.SQL_INTERVAL_HOUR_TO_MINUTE:
case Types.SQL_INTERVAL_HOUR_TO_SECOND:
case Types.SQL_INTERVAL_MINUTE:
case Types.SQL_INTERVAL_MINUTE_TO_SECOND:
case Types.SQL_INTERVAL_SECOND:
writeDaySecondInterval((IntervalSecondData) o, t);
break;
case Types.OTHER:
writeOther((JavaObjectData) o);
break;
case Types.SQL_BLOB:
writeBlob((BlobData) o, t);
break;
case Types.SQL_CLOB:
writeClob((ClobData) o, t);
break;
case Types.SQL_BINARY:
case Types.SQL_VARBINARY:
writeBinary((BinaryData) o);
break;
case Types.SQL_BIT:
case Types.SQL_BIT_VARYING:
writeBit((BinaryData) o);
break;
default:
throw Error.runtimeError(ErrorCode.U_S0500, t.getNameString());
}
}
}
Aggregations