Search in sources :

Example 51 with Result

use of org.hsqldb_voltpatches.result.Result in project voltdb by VoltDB.

the class DatabaseInformationFull method DATA_TYPE_PRIVILEGES.

Table DATA_TYPE_PRIVILEGES() {
    Table t = sysTables[DATA_TYPE_PRIVILEGES];
    if (t == null) {
        t = createBlankTable(sysTableHsqlNames[DATA_TYPE_PRIVILEGES]);
        addColumn(t, "OBJECT_CATALOG", SQL_IDENTIFIER);
        addColumn(t, "OBJECT_SCHEMA", SQL_IDENTIFIER);
        // not null
        addColumn(t, "OBJECT_NAME", SQL_IDENTIFIER);
        addColumn(t, "OBJECT_TYPE", SQL_IDENTIFIER);
        addColumn(t, "DTD_IDENTIFIER", SQL_IDENTIFIER);
        HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[DATA_TYPE_PRIVILEGES].name, false, SchemaObject.INDEX);
        t.createPrimaryKey(name, new int[] { 0, 1, 2, 3, 4 }, false);
        return t;
    }
    PersistentStore store = database.persistentStoreCollection.getStore(t);
    //
    Session sys = database.sessionManager.newSysSession(SqlInvariants.INFORMATION_SCHEMA_HSQLNAME, session.getUser());
    String sql = (String) statementMap.get("/*data_type_privileges*/");
    Result rs = sys.executeDirectStatement(sql);
    t.insertSys(store, rs);
    sys.close();
    return t;
}
Also used : Table(org.hsqldb_voltpatches.Table) TextTable(org.hsqldb_voltpatches.TextTable) PersistentStore(org.hsqldb_voltpatches.persist.PersistentStore) HsqlName(org.hsqldb_voltpatches.HsqlNameManager.HsqlName) Session(org.hsqldb_voltpatches.Session) Result(org.hsqldb_voltpatches.result.Result)

Example 52 with Result

use of org.hsqldb_voltpatches.result.Result in project voltdb by VoltDB.

the class DatabaseInformationFull method ROLE_TABLE_GRANTS.

Table ROLE_TABLE_GRANTS() {
    Table t = sysTables[ROLE_TABLE_GRANTS];
    if (t == null) {
        t = createBlankTable(sysTableHsqlNames[ROLE_TABLE_GRANTS]);
        // not null
        addColumn(t, "GRANTOR", SQL_IDENTIFIER);
        // not null
        addColumn(t, "GRANTEE", SQL_IDENTIFIER);
        addColumn(t, "TABLE_CATALOG", SQL_IDENTIFIER);
        addColumn(t, "TABLE_SCHEMA", SQL_IDENTIFIER);
        // not null
        addColumn(t, "TABLE_NAME", SQL_IDENTIFIER);
        // not null
        addColumn(t, "PRIVILEGE_TYPE", CHARACTER_DATA);
        // not null
        addColumn(t, "IS_GRANTABLE", YES_OR_NO);
        addColumn(t, "WITH_HIERARCHY", YES_OR_NO);
        // order:  TABLE_SCHEM, TABLE_NAME, and PRIVILEGE,
        // added for unique:  GRANTEE, GRANTOR,
        // false PK, as TABLE_SCHEM and/or TABLE_CAT may be null
        HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[ROLE_TABLE_GRANTS].name, false, SchemaObject.INDEX);
        t.createPrimaryKey(name, new int[] { 3, 4, 5, 0, 1 }, false);
        return t;
    }
    PersistentStore store = database.persistentStoreCollection.getStore(t);
    Session sys = database.sessionManager.newSysSession(SqlInvariants.INFORMATION_SCHEMA_HSQLNAME, session.getUser());
    Result rs = sys.executeDirectStatement("SELECT GRANTOR, GRANTEE, TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME, PRIVILEGE_TYPE, IS_GRANTABLE, 'NO' " + "FROM INFORMATION_SCHEMA.TABLE_PRIVILEGES " + "JOIN INFORMATION_SCHEMA.APPLICABLE_ROLES ON GRANTEE = ROLE_NAME;");
    t.insertSys(store, rs);
    sys.close();
    return t;
}
Also used : Table(org.hsqldb_voltpatches.Table) TextTable(org.hsqldb_voltpatches.TextTable) PersistentStore(org.hsqldb_voltpatches.persist.PersistentStore) HsqlName(org.hsqldb_voltpatches.HsqlNameManager.HsqlName) Session(org.hsqldb_voltpatches.Session) Result(org.hsqldb_voltpatches.result.Result)

