use of org.hsqldb_voltpatches.HsqlNameManager.HsqlName in project voltdb by VoltDB.
the class ParserDDL method compileCreateSchema.
StatementSchema compileCreateSchema() {
HsqlName schemaName = null;
String authorisation = null;
read();
if (token.tokenType != Tokens.AUTHORIZATION) {
schemaName = readNewSchemaName();
}
if (token.tokenType == Tokens.AUTHORIZATION) {
read();
checkIsSimpleName();
authorisation = token.tokenString;
read();
if (schemaName == null) {
Grantee owner = database.getGranteeManager().get(authorisation);
if (owner == null) {
throw Error.error(ErrorCode.X_28501, authorisation);
}
schemaName = database.nameManager.newHsqlName(owner.getName().name, isDelimitedIdentifier(), SchemaObject.SCHEMA);
SqlInvariants.checkSchemaNameNotSystem(token.tokenString);
}
}
if (SqlInvariants.PUBLIC_ROLE_NAME.equals(authorisation)) {
throw Error.error(ErrorCode.X_28502, authorisation);
}
Grantee owner = authorisation == null ? session.getGrantee() : database.getGranteeManager().get(authorisation);
if (owner == null) {
throw Error.error(ErrorCode.X_28501, authorisation);
}
if (!session.getGrantee().isSchemaCreator()) {
throw Error.error(ErrorCode.X_0L000, session.getGrantee().getNameString());
}
if (database.schemaManager.schemaExists(schemaName.name)) {
throw Error.error(ErrorCode.X_42504, schemaName.name);
}
String sql = getLastPart();
Object[] args = new Object[] { schemaName, owner };
HsqlArrayList list = new HsqlArrayList();
StatementSchema cs = new StatementSchema(sql, StatementTypes.CREATE_SCHEMA, args, null, null);
cs.setSchemaHsqlName(schemaName);
list.add(cs);
getCompiledStatementBody(list);
StatementSchema[] array = new StatementSchema[list.size()];
list.toArray(array);
boolean swapped;
do {
swapped = false;
for (int i = 0; i < array.length - 1; i++) {
if (array[i].order > array[i + 1].order) {
StatementSchema temp = array[i + 1];
array[i + 1] = array[i];
array[i] = temp;
swapped = true;
}
}
} while (swapped);
return new StatementSchemaDefinition(array);
}
use of org.hsqldb_voltpatches.HsqlNameManager.HsqlName in project voltdb by VoltDB.
the class StatementSchema method dropRoutine.
private void dropRoutine(Session session, HsqlName name, boolean cascade) {
HsqlName routineName = session.database.schemaManager.getSchemaObjectName(name.schema, name.name, name.type, true);
checkSchemaUpdateAuthorisation(session, name.schema);
session.database.schemaManager.removeSchemaObject(routineName, cascade);
}
use of org.hsqldb_voltpatches.HsqlNameManager.HsqlName in project voltdb by VoltDB.
the class StatementSchema method dropSchema.
private void dropSchema(Session session, HsqlName name, boolean cascade) {
HsqlName schema = session.database.schemaManager.getUserSchemaHsqlName(name.name);
checkSchemaUpdateAuthorisation(session, schema);
session.database.schemaManager.dropSchema(name.name, cascade);
}
use of org.hsqldb_voltpatches.HsqlNameManager.HsqlName in project voltdb by VoltDB.
the class DatabaseInformationMain method SYSTEM_PROCEDURES.
/**
* Retrieves a <code>Table</code> object describing the accessible
* routines defined within this database.
*
* Each row is a procedure description with the following
* columns: <p>
*
* <pre class="SqlCodeExample">
* PROCEDURE_CAT VARCHAR catalog in which routine is defined
* PROCEDURE_SCHEM VARCHAR schema in which routine is defined
* PROCEDURE_NAME VARCHAR simple routine identifier
* NUM_INPUT_PARAMS INTEGER number of input parameters
* NUM_OUTPUT_PARAMS INTEGER number of output parameters
* NUM_RESULT_SETS INTEGER number of result sets returned
* REMARKS VARCHAR explanatory comment on the routine
* PROCEDURE_TYPE SMALLINT { Unknown | No Result | Returns Result }
* // JDBC 4.0
* SPECIFIC_NAME VARCHAR The name which uniquely identifies this
* procedure within its schema.
* typically (but not restricted to) a
* fully qualified Java Method name
* and signature.
* // HSQLDB extension
* ORIGIN VARCHAR {ALIAS |
* [BUILTIN | USER DEFINED] ROUTINE |
* [BUILTIN | USER DEFINED] TRIGGER |
* ...}
* </pre> <p>
*
* @return a <code>Table</code> object describing the accessible
* routines defined within the this database
*/
Table SYSTEM_PROCEDURES() {
Table t = sysTables[SYSTEM_PROCEDURES];
if (t == null) {
t = createBlankTable(sysTableHsqlNames[SYSTEM_PROCEDURES]);
// ----------------------------------------------------------------
// required
// ----------------------------------------------------------------
// 0
addColumn(t, "PROCEDURE_CAT", SQL_IDENTIFIER);
// 1
addColumn(t, "PROCEDURE_SCHEM", SQL_IDENTIFIER);
// not null
addColumn(t, "PROCEDURE_NAME", SQL_IDENTIFIER);
// 3
addColumn(t, "NUM_INPUT_PARAMS", Type.SQL_INTEGER);
// 4
addColumn(t, "NUM_OUTPUT_PARAMS", Type.SQL_INTEGER);
// 5
addColumn(t, "NUM_RESULT_SETS", Type.SQL_INTEGER);
// 6
addColumn(t, "REMARKS", CHARACTER_DATA);
// basically: function (returns result), procedure (no return value)
// or unknown (say, a trigger callout routine)
// not null
addColumn(t, "PROCEDURE_TYPE", Type.SQL_SMALLINT);
// ----------------------------------------------------------------
// JDBC 4.0
// ----------------------------------------------------------------
// not null
addColumn(t, "SPECIFIC_NAME", SQL_IDENTIFIER);
// ----------------------------------------------------------------
// extended
// ----------------------------------------------------------------
// not null
addColumn(t, "ORIGIN", CHARACTER_DATA);
// ----------------------------------------------------------------
// order: PROCEDURE_SCHEM, PROCEDURE_NAME, SPECIFIC_NAME
// added for uniqe: PROCEDURE_CAT
// false PK, as PROCEDURE_SCHEM and/or PROCEDURE_CAT may be null
HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[SYSTEM_PROCEDURES].name, false, SchemaObject.INDEX);
t.createPrimaryKey(name, new int[] { 1, 2, 8, 0 }, false);
return t;
}
// calculated column values
// ------------------------
// required
// ------------------------
String catalog;
String schema;
String procName;
Integer numInputParams;
Integer numOutputParams;
Integer numResultSets;
String remarks;
Integer procRType;
// -------------------
// extended
// -------------------
String procOrigin;
String specificName;
// intermediate holders
String alias;
HsqlArrayList aliasList;
Iterator methods;
Object[] methodInfo;
Method method;
String methodOrigin;
Object[] row;
// Initialization
//and aliases
methods = ns.iterateAllAccessibleMethods(session, true);
catalog = database.getCatalogName().name;
schema = database.schemaManager.getDefaultSchemaHsqlName().name;
// Do it.
while (methods.hasNext()) {
methodInfo = (Object[]) methods.next();
method = (Method) methodInfo[0];
aliasList = (HsqlArrayList) methodInfo[1];
methodOrigin = (String) methodInfo[2];
pi.setMethod(method);
procName = pi.getFQN();
numInputParams = pi.getInputParmCount();
numOutputParams = pi.getOutputParmCount();
numResultSets = pi.getResultSetCount();
remarks = pi.getRemark();
procRType = pi.getResultType(methodOrigin);
specificName = pi.getSpecificName();
procOrigin = pi.getOrigin(methodOrigin);
addProcRows(t, aliasList, catalog, schema, procName, numInputParams, numOutputParams, numResultSets, remarks, procRType, specificName, procOrigin);
}
return t;
}
use of org.hsqldb_voltpatches.HsqlNameManager.HsqlName 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;
}
Aggregations