Search in sources :

Example 21 with HsqlException

use of org.hsqldb_voltpatches.HsqlException in project voltdb by VoltDB.

the class TextCache method readObject.

protected synchronized RowInputInterface readObject(int pos) {
    try {
        ByteArray buffer = new ByteArray(80);
        boolean complete = false;
        boolean wasCR = false;
        int c;
        boolean hasQuote = false;
        boolean wasNormal = false;
        pos = findNextUsedLinePos(pos);
        if (pos == -1) {
            return null;
        }
        dataFile.seek(pos);
        while (!complete) {
            wasNormal = false;
            c = dataFile.read();
            if (c == -1) {
                if (buffer.length() == 0) {
                    return null;
                }
                complete = true;
                if (wasCR) {
                    break;
                }
                if (!cacheReadonly) {
                    dataFile.write(ScriptWriterText.BYTES_LINE_SEP, 0, ScriptWriterText.BYTES_LINE_SEP.length);
                }
                break;
            }
            switch(c) {
                case DOUBLE_QUOTE_CHAR:
                    wasNormal = true;
                    complete = wasCR;
                    wasCR = false;
                    if (isQuoted) {
                        hasQuote = !hasQuote;
                    }
                    break;
                case CR_CHAR:
                    wasCR = !hasQuote;
                    break;
                case LF_CHAR:
                    complete = !hasQuote;
                    break;
                default:
                    wasNormal = true;
                    complete = wasCR;
                    wasCR = false;
            }
            buffer.append(c);
        }
        if (complete) {
            int length = (int) dataFile.getFilePointer() - pos;
            if (wasNormal) {
                length--;
            }
            ((RowInputText) rowIn).setSource(buffer.toString(), pos, length);
            return rowIn;
        }
        return null;
    } catch (IOException e) {
        throw new HsqlException(e.getMessage(), "", 0);
    }
}
Also used : RowInputText(org.hsqldb_voltpatches.rowio.RowInputText) IOException(java.io.IOException) HsqlException(org.hsqldb_voltpatches.HsqlException)

Example 22 with HsqlException

use of org.hsqldb_voltpatches.HsqlException in project voltdb by VoltDB.

the class TextCache method setHeader.

public void setHeader(String header) {
    if (ignoreFirst && fileFreePosition == 0) {
        try {
            writeHeader(header);
            this.header = header;
        } catch (HsqlException e) {
            throw new HsqlException(e, Error.getMessage(ErrorCode.GENERAL_IO_ERROR), ErrorCode.GENERAL_IO_ERROR);
        }
        return;
    }
    throw Error.error(ErrorCode.TEXT_TABLE_HEADER);
}
Also used : HsqlException(org.hsqldb_voltpatches.HsqlException)

Example 23 with HsqlException

use of org.hsqldb_voltpatches.HsqlException in project voltdb by VoltDB.

the class JDBCPreparedStatement method setParameter.

/**
     * The internal parameter value setter always converts the parameter to
     * the Java type required for data transmission.
     *
     * @param i parameter index
     * @param o object
     * @throws SQLException if either argument is not acceptable.
     */
void setParameter(int i, Object o) throws SQLException {
    checkSetParameterIndex(i, false);
    i--;
    if (o == null) {
        parameterValues[i] = null;
        return;
    }
    Type outType = parameterTypes[i];
    switch(outType.typeCode) {
        case Types.OTHER:
            try {
                if (o instanceof Serializable) {
                    o = new JavaObjectData((Serializable) o);
                    break;
                }
            } catch (HsqlException e) {
                Util.throwError(e);
            }
            Util.throwError(Error.error(ErrorCode.X_42565));
            break;
        case Types.SQL_BIT:
        case Types.SQL_BIT_VARYING:
            if (o instanceof Boolean) {
                if (outType.precision == 1) {
                    byte[] bytes = ((Boolean) o).booleanValue() ? new byte[] { -0x80 } : new byte[] { 0 };
                    o = new BinaryData(bytes, 1);
                    break;
                }
                Util.throwError(Error.error(ErrorCode.X_42565));
            }
            try {
                if (o instanceof byte[]) {
                    o = outType.convertToDefaultType(connection.sessionProxy, o);
                    break;
                }
                if (o instanceof String) {
                    o = outType.convertToDefaultType(connection.sessionProxy, o);
                    break;
                }
            } catch (HsqlException e) {
                Util.throwError(e);
            }
            Util.throwError(Error.error(ErrorCode.X_42565));
        // $FALL-THROUGH$
        case Types.SQL_BINARY:
        case Types.SQL_VARBINARY:
            if (o instanceof byte[]) {
                o = new BinaryData((byte[]) o, !connection.isNetConn);
                break;
            }
            try {
                if (o instanceof String) {
                    o = outType.convertToDefaultType(connection.sessionProxy, o);
                    break;
                }
            } catch (HsqlException e) {
                Util.throwError(e);
            }
            Util.throwError(Error.error(ErrorCode.X_42565));
            break;
        case Types.SQL_BLOB:
            setBlobParameter(i + 1, o);
            return;
        case Types.SQL_CLOB:
            setClobParameter(i + 1, o);
            return;
        case Types.SQL_DATE:
        case Types.SQL_TIME_WITH_TIME_ZONE:
        case Types.SQL_TIMESTAMP_WITH_TIME_ZONE:
        case Types.SQL_TIME:
        case Types.SQL_TIMESTAMP:
            {
                try {
                    if (o instanceof String) {
                        o = outType.convertToType(connection.sessionProxy, o, Type.SQL_VARCHAR);
                        break;
                    }
                    o = outType.convertJavaToSQL(connection.sessionProxy, o);
                    break;
                } catch (HsqlException e) {
                    Util.throwError(e);
                }
            }
        // $FALL-THROUGH$
        case Types.TINYINT:
        case Types.SQL_SMALLINT:
        case Types.SQL_INTEGER:
        case Types.SQL_BIGINT:
        case Types.SQL_REAL:
        case Types.SQL_FLOAT:
        case Types.SQL_DOUBLE:
        case Types.SQL_NUMERIC:
        case Types.SQL_DECIMAL:
            try {
                if (o instanceof String) {
                    o = outType.convertToType(connection.sessionProxy, o, Type.SQL_VARCHAR);
                    break;
                }
                o = outType.convertToDefaultType(connection.sessionProxy, o);
                break;
            } catch (HsqlException e) {
                Util.throwError(e);
            }
        // $FALL-THROUGH$
        default:
            try {
                o = outType.convertToDefaultType(connection.sessionProxy, o);
                break;
            } catch (HsqlException e) {
                Util.throwError(e);
            }
    }
    parameterValues[i] = o;
}
Also used : Type(org.hsqldb_voltpatches.types.Type) Serializable(java.io.Serializable) JavaObjectData(org.hsqldb_voltpatches.types.JavaObjectData) BinaryData(org.hsqldb_voltpatches.types.BinaryData) HsqlException(org.hsqldb_voltpatches.HsqlException)