Example 53 with Result

use of org.hsqldb_voltpatches.result.Result in project voltdb by VoltDB.

the class SubQuery method materialise.

/**
     * Fills the table with a result set
     */
public void materialise(Session session) {
    PersistentStore store;
    // table constructors
    if (isDataExpression) {
        store = session.sessionData.getSubqueryRowStore(table);
        dataExpression.insertValuesIntoSubqueryTable(session, store);
        return;
    }
    Result result = queryExpression.getResult(session, isExistsPredicate ? 1 : 0);
    RowSetNavigatorData navigator = ((RowSetNavigatorData) result.getNavigator());
    if (uniqueRows) {
        navigator.removeDuplicates();
    }
    store = session.sessionData.getSubqueryRowStore(table);
    table.insertResult(store, result);
    result.getNavigator().close();
}
Also used : RowSetNavigatorData(org.hsqldb_voltpatches.navigator.RowSetNavigatorData) PersistentStore(org.hsqldb_voltpatches.persist.PersistentStore) Result(org.hsqldb_voltpatches.result.Result)

Example 54 with Result

use of org.hsqldb_voltpatches.result.Result in project voltdb by VoltDB.

the class StatementSchemaDefinition method getResult.

Result getResult(Session session) {
    schemaName = statements[0].getSchemaName();
    if (this.isExplain) {
        return Result.newSingleColumnStringResult("OPERATION", describe(session));
    }
    StatementSchema cs;
    Result result = statements[0].execute(session);
    HsqlArrayList constraints = new HsqlArrayList();
    if (statements.length == 1 || result.isError()) {
        return result;
    }
    HsqlName oldSessionSchema = session.getCurrentSchemaHsqlName();
    for (int i = 1; i < statements.length; i++) {
        try {
            session.setSchema(schemaName.name);
        } catch (HsqlException e) {
        }
        statements[i].setSchemaHsqlName(schemaName);
        session.parser.reset(statements[i].getSQL());
        try {
            session.parser.read();
            switch(statements[i].getType()) {
                case StatementTypes.GRANT:
                case StatementTypes.GRANT_ROLE:
                    result = statements[i].execute(session);
                    break;
                case StatementTypes.CREATE_TABLE:
                    cs = session.parser.compileCreate();
                    cs.isSchemaDefinition = true;
                    cs.setSchemaHsqlName(schemaName);
                    if (session.parser.token.tokenType != Tokens.X_ENDPARSE) {
                        throw session.parser.unexpectedToken();
                    }
                    result = cs.execute(session);
                    constraints.addAll((HsqlArrayList) cs.arguments[1]);
                    ((HsqlArrayList) cs.arguments[1]).clear();
                    break;
                case StatementTypes.CREATE_ROLE:
                case StatementTypes.CREATE_SEQUENCE:
                case StatementTypes.CREATE_TYPE:
                case StatementTypes.CREATE_CHARACTER_SET:
                case StatementTypes.CREATE_COLLATION:
                    result = statements[i].execute(session);
                    break;
                case StatementTypes.CREATE_INDEX:
                case StatementTypes.CREATE_TRIGGER:
                case StatementTypes.CREATE_VIEW:
                case StatementTypes.CREATE_DOMAIN:
                case StatementTypes.CREATE_ROUTINE:
                    cs = session.parser.compileCreate();
                    cs.isSchemaDefinition = true;
                    cs.setSchemaHsqlName(schemaName);
                    if (session.parser.token.tokenType != Tokens.X_ENDPARSE) {
                        throw session.parser.unexpectedToken();
                    }
                    result = cs.execute(session);
                    break;
                case StatementTypes.CREATE_ASSERTION:
                case StatementTypes.CREATE_TRANSFORM:
                case StatementTypes.CREATE_TRANSLATION:
                case StatementTypes.CREATE_CAST:
                case StatementTypes.CREATE_ORDERING:
                    throw session.parser.unsupportedFeature();
                default:
                    throw Error.runtimeError(ErrorCode.U_S0500, "");
            }
            if (result.isError()) {
                break;
            }
        } catch (HsqlException e) {
            result = Result.newErrorResult(e, statements[i].getSQL());
        }
    }
    if (!result.isError()) {
        try {
            for (int i = 0; i < constraints.size(); i++) {
                Constraint c = (Constraint) constraints.get(i);
                Table table = session.database.schemaManager.getUserTable(session, c.core.refTableName);
                ParserDDL.addForeignKey(session, table, c, null);
            }
        } catch (HsqlException e) {
            result = Result.newErrorResult(e, sql);
        }
    }
    if (result.isError()) {
        try {
            session.database.schemaManager.dropSchema(schemaName.name, true);
            session.database.logger.writeToLog(session, getDropSchemaStatement(schemaName));
        } catch (HsqlException e) {
        }
    }
    try {
        // A VoltDB extension to disable 
        // Try not to explicitly throw an exception, just to catch and ignore it,
        // but accidents can happen, so keep the try/catch anyway.
        session.setSchemaNoThrow(oldSessionSchema.name);
    /* disable 1 line ...
            session.setSchema(oldSessionSchema.name);
            ... disabled 1 line */
    // End of VoltDB extension
    } catch (Exception e) {
    }
    return result;
}
Also used : HsqlArrayList(org.hsqldb_voltpatches.lib.HsqlArrayList) HsqlName(org.hsqldb_voltpatches.HsqlNameManager.HsqlName) Result(org.hsqldb_voltpatches.result.Result)

