use of org.hsqldb_voltpatches.View in project voltdb by VoltDB.
the class DatabaseInformationFull method VIEW_COLUMN_USAGE.
/**
* The VIEW_COLUMN_USAGE table has one row for each column of a
* table that is explicitly or implicitly referenced in the
* <query expression> of the view being described. <p>
*
* <b>Definition:</b> <p>
*
* <pre class="SqlCodeExample">
* CREATE TABLE SYSTEM_VIEW_COLUMN_USAGE (
* VIEW_CATALOG VARCHAR NULL,
* VIEW_SCHEMA VARCHAR NULL,
* VIEW_NAME VARCHAR NOT NULL,
* TABLE_CATALOG VARCHAR NULL,
* TABLE_SCHEMA VARCHAR NULL,
* TABLE_NAME VARCHAR NOT NULL,
* COLUMN_NAME VARCHAR NOT NULL,
* UNIQUE ( VIEW_CATALOG, VIEW_SCHEMA, VIEW_NAME,
* TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME,
* COLUMN_NAME )
* )
* </pre>
*
* <b>Description:</b> <p>
*
* <ol>
* <li> The values of VIEW_CATALOG, VIEW_SCHEMA, and VIEW_NAME are the
* catalog name, unqualified schema name, and qualified identifier,
* respectively, of the view being described. <p>
*
* <li> The values of TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME, and
* COLUMN_NAME are the catalog name, unqualified schema name,
* qualified identifier, and column name, respectively, of a column
* of a table that is explicitly or implicitly referenced in the
* <query expression> of the view being described.
* </ol>
*
* @return Table
*/
Table VIEW_COLUMN_USAGE() {
Table t = sysTables[VIEW_COLUMN_USAGE];
if (t == null) {
t = createBlankTable(sysTableHsqlNames[VIEW_COLUMN_USAGE]);
addColumn(t, "VIEW_CATALOG", SQL_IDENTIFIER);
addColumn(t, "VIEW_SCHEMA", SQL_IDENTIFIER);
addColumn(t, "VIEW_NAME", SQL_IDENTIFIER);
addColumn(t, "TABLE_CATALOG", SQL_IDENTIFIER);
addColumn(t, "TABLE_SCHEMA", SQL_IDENTIFIER);
addColumn(t, "TABLE_NAME", SQL_IDENTIFIER);
addColumn(t, "COLUMN_NAME", SQL_IDENTIFIER);
HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[VIEW_COLUMN_USAGE].name, false, SchemaObject.INDEX);
t.createPrimaryKey(name, new int[] { 0, 1, 2, 3, 4, 5, 6 }, false);
return t;
}
PersistentStore store = database.persistentStoreCollection.getStore(t);
// Calculated column values
String viewCatalog;
String viewSchema;
String viewName;
// Intermediate holders
Iterator tables;
View view;
Table table;
Object[] row;
Iterator iterator;
// Column number mappings
final int view_catalog = 0;
final int view_schema = 1;
final int view_name = 2;
final int table_catalog = 3;
final int table_schema = 4;
final int table_name = 5;
final int column_name = 6;
// Initialization
tables = database.schemaManager.databaseObjectIterator(SchemaObject.TABLE);
// Do it.
while (tables.hasNext()) {
table = (Table) tables.next();
if (table.isView() && session.getGrantee().isFullyAccessibleByRole(table)) {
// $FALL-THROUGH$
} else {
continue;
}
viewCatalog = database.getCatalogName().name;
viewSchema = table.getSchemaName().name;
viewName = table.getName().name;
view = (View) table;
OrderedHashSet references = view.getReferences();
iterator = references.iterator();
while (iterator.hasNext()) {
HsqlName refName = (HsqlName) iterator.next();
if (refName.type == SchemaObject.COLUMN) {
row = t.getEmptyRowData();
row[view_catalog] = viewCatalog;
row[view_schema] = viewSchema;
row[view_name] = viewName;
row[table_catalog] = viewCatalog;
row[table_schema] = refName.parent.schema.name;
row[table_name] = refName.parent.name;
row[column_name] = refName.name;
try {
t.insertSys(store, row);
} catch (HsqlException e) {
}
}
}
}
return t;
}
use of org.hsqldb_voltpatches.View in project voltdb by VoltDB.
the class DatabaseInformationFull method VIEWS.
/**
* The VIEWS view contains one row for each VIEW definition. <p>
*
* Each row is a description of the query expression that defines its view,
* with the following columns:
*
* <pre class="SqlCodeExample">
* TABLE_CATALOG VARCHAR name of view's defining catalog.
* TABLE_SCHEMA VARCHAR name of view's defining schema.
* TABLE_NAME VARCHAR the simple name of the view.
* VIEW_DEFINITION VARCHAR the character representation of the
* <query expression> contained in the
* corresponding <view descriptor>.
* CHECK_OPTION VARCHAR {"CASCADED" | "LOCAL" | "NONE"}
* IS_UPDATABLE VARCHAR {"YES" | "NO"}
* INSERTABLE_INTO VARCHAR {"YES" | "NO"}
* IS_TRIGGER_UPDATABLE VARCHAR {"YES" | "NO"}
* IS_TRIGGER_DELETEABLE VARCHAR {"YES" | "NO"}
* IS_TRIGGER_INSERTABLE_INTO VARCHAR {"YES" | "NO"}
* </pre> <p>
*
* @return a tabular description of the text source of all
* <code>View</code> objects accessible to
* the user.
*/
Table VIEWS() {
Table t = sysTables[VIEWS];
if (t == null) {
t = createBlankTable(sysTableHsqlNames[VIEWS]);
addColumn(t, "TABLE_CATALOG", SQL_IDENTIFIER);
addColumn(t, "TABLE_SCHEMA", SQL_IDENTIFIER);
// not null
addColumn(t, "TABLE_NAME", SQL_IDENTIFIER);
// not null
addColumn(t, "VIEW_DEFINITION", CHARACTER_DATA);
// not null
addColumn(t, "CHECK_OPTION", CHARACTER_DATA);
// not null
addColumn(t, "IS_UPDATABLE", YES_OR_NO);
// not null
addColumn(t, "INSERTABLE_INTO", YES_OR_NO);
// not null
addColumn(t, "IS_TRIGGER_UPDATABLE", YES_OR_NO);
// not null
addColumn(t, "IS_TRIGGER_DELETABLE", YES_OR_NO);
// not null
addColumn(t, "IS_TRIGGER_INSERTABLE_INTO", YES_OR_NO);
// order TABLE_NAME
// added for unique: TABLE_SCHEMA, TABLE_CATALOG
// false PK, as TABLE_SCHEMA and/or TABLE_CATALOG may be null
HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[VIEWS].name, false, SchemaObject.INDEX);
t.createPrimaryKey(name, new int[] { 1, 2, 0 }, false);
return t;
}
PersistentStore store = database.persistentStoreCollection.getStore(t);
Iterator tables;
Table table;
Object[] row;
final int table_catalog = 0;
final int table_schema = 1;
final int table_name = 2;
final int view_definition = 3;
final int check_option = 4;
final int is_updatable = 5;
final int insertable_into = 6;
final int is_trigger_updatable = 7;
final int is_trigger_deletable = 8;
final int is_trigger_insertable_into = 9;
tables = allTables();
while (tables.hasNext()) {
table = (Table) tables.next();
if ((table.getSchemaName() != SqlInvariants.INFORMATION_SCHEMA_HSQLNAME && !table.isView()) || !isAccessibleTable(table)) {
continue;
}
row = t.getEmptyRowData();
row[table_catalog] = database.getCatalogName().name;
row[table_schema] = table.getSchemaName().name;
row[table_name] = table.getName().name;
String check = Tokens.T_NONE;
if (table instanceof View) {
if (session.getGrantee().isFullyAccessibleByRole(table)) {
row[view_definition] = ((View) table).getStatement();
}
switch(((View) table).getCheckOption()) {
case SchemaObject.ViewCheckModes.CHECK_NONE:
break;
case SchemaObject.ViewCheckModes.CHECK_LOCAL:
check = Tokens.T_LOCAL;
break;
case SchemaObject.ViewCheckModes.CHECK_CASCADE:
check = Tokens.T_CASCADED;
break;
}
}
row[check_option] = check;
row[is_updatable] = table.isUpdatable() ? Tokens.T_YES : Tokens.T_NO;
row[insertable_into] = table.isInsertable() ? Tokens.T_YES : Tokens.T_NO;
// only applies to INSTEAD OF triggers
row[is_trigger_updatable] = null;
row[is_trigger_deletable] = null;
row[is_trigger_insertable_into] = null;
t.insertSys(store, row);
}
return t;
}
Aggregations