Example 24 with HsqlException

use of org.hsqldb_voltpatches.HsqlException in project voltdb by VoltDB.

the class JDBCConnection method prepareCall.

/**
     * <!-- start generic documentation -->
     *
     * Creates a <code>CallableStatement</code> object for calling
     * database stored procedures.
     * The <code>CallableStatement</code> object provides
     * methods for setting up its IN and OUT parameters, and
     * methods for executing the call to a stored procedure.
     *
     * <P><B>Note:</B> This method is optimized for handling stored
     * procedure call statements. Some drivers may send the call
     * statement to the database when the method <code>prepareCall</code>
     * is done; others
     * may wait until the <code>CallableStatement</code> object
     * is executed. This has no
     * direct effect on users; however, it does affect which method
     * throws certain SQLExceptions.
     * <P>
     * Result sets created using the returned <code>CallableStatement</code>
     * object will by default be type <code>TYPE_FORWARD_ONLY</code>
     * and have a concurrency level of <code>CONCUR_READ_ONLY</code>.
     * The holdability of the created result sets can be determined by
     * calling {@link #getHoldability}.
     *
     * <!-- end generic documentation -->
     * <!-- start release-specific documentation -->
     * <div class="ReleaseSpecificDocumentation">
     * <h3>HSQLDB-Specific Information:</h3> <p>
     *
     * Starting with 1.7.2, the support for and behaviour of
     * CallableStatement has changed.  Please read the introductory section
     * of the documentation for org.hsqldb_voltpatches.jdbc.JDBCCallableStatement.
     *
     * </div> <!-- end release-specific documentation -->
     *
     * @param sql an SQL statement that may contain one or more '?'
     * parameter placeholders. (JDBC4 clarification:) Typically this statement is specified using JDBC
     * call escape syntax.
     * @return a new default <code>CallableStatement</code> object containing the
     * pre-compiled SQL statement
     * @exception SQLException if a database access error occurs
     * (JDBC4 clarification:)
     * or this method is called on a closed connection
     * @see #prepareCall(String,int,int)
     */
public synchronized CallableStatement prepareCall(String sql) throws SQLException {
    CallableStatement stmt;
    checkClosed();
    try {
        stmt = new JDBCCallableStatement(this, sql, JDBCResultSet.TYPE_FORWARD_ONLY, JDBCResultSet.CONCUR_READ_ONLY, rsHoldability);
        return stmt;
    } catch (HsqlException e) {
        throw Util.sqlException(e);
    }
}
Also used : CallableStatement(java.sql.CallableStatement) HsqlException(org.hsqldb_voltpatches.HsqlException)

Example 25 with HsqlException

use of org.hsqldb_voltpatches.HsqlException in project voltdb by VoltDB.

the class DatabaseInformationFull method VIEW_TABLE_USAGE.