Example 55 with Result

use of org.hsqldb_voltpatches.result.Result in project voltdb by VoltDB.

the class StatementProcedure method getExpressionResult.

Result getExpressionResult(Session session) {
    // representing CALL
    Expression e = expression;
    // expression return value
    Object o = e.getValue(session);
    Result r;
    if (o instanceof Result) {
        return (Result) o;
    }
    if (resultMetaData == null) {
        getResultMetaData();
    }
    /**
         * @todo 1.9.0 For table functions implment handling of Result objects
         * returned from Java functions. Review and document instantiation and usage
         * of relevant implementation of Result and JDBCResultSet for returning
         * from Java functions?
         * else if (o instanceof JDBCResultSet) {
         *   return ((JDBCResultSet) o).getResult();
         * }
         */
    r = Result.newSingleColumnResult(resultMetaData);
    Object[] row = new Object[1];
    row[0] = o;
    r.getNavigator().add(row);
    return r;
}
Also used : Result(org.hsqldb_voltpatches.result.Result)

Aggregations

Result (org.hsqldb_voltpatches.result.Result)83 Session (org.hsqldb_voltpatches.Session)18 PersistentStore (org.hsqldb_voltpatches.persist.PersistentStore)16 HsqlName (org.hsqldb_voltpatches.HsqlNameManager.HsqlName)15 Table (org.hsqldb_voltpatches.Table)14 ResultLob (org.hsqldb_voltpatches.result.ResultLob)13 TextTable (org.hsqldb_voltpatches.TextTable)12 ResultMetaData (org.hsqldb_voltpatches.result.ResultMetaData)11 RowSetNavigator (org.hsqldb_voltpatches.navigator.RowSetNavigator)10 HsqlException (org.hsqldb_voltpatches.HsqlException)5 RowSetNavigatorData (org.hsqldb_voltpatches.navigator.RowSetNavigatorData)4 EOFException (java.io.EOFException)3 RowSetNavigatorClient (org.hsqldb_voltpatches.navigator.RowSetNavigatorClient)3 IOException (java.io.IOException)2 RangeIteratorBase (org.hsqldb_voltpatches.RangeVariable.RangeIteratorBase)2 Statement (org.hsqldb_voltpatches.Statement)2 HashMappedList (org.hsqldb_voltpatches.lib.HashMappedList)2 HsqlArrayList (org.hsqldb_voltpatches.lib.HsqlArrayList)2 HsqlByteArrayInputStream (org.hsqldb_voltpatches.lib.HsqlByteArrayInputStream)2 Iterator (org.hsqldb_voltpatches.lib.Iterator)2