use of org.hsqldb_voltpatches.types.Type in project voltdb by VoltDB.
the class DatabaseInformationFull method ROUTINES.
Table ROUTINES() {
Table t = sysTables[ROUTINES];
if (t == null) {
t = createBlankTable(sysTableHsqlNames[ROUTINES]);
addColumn(t, "SPECIFIC_CATALOG", SQL_IDENTIFIER);
addColumn(t, "SPECIFIC_SCHEMA", SQL_IDENTIFIER);
addColumn(t, "SPECIFIC_NAME", SQL_IDENTIFIER);
addColumn(t, "ROUTINE_CATALOG", SQL_IDENTIFIER);
addColumn(t, "ROUTINE_SCHEMA", SQL_IDENTIFIER);
addColumn(t, "ROUTINE_NAME", SQL_IDENTIFIER);
addColumn(t, "ROUTINE_TYPE", CHARACTER_DATA);
addColumn(t, "MODULE_CATALOG", SQL_IDENTIFIER);
addColumn(t, "MODULE_SCHEMA", SQL_IDENTIFIER);
addColumn(t, "MODULE_NAME", SQL_IDENTIFIER);
addColumn(t, "UDT_CATALOG", SQL_IDENTIFIER);
addColumn(t, "UDT_SCHEMA", SQL_IDENTIFIER);
addColumn(t, "UDT_NAME", SQL_IDENTIFIER);
addColumn(t, "DATA_TYPE", CHARACTER_DATA);
addColumn(t, "CHARACTER_MAXIMUM_LENGTH", CARDINAL_NUMBER);
addColumn(t, "CHARACTER_OCTET_LENGTH", CARDINAL_NUMBER);
addColumn(t, "CHARACTER_SET_CATALOG", SQL_IDENTIFIER);
addColumn(t, "CHARACTER_SET_SCHEMA", SQL_IDENTIFIER);
addColumn(t, "CHARACTER_SET_NAME", SQL_IDENTIFIER);
addColumn(t, "COLLATION_CATALOG", SQL_IDENTIFIER);
//
addColumn(t, "COLLATION_SCHEMA", SQL_IDENTIFIER);
addColumn(t, "COLLATION_NAME", SQL_IDENTIFIER);
//
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, "TYPE_UDT_CATALOG", SQL_IDENTIFIER);
addColumn(t, "TYPE_UDT_SCHEMA", SQL_IDENTIFIER);
addColumn(t, "TYPE_UDT_NAME", SQL_IDENTIFIER);
addColumn(t, "SCOPE_CATALOG", SQL_IDENTIFIER);
addColumn(t, "SCOPE_SCHEMA", SQL_IDENTIFIER);
//
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, "ROUTINE_BODY", CHARACTER_DATA);
addColumn(t, "ROUTINE_DEFINITION", CHARACTER_DATA);
addColumn(t, "EXTERNAL_NAME", CHARACTER_DATA);
addColumn(t, "EXTERNAL_LANGUAGE", CHARACTER_DATA);
addColumn(t, "PARAMETER_STYLE", CHARACTER_DATA);
addColumn(t, "IS_DETERMINISTIC", YES_OR_NO);
addColumn(t, "SQL_DATA_ACCESS", CHARACTER_DATA);
addColumn(t, "IS_NULL_CALL", YES_OR_NO);
addColumn(t, "SQL_PATH", CHARACTER_DATA);
//
addColumn(t, "SCHEMA_LEVEL_ROUTINE", YES_OR_NO);
addColumn(t, "MAX_DYNAMIC_RESULT_SETS", CARDINAL_NUMBER);
addColumn(t, "IS_USER_DEFINED_CAST", YES_OR_NO);
addColumn(t, "IS_IMPLICITLY_INVOCABLE", YES_OR_NO);
addColumn(t, "SECURITY_TYPE", CHARACTER_DATA);
addColumn(t, "TO_SQL_SPECIFIC_CATALOG", SQL_IDENTIFIER);
//
addColumn(t, "TO_SQL_SPECIFIC_SCHEMA", SQL_IDENTIFIER);
addColumn(t, "TO_SQL_SPECIFIC_NAME", SQL_IDENTIFIER);
addColumn(t, "AS_LOCATOR", YES_OR_NO);
addColumn(t, "CREATED", TIME_STAMP);
addColumn(t, "LAST_ALTERED", TIME_STAMP);
addColumn(t, "NEW_SAVEPOINT_LEVEL", YES_OR_NO);
addColumn(t, "IS_UDT_DEPENDENT", YES_OR_NO);
addColumn(t, "RESULT_CAST_FROM_DATA_TYPE", CHARACTER_DATA);
addColumn(t, "RESULT_CAST_AS_LOCATOR", YES_OR_NO);
addColumn(t, "RESULT_CAST_CHAR_MAX_LENGTH", CARDINAL_NUMBER);
addColumn(t, "RESULT_CAST_CHAR_OCTET_LENGTH", CARDINAL_NUMBER);
addColumn(t, "RESULT_CAST_CHAR_SET_CATALOG", CHARACTER_DATA);
addColumn(t, "RESULT_CAST_CHAR_SET_SCHEMA", SQL_IDENTIFIER);
addColumn(t, "RESULT_CAST_CHARACTER_SET_NAME", SQL_IDENTIFIER);
addColumn(t, "RESULT_CAST_COLLATION_CATALOG", SQL_IDENTIFIER);
addColumn(t, "RESULT_CAST_COLLATION_SCHEMA", SQL_IDENTIFIER);
addColumn(t, "RESULT_CAST_COLLATION_NAME", SQL_IDENTIFIER);
addColumn(t, "RESULT_CAST_NUMERIC_PRECISION", CARDINAL_NUMBER);
addColumn(t, "RESULT_CAST_NUMERIC_RADIX", CARDINAL_NUMBER);
addColumn(t, "RESULT_CAST_NUMERIC_SCALE", CARDINAL_NUMBER);
addColumn(t, "RESULT_CAST_DATETIME_PRECISION", CARDINAL_NUMBER);
addColumn(t, "RESULT_CAST_INTERVAL_TYPE", CHARACTER_DATA);
addColumn(t, "RESULT_CAST_INTERVAL_PRECISION", CARDINAL_NUMBER);
addColumn(t, "RESULT_CAST_TYPE_UDT_CATALOG", SQL_IDENTIFIER);
addColumn(t, "RESULT_CAST_TYPE_UDT_SCHEMA", SQL_IDENTIFIER);
addColumn(t, "RESULT_CAST_TYPE_UDT_NAME", SQL_IDENTIFIER);
addColumn(t, "RESULT_CAST_SCOPE_CATALOG", SQL_IDENTIFIER);
addColumn(t, "RESULT_CAST_SCOPE_SCHEMA", SQL_IDENTIFIER);
addColumn(t, "RESULT_CAST_SCOPE_NAME", SQL_IDENTIFIER);
addColumn(t, "RESULT_CAST_MAX_CARDINALITY", CARDINAL_NUMBER);
addColumn(t, "RESULT_CAST_DTD_IDENTIFIER", CHARACTER_DATA);
addColumn(t, "DECLARED_DATA_TYPE", CHARACTER_DATA);
addColumn(t, "DECLARED_NUMERIC_PRECISION", CARDINAL_NUMBER);
addColumn(t, "DECLARED_NUMERIC_SCALE", CARDINAL_NUMBER);
addColumn(t, "RESULT_CAST_FROM_DECLARED_DATA_TYPE", CHARACTER_DATA);
addColumn(t, "RESULT_CAST_DECLARED_NUMERIC_PRECISION", CARDINAL_NUMBER);
addColumn(t, "RESULT_CAST_DECLARED_NUMERIC_SCALE", CARDINAL_NUMBER);
HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[ROUTINES].name, false, SchemaObject.INDEX);
t.createPrimaryKey(name, new int[] { 3, 4, 5, 0, 1, 2 }, false);
return t;
}
// column number mappings
final int specific_catalog = 0;
final int specific_schema = 1;
final int specific_name = 2;
final int routine_catalog = 3;
final int routine_schema = 4;
final int routine_name = 5;
final int routine_type = 6;
final int module_catalog = 7;
final int module_schema = 8;
final int module_name = 9;
final int udt_catalog = 10;
final int udt_schema = 11;
final int udt_name = 12;
final int data_type = 13;
final int character_maximum_length = 14;
final int character_octet_length = 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 numeric_precision = 22;
final int numeric_precision_radix = 23;
final int numeric_scale = 24;
final int datetime_precision = 25;
final int interval_type = 26;
final int interval_precision = 27;
final int type_udt_catalog = 28;
final int type_udt_schema = 29;
final int type_udt_name = 30;
final int scope_catalog = 31;
final int scope_schema = 32;
final int scope_name = 33;
final int maximum_cardinality = 34;
final int dtd_identifier = 35;
final int routine_body = 36;
final int routine_definition = 37;
final int external_name = 38;
final int external_language = 39;
final int parameter_style = 40;
final int is_deterministic = 41;
final int sql_data_access = 42;
final int is_null_call = 43;
final int sql_path = 44;
final int schema_level_routine = 45;
final int max_dynamic_result_sets = 46;
final int is_user_defined_cast = 47;
final int is_implicitly_invocable = 48;
final int security_type = 49;
final int to_sql_specific_catalog = 50;
final int to_sql_specific_schema = 51;
final int to_sql_specific_name = 52;
final int as_locator = 53;
final int created = 54;
final int last_altered = 55;
final int new_savepoint_level = 56;
final int is_udt_dependent = 57;
final int result_cast_from_data_type = 58;
final int result_cast_as_locator = 59;
final int result_cast_char_max_length = 60;
final int result_cast_char_octet_length = 61;
final int result_cast_char_set_catalog = 62;
final int result_cast_char_set_schema = 63;
final int result_cast_character_set_name = 64;
final int result_cast_collation_catalog = 65;
final int result_cast_collation_schema = 66;
final int result_cast_collation_name = 67;
final int result_cast_numeric_precision = 68;
final int result_cast_numeric_radix = 69;
final int result_cast_numeric_scale = 70;
final int result_cast_datetime_precision = 71;
final int result_cast_interval_type = 72;
final int result_cast_interval_precision = 73;
final int result_cast_type_udt_catalog = 74;
final int result_cast_type_udt_schema = 75;
final int result_cast_type_udt_name = 76;
final int result_cast_scope_catalog = 77;
final int result_cast_scope_schema = 78;
final int result_cast_scope_name = 79;
final int result_cast_max_cardinality = 80;
final int result_cast_dtd_identifier = 81;
final int declared_data_type = 82;
final int declared_numeric_precision = 83;
final int declared_numeric_scale = 84;
final int result_cast_from_declared_data_type = 85;
final int result_cast_declared_numeric_precision = 86;
final int result_cast_declared_numeric_scale = 87;
//
PersistentStore store = database.persistentStoreCollection.getStore(t);
Iterator it;
Object[] row;
it = database.schemaManager.databaseObjectIterator(SchemaObject.ROUTINE);
while (it.hasNext()) {
RoutineSchema routine = (RoutineSchema) it.next();
if (!session.getGrantee().isAccessible(routine)) {
continue;
}
Routine[] specifics = routine.getSpecificRoutines();
for (int m = 0; m < specifics.length; m++) {
row = t.getEmptyRowData();
Routine specific = specifics[m];
Type type = specific.isProcedure() ? null : specific.getReturnType();
//
row[specific_catalog] = database.getCatalogName().name;
row[specific_schema] = specific.getSchemaName().name;
row[specific_name] = specific.getSpecificName().name;
row[routine_catalog] = database.getCatalogName().name;
row[routine_schema] = routine.getSchemaName().name;
row[routine_name] = specific.getName().name;
row[routine_type] = specific.isProcedure() ? "PROCEDURE" : "FUNCTION";
row[module_catalog] = null;
row[module_schema] = null;
row[module_name] = null;
row[udt_catalog] = null;
row[udt_schema] = null;
row[udt_name] = null;
row[data_type] = type == null ? null : type.getNameString();
if (type != null && 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 != null && type.isNumberType()) {
row[numeric_precision] = ValuePool.getLong(type.precision);
row[numeric_precision_radix] = ValuePool.getLong(((NumberType) type).getPrecisionRadix());
row[numeric_scale] = ValuePool.getLong(type.precision);
}
if (type != null && (type.isIntervalType() || type.isDateTimeType())) {
row[datetime_precision] = ValuePool.getLong(type.scale);
}
if (type != null && type.isIntervalType()) {
row[interval_type] = IntervalType.getQualifier(type.typeCode);
row[interval_precision] = ValuePool.getLong(type.precision);
}
row[type_udt_catalog] = null;
row[type_udt_schema] = null;
row[type_udt_name] = null;
row[scope_catalog] = null;
row[scope_schema] = null;
row[scope_name] = null;
row[maximum_cardinality] = null;
//**
row[dtd_identifier] = null;
row[routine_body] = specific.getLanguage() == Routine.LANGUAGE_JAVA ? "EXTERNAL" : "SQL";
row[routine_definition] = specific.getSQL();
row[external_name] = specific.getLanguage() == Routine.LANGUAGE_JAVA ? specific.getMethod().getName() : null;
row[external_language] = specific.getLanguage() == Routine.LANGUAGE_JAVA ? "JAVA" : null;
row[parameter_style] = specific.getLanguage() == Routine.LANGUAGE_JAVA ? "JAVA" : null;
row[is_deterministic] = specific.isDeterministic() ? "YES" : "NO";
row[sql_data_access] = specific.getDataImpactString();
row[is_null_call] = type == null ? null : specific.isNullInputOutput() ? "YES" : "NO";
row[sql_path] = null;
row[schema_level_routine] = "YES";
row[max_dynamic_result_sets] = ValuePool.getLong(0);
row[is_user_defined_cast] = type == null ? null : "NO";
row[is_implicitly_invocable] = null;
row[security_type] = "DEFINER";
row[to_sql_specific_catalog] = null;
row[to_sql_specific_schema] = null;
row[to_sql_specific_name] = null;
row[as_locator] = type == null ? null : "NO";
row[created] = null;
row[last_altered] = null;
row[new_savepoint_level] = "YES";
row[is_udt_dependent] = null;
row[result_cast_from_data_type] = null;
row[result_cast_as_locator] = null;
row[result_cast_char_max_length] = null;
row[result_cast_char_octet_length] = null;
row[result_cast_char_set_catalog] = null;
row[result_cast_char_set_schema] = null;
row[result_cast_character_set_name] = null;
row[result_cast_collation_catalog] = null;
row[result_cast_collation_schema] = null;
row[result_cast_collation_name] = null;
row[result_cast_numeric_precision] = null;
row[result_cast_numeric_radix] = null;
row[result_cast_numeric_scale] = null;
row[result_cast_datetime_precision] = null;
row[result_cast_interval_type] = null;
row[result_cast_interval_precision] = null;
row[result_cast_type_udt_catalog] = null;
row[result_cast_type_udt_schema] = null;
row[result_cast_type_udt_name] = null;
row[result_cast_scope_catalog] = null;
row[result_cast_scope_schema] = null;
row[result_cast_scope_name] = null;
row[result_cast_max_cardinality] = null;
row[result_cast_dtd_identifier] = null;
row[declared_data_type] = row[data_type];
row[declared_numeric_precision] = row[numeric_precision];
row[declared_numeric_scale] = row[numeric_scale];
row[result_cast_from_declared_data_type] = null;
row[result_cast_declared_numeric_precision] = null;
row[result_cast_declared_numeric_scale] = null;
t.insertSys(store, row);
}
}
return t;
}
use of org.hsqldb_voltpatches.types.Type in project voltdb by VoltDB.
the class DatabaseInformationMain method SYSTEM_BESTROWIDENTIFIER.
/**
* Retrieves a <code>Table</code> object describing the optimal
* set of visible columns that uniquely identifies a row
* for each accessible table defined within this database. <p>
*
* Each row describes a single column of the best row indentifier column
* set for a particular table. Each row has the following
* columns: <p>
*
* <pre class="SqlCodeExample">
* SCOPE SMALLINT scope of applicability
* COLUMN_NAME VARCHAR simple name of the column
* DATA_TYPE SMALLINT SQL data type from Types
* TYPE_NAME VARCHAR canonical type name
* COLUMN_SIZE INTEGER precision
* BUFFER_LENGTH INTEGER transfer size in bytes, if definitely known
* DECIMAL_DIGITS SMALLINT scale - fixed # of decimal digits
* PSEUDO_COLUMN SMALLINT is this a pseudo column like an Oracle ROWID?
* TABLE_CAT VARCHAR table catalog
* TABLE_SCHEM VARCHAR simple name of table schema
* TABLE_NAME VARCHAR simple table name
* NULLABLE SMALLINT is column nullable?
* IN_KEY BOOLEAN column belongs to a primary or alternate key?
* </pre> <p>
*
* <b>Notes:</b><p>
*
* <code>JDBCDatabaseMetaData.getBestRowIdentifier</code> uses its
* nullable parameter to filter the rows of this table in the following
* manner: <p>
*
* If the nullable parameter is <code>false</code>, then rows are reported
* only if, in addition to satisfying the other specified filter values,
* the IN_KEY column value is TRUE. If the nullable parameter is
* <code>true</code>, then the IN_KEY column value is ignored. <p>
*
* There is not yet infrastructure in place to make some of the ranking
* descisions described below, and it is anticipated that mechanisms
* upon which cost descisions could be based will change significantly over
* the next few releases. Hence, in the interest of simplicity and of not
* making overly complex dependency on features that will almost certainly
* change significantly in the near future, the current implementation,
* while perfectly adequate for all but the most demanding or exacting
* purposes, is actually sub-optimal in the strictest sense. <p>
*
* A description of the current implementation follows: <p>
*
* <b>DEFINTIONS:</b> <p>
*
* <b>Alternate key</b> <p>
*
* <UL>
* <LI> An attribute of a table that, by virtue of its having a set of
* columns that are both the full set of columns participating in a
* unique constraint or index and are all not null, yeilds the same
* selectability characteristic that would obtained by declaring a
* primary key on those same columns.
* </UL> <p>
*
* <b>Column set performance ranking</b> <p>
*
* <UL>
* <LI> The ranking of the expected average performance w.r.t a subset of
* a table's columns used to select and/or compare rows, as taken in
* relation to all other distinct candidate subsets under
* consideration. This can be estimated by comparing each cadidate
* subset in terms of total column count, relative peformance of
* comparisons amongst the domains of the columns and differences
* in other costs involved in the execution plans generated using
* each subset under consideration for row selection/comparison.
* </UL> <p>
*
*
* <b>Rules:</b> <p>
*
* Given the above definitions, the rules currently in effect for reporting
* best row identifier are as follows, in order of precedence: <p>
*
* <OL>
* <LI> if the table under consideration has a primary key contraint, then
* the columns of the primary key are reported, with no consideration
* given to the column set performance ranking over the set of
* candidate keys. Each row has its IN_KEY column set to TRUE.
*
* <LI> if 1.) does not hold, then if there exits one or more alternate
* keys, then the columns of the alternate key with the lowest column
* count are reported, with no consideration given to the column set
* performance ranking over the set of candidate keys. If there
* exists a tie for lowest column count, then the columns of the
* first such key encountered are reported.
* Each row has its IN_KEY column set to TRUE.
*
* <LI> if both 1.) and 2.) do not hold, then, if possible, a unique
* contraint/index is selected from the set of unique
* contraints/indices containing at least one column having
* a not null constraint, with no consideration given to the
* column set performance ranking over the set of all such
* candidate column sets. If there exists a tie for lowest non-zero
* count of columns having a not null constraint, then the columns
* of the first such encountered candidate set are reported. Each
* row has its IN_KEY column set to FALSE. <p>
*
* <LI> Finally, if the set of candidate column sets in 3.) is the empty,
* then no column set is reported for the table under consideration.
* </OL> <p>
*
* The scope reported for a best row identifier column set is determined
* thus: <p>
*
* <OL>
* <LI> if the database containing the table under consideration is in
* read-only mode or the table under consideration is GLOBAL TEMPORARY
* (a TEMP or TEMP TEXT table, in HSQLDB parlance), then the scope
* is reported as
* <code>java.sql.DatabaseMetaData.bestRowSession</code>.
*
* <LI> if 1.) does not hold, then the scope is reported as
* <code>java.sql.DatabaseMetaData.bestRowTemporary</code>.
* </OL> <p>
*
* @return a <code>Table</code> object describing the optimal
* set of visible columns that uniquely identifies a row
* for each accessible table defined within this database
*/
final Table SYSTEM_BESTROWIDENTIFIER() {
Table t = sysTables[SYSTEM_BESTROWIDENTIFIER];
if (t == null) {
t = createBlankTable(sysTableHsqlNames[SYSTEM_BESTROWIDENTIFIER]);
// not null
addColumn(t, "SCOPE", Type.SQL_SMALLINT);
// 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);
addColumn(t, "COLUMN_SIZE", Type.SQL_INTEGER);
addColumn(t, "BUFFER_LENGTH", Type.SQL_INTEGER);
addColumn(t, "DECIMAL_DIGITS", Type.SQL_SMALLINT);
// not null
addColumn(t, "PSEUDO_COLUMN", Type.SQL_SMALLINT);
addColumn(t, "TABLE_CAT", SQL_IDENTIFIER);
addColumn(t, "TABLE_SCHEM", SQL_IDENTIFIER);
// not null
addColumn(t, "TABLE_NAME", SQL_IDENTIFIER);
// not null
addColumn(t, "NULLABLE", Type.SQL_SMALLINT);
// not null
addColumn(t, "IN_KEY", Type.SQL_BOOLEAN);
// order: SCOPE
// for unique: TABLE_CAT, TABLE_SCHEM, TABLE_NAME, COLUMN_NAME
// false PK, as TABLE_CAT and/or TABLE_SCHEM may be null
HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[SYSTEM_BESTROWIDENTIFIER].name, false, SchemaObject.INDEX);
t.createPrimaryKey(name, new int[] { 0, 8, 9, 10, 1 }, false);
return t;
}
PersistentStore store = database.persistentStoreCollection.getStore(t);
// calculated column values
// { temp, transaction, session }
Integer scope;
Integer pseudo;
//-------------------------------------------
// required for restriction of results via
// DatabaseMetaData filter parameters, but
// not actually required to be included in
// DatabaseMetaData.getBestRowIdentifier()
// result set
//-------------------------------------------
// table calalog
String tableCatalog;
// table schema
String tableSchema;
// table name
String tableName;
// column participates in PK or AK?
Boolean inKey;
//-------------------------------------------
/**
* @todo - Maybe include: - backing index (constraint) name?
* - column sequence in index (constraint)?
*/
//-------------------------------------------
// Intermediate holders
Iterator tables;
Table table;
DITableInfo ti;
int[] cols;
Object[] row;
HsqlProperties p;
// Column number mappings
final int iscope = 0;
final int icolumn_name = 1;
final int idata_type = 2;
final int itype_name = 3;
final int icolumn_size = 4;
final int ibuffer_length = 5;
final int idecimal_digits = 6;
final int ipseudo_column = 7;
final int itable_cat = 8;
final int itable_schem = 9;
final int itable_name = 10;
final int inullable = 11;
final int iinKey = 12;
// Initialization
ti = new DITableInfo();
tables = database.schemaManager.databaseObjectIterator(SchemaObject.TABLE);
// Do it.
while (tables.hasNext()) {
table = (Table) tables.next();
/** @todo - requires access to the actual columns */
if (table.isView() || !isAccessibleTable(table)) {
continue;
}
cols = table.getBestRowIdentifiers();
if (cols == null) {
continue;
}
ti.setTable(table);
inKey = ValuePool.getBoolean(table.isBestRowIdentifiersStrict());
tableCatalog = table.getCatalogName().name;
tableSchema = table.getSchemaName().name;
tableName = table.getName().name;
Type[] types = table.getColumnTypes();
scope = ti.getBRIScope();
pseudo = ti.getBRIPseudo();
for (int i = 0; i < cols.length; i++) {
ColumnSchema column = table.getColumn(i);
row = t.getEmptyRowData();
row[iscope] = scope;
row[icolumn_name] = column.getName().name;
row[idata_type] = ValuePool.getInt(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[ipseudo_column] = pseudo;
row[itable_cat] = tableCatalog;
row[itable_schem] = tableSchema;
row[itable_name] = tableName;
row[inullable] = column.getNullability();
row[iinKey] = inKey;
t.insertSys(store, row);
}
}
return t;
}
use of org.hsqldb_voltpatches.types.Type in project voltdb by VoltDB.
the class DatabaseInformationFull method CHECK_CONSTRAINTS.
/**
* The CHECK_CONSTRAINTS view has one row for each domain
* constraint, table check constraint, and assertion. <p>
*
* <b>Definition:</b><p>
*
* <pre class="SqlCodeExample">
* CONSTRAINT_CATALOG VARCHAR NULL,
* CONSTRAINT_SCHEMA VARCHAR NULL,
* CONSTRAINT_NAME VARCHAR NOT NULL,
* CHECK_CLAUSE VARCHAR NOT NULL,
* </pre>
*
* <b>Description:</b><p>
*
* <ol>
* <li> A constraint is shown in this view if the authorization for the
* schema that contains the constraint is the current user or is a role
* assigned to the current user. <p>
*
* <li> The values of CONSTRAINT_CATALOG, CONSTRAINT_SCHEMA and
* CONSTRAINT_NAME are the catalog name, unqualified schema name,
* and qualified identifier, respectively, of the constraint being
* described. <p>
*
* <li> Case: <p>
*
* <table>
* <tr>
* <td valign="top" halign="left">a)</td>
* <td> If the character representation of the
* <search condition> contained in the
* <check constraint definition>,
* <domain constraint definition>, or
* <assertion definition> that defined
* the check constraint being described can be
* represented without truncation, then the
* value of CHECK_CLAUSE is that character
* representation. </td>
* </tr>
* <tr>
* <td align="top" halign="left">b)</td>
* <td>Otherwise, the value of CHECK_CLAUSE is the
* null value.</td>
* </tr>
* </table>
* </ol>
*
* @return Table
*/
Table CHECK_CONSTRAINTS() {
Table t = sysTables[CHECK_CONSTRAINTS];
if (t == null) {
t = createBlankTable(sysTableHsqlNames[CHECK_CONSTRAINTS]);
addColumn(t, "CONSTRAINT_CATALOG", SQL_IDENTIFIER);
addColumn(t, "CONSTRAINT_SCHEMA", SQL_IDENTIFIER);
// not null
addColumn(t, "CONSTRAINT_NAME", SQL_IDENTIFIER);
// not null
addColumn(t, "CHECK_CLAUSE", CHARACTER_DATA);
HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[CHECK_CONSTRAINTS].name, false, SchemaObject.INDEX);
t.createPrimaryKey(name, new int[] { 2, 1, 0 }, false);
return t;
}
// column number mappings
final int constraint_catalog = 0;
final int constraint_schema = 1;
final int constraint_name = 2;
final int check_clause = 3;
//
PersistentStore store = database.persistentStoreCollection.getStore(t);
// calculated column values
// Intermediate holders
Iterator tables;
Table table;
Constraint[] tableConstraints;
int constraintCount;
Constraint constraint;
Object[] row;
//
tables = database.schemaManager.databaseObjectIterator(SchemaObject.TABLE);
while (tables.hasNext()) {
table = (Table) tables.next();
if (table.isView() || !session.getGrantee().isFullyAccessibleByRole(table)) {
continue;
}
tableConstraints = table.getConstraints();
constraintCount = tableConstraints.length;
for (int i = 0; i < constraintCount; i++) {
constraint = tableConstraints[i];
if (constraint.getConstraintType() != Constraint.CHECK) {
continue;
}
row = t.getEmptyRowData();
row[constraint_catalog] = database.getCatalogName().name;
row[constraint_schema] = table.getSchemaName().name;
row[constraint_name] = constraint.getName().name;
try {
row[check_clause] = constraint.getCheckSQL();
} catch (Exception e) {
}
t.insertSys(store, row);
}
}
Iterator it = database.schemaManager.databaseObjectIterator(SchemaObject.DOMAIN);
while (it.hasNext()) {
Type domain = (Type) it.next();
if (!domain.isDomainType()) {
continue;
}
if (!session.getGrantee().isFullyAccessibleByRole(domain)) {
continue;
}
tableConstraints = domain.userTypeModifier.getConstraints();
constraintCount = tableConstraints.length;
for (int i = 0; i < constraintCount; i++) {
constraint = tableConstraints[i];
row = t.getEmptyRowData();
row[constraint_catalog] = database.getCatalogName().name;
row[constraint_schema] = domain.getSchemaName().name;
row[constraint_name] = constraint.getName().name;
try {
row[check_clause] = constraint.getCheckSQL();
} catch (Exception e) {
}
t.insertSys(store, row);
}
}
return t;
}
use of org.hsqldb_voltpatches.types.Type in project voltdb by VoltDB.
the class Table method getSQL.
@Override
public String getSQL() {
StringBuffer sb = new StringBuffer();
sb.append(Tokens.T_CREATE).append(' ');
if (isTemp()) {
sb.append(Tokens.T_GLOBAL).append(' ');
sb.append(Tokens.T_TEMPORARY).append(' ');
} else if (isText()) {
sb.append(Tokens.T_TEXT).append(' ');
} else if (isCached()) {
sb.append(Tokens.T_CACHED).append(' ');
} else {
sb.append(Tokens.T_MEMORY).append(' ');
}
sb.append(Tokens.T_TABLE).append(' ');
sb.append(getName().getSchemaQualifiedStatementName());
sb.append('(');
int columns = getColumnCount();
int[] pk = getPrimaryKey();
Constraint pkConst = getPrimaryConstraint();
for (int j = 0; j < columns; j++) {
ColumnSchema column = getColumn(j);
String colname = column.getName().statementName;
Type type = column.getDataType();
if (j > 0) {
sb.append(',');
}
sb.append(colname);
sb.append(' ');
sb.append(type.getTypeDefinition());
String defaultString = column.getDefaultSQL();
if (defaultString != null) {
sb.append(' ').append(Tokens.T_DEFAULT).append(' ');
sb.append(defaultString);
}
if (column.isIdentity()) {
sb.append(' ').append(column.getIdentitySequence().getSQL());
}
if (!column.isNullable()) {
Constraint c = getNotNullConstraintForColumn(j);
if (c != null && !c.getName().isReservedName()) {
sb.append(' ').append(Tokens.T_CONSTRAINT).append(' ').append(c.getName().statementName);
}
sb.append(' ').append(Tokens.T_NOT).append(' ').append(Tokens.T_NULL);
}
if (pk.length == 1 && j == pk[0] && pkConst.getName().isReservedName()) {
sb.append(' ').append(Tokens.T_PRIMARY).append(' ').append(Tokens.T_KEY);
}
}
Constraint[] constraintList = getConstraints();
for (int j = 0, vSize = constraintList.length; j < vSize; j++) {
Constraint c = constraintList[j];
if (!c.isForward) {
String d = c.getSQL();
if (d.length() > 0) {
sb.append(',');
sb.append(d);
}
}
}
sb.append(')');
if (onCommitPreserve()) {
sb.append(' ').append(Tokens.T_ON).append(' ');
sb.append(Tokens.T_COMMIT).append(' ').append(Tokens.T_PRESERVE);
sb.append(' ').append(Tokens.T_ROWS);
}
return sb.toString();
}
use of org.hsqldb_voltpatches.types.Type in project voltdb by VoltDB.
the class StatementSchema method dropDomain.
private static void dropDomain(Session session, HsqlName name, boolean cascade) {
Type domain = (Type) session.database.schemaManager.getSchemaObject(name);
OrderedHashSet set = session.database.schemaManager.getReferencingObjects(domain.getName());
if (!cascade && set.size() > 0) {
HsqlName objectName = (HsqlName) set.get(0);
throw Error.error(ErrorCode.X_42502, objectName.getSchemaQualifiedStatementName());
}
Constraint[] constraints = domain.userTypeModifier.getConstraints();
set.clear();
for (int i = 0; i < constraints.length; i++) {
set.add(constraints[i].getName());
}
session.database.schemaManager.removeSchemaObjects(set);
session.database.schemaManager.removeSchemaObject(domain.getName(), cascade);
domain.userTypeModifier = null;
}
Aggregations