/**
     * The VIEW_TABLE_USAGE table has one row for each table identified
     * by a &lt;table name&gt; simply contained in a &lt;table reference&gt;
     * that is contained in the &lt;query expression&gt; of a view. <p>
     *
     * <b>Definition</b><p>
     *
     * <pre class="SqlCodeExample">
     * CREATE TABLE SYSTEM_VIEW_TABLE_USAGE (
     *      VIEW_CATALOG    VARCHAR NULL,
     *      VIEW_SCHEMA     VARCHAR NULL,
     *      VIEW_NAME       VARCHAR NULL,
     *      TABLE_CATALOG   VARCHAR NULL,
     *      TABLE_SCHEMA    VARCHAR NULL,
     *      TABLE_NAME      VARCHAR NULL,
     *      UNIQUE( VIEW_CATALOG, VIEW_SCHEMA, VIEW_NAME,
     *              TABLE_CATALOG, TABLE_SCHEMA, TABLE_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, and TABLE_NAME are the
     *      catalog name, unqualified schema name, and qualified identifier,
     *      respectively, of a table identified by a &lt;table name&gt;
     *      simply contained in a &lt;table reference&gt; that is contained in
     *      the &lt;query expression&gt; of the view being described.
     * </ol>
     *
     * @return Table
     */
Table VIEW_TABLE_USAGE() {
    Table t = sysTables[VIEW_TABLE_USAGE];
    if (t == null) {
        t = createBlankTable(sysTableHsqlNames[VIEW_TABLE_USAGE]);
        addColumn(t, "VIEW_CATALOG", SQL_IDENTIFIER);
        addColumn(t, "VIEW_SCHEMA", SQL_IDENTIFIER);
        // not null
        addColumn(t, "VIEW_NAME", SQL_IDENTIFIER);
        addColumn(t, "TABLE_CATALOG", SQL_IDENTIFIER);
        addColumn(t, "TABLE_SCHEMA", SQL_IDENTIFIER);
        // not null
        addColumn(t, "TABLE_NAME", SQL_IDENTIFIER);
        // false PK, as VIEW_CATALOG, VIEW_SCHEMA, TABLE_CATALOG, and/or
        // TABLE_SCHEMA may be NULL
        HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[VIEW_TABLE_USAGE].name, false, SchemaObject.INDEX);
        t.createPrimaryKey(name, new int[] { 0, 1, 2, 3, 4, 5 }, false);
        return t;
    }
    // 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;
    //
    PersistentStore store = database.persistentStoreCollection.getStore(t);
    Iterator tables;
    Table table;
    Object[] row;
    // 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;
        }
        OrderedHashSet references = table.getReferences();
        for (int i = 0; i < references.size(); i++) {
            HsqlName refName = (HsqlName) references.get(i);
            if (!session.getGrantee().isFullyAccessibleByRole(refName)) {
                continue;
            }
            if (refName.type != SchemaObject.TABLE) {
                continue;
            }
            row = t.getEmptyRowData();
            row[view_catalog] = database.getCatalogName().name;
            row[view_schema] = table.getSchemaName().name;
            row[view_name] = table.getName().name;
            row[table_catalog] = database.getCatalogName().name;
            row[table_schema] = refName.schema.name;
            row[table_name] = refName.name;
            try {
                t.insertSys(store, row);
            } catch (HsqlException e) {
            }
        }
    }
    return t;
}
Also used : Table(org.hsqldb_voltpatches.Table) TextTable(org.hsqldb_voltpatches.TextTable) Iterator(org.hsqldb_voltpatches.lib.Iterator) WrapperIterator(org.hsqldb_voltpatches.lib.WrapperIterator) PersistentStore(org.hsqldb_voltpatches.persist.PersistentStore) OrderedHashSet(org.hsqldb_voltpatches.lib.OrderedHashSet) HsqlName(org.hsqldb_voltpatches.HsqlNameManager.HsqlName) SchemaObject(org.hsqldb_voltpatches.SchemaObject) Constraint(org.hsqldb_voltpatches.Constraint) HsqlException(org.hsqldb_voltpatches.HsqlException)

Aggregations

HsqlException (org.hsqldb_voltpatches.HsqlException)46 SchemaObject (org.hsqldb_voltpatches.SchemaObject)19 HsqlName (org.hsqldb_voltpatches.HsqlNameManager.HsqlName)17 Constraint (org.hsqldb_voltpatches.Constraint)16 Table (org.hsqldb_voltpatches.Table)16 Iterator (org.hsqldb_voltpatches.lib.Iterator)16 OrderedHashSet (org.hsqldb_voltpatches.lib.OrderedHashSet)16 WrapperIterator (org.hsqldb_voltpatches.lib.WrapperIterator)16 PersistentStore (org.hsqldb_voltpatches.persist.PersistentStore)16 TextTable (org.hsqldb_voltpatches.TextTable)14 IOException (java.io.IOException)10 Routine (org.hsqldb_voltpatches.Routine)5 RoutineSchema (org.hsqldb_voltpatches.RoutineSchema)5 TriggerDef (org.hsqldb_voltpatches.TriggerDef)4 Grantee (org.hsqldb_voltpatches.rights.Grantee)4 Right (org.hsqldb_voltpatches.rights.Right)4 Type (org.hsqldb_voltpatches.types.Type)4 Row (org.hsqldb_voltpatches.Row)3 Result (org.hsqldb_voltpatches.result.Result)3 BatchUpdateException (java.sql.BatchUpdateException)2