Search in sources :

Example 11 with Session

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

the class LobManager method setBytesForNewBlob.

public Result setBytesForNewBlob(long lobID, InputStream inputStream, long length) {
    Session session = sysLobSession;
    if (length == 0) {
        return ResultLob.newLobSetResponse(lobID, 0);
    }
    Result result = setBytesIS(session, lobID, inputStream, length);
    return result;
}
Also used : Session(org.hsqldb_voltpatches.Session) Result(org.hsqldb_voltpatches.result.Result)

Example 12 with Session

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

the class LobManager method deleteLob.

public Result deleteLob(long lobID) {
    Session session = this.sysLobSession;
    ResultMetaData meta = deleteLob.getParametersMetaData();
    Object[] params = new Object[meta.getColumnCount()];
    params[0] = Long.valueOf(lobID);
    params[1] = Long.valueOf(0);
    Result result = session.executeCompiledStatement(deleteLob, params);
    return result;
}
Also used : ResultMetaData(org.hsqldb_voltpatches.result.ResultMetaData) Session(org.hsqldb_voltpatches.Session) Result(org.hsqldb_voltpatches.result.Result)

Example 13 with Session

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

the class Log method processScript.

/**
     * Performs all the commands in the .script file.
     */
private void processScript() {
    ScriptReaderBase scr = null;
    try {
        if (database.isFilesInJar() || fa.isStreamElement(scriptFileName)) {
            scr = ScriptReaderBase.newScriptReader(database, scriptFileName, scriptFormat);
            Session session = database.sessionManager.getSysSessionForScript(database);
            scr.readAll(session);
            scr.close();
        }
    } catch (Throwable e) {
        if (scr != null) {
            scr.close();
            if (cache != null) {
                cache.close(false);
            }
            closeAllTextCaches(false);
        }
        database.logger.appLog.logContext(e, null);
        if (e instanceof HsqlException) {
            throw (HsqlException) e;
        } else if (e instanceof IOException) {
            throw Error.error(ErrorCode.FILE_IO_ERROR, e.toString());
        } else if (e instanceof OutOfMemoryError) {
            throw Error.error(ErrorCode.OUT_OF_MEMORY);
        } else {
            throw Error.error(ErrorCode.GENERAL_ERROR, e.toString());
        }
    }
}
Also used : ScriptReaderBase(org.hsqldb_voltpatches.scriptio.ScriptReaderBase) IOException(java.io.IOException) HsqlException(org.hsqldb_voltpatches.HsqlException) Session(org.hsqldb_voltpatches.Session)

Example 14 with Session

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

the class NumberType method convertToInt.

// BEGIN Cherry-picked code change from hsqldb-2.2.8
/**
     * Type narrowing from DOUBLE/DECIMAL/NUMERIC to BIGINT / INT / SMALLINT / TINYINT
     * following SQL rules. When conversion is from a non-integral type,
     * digits to the right of the decimal point are lost.
     */
/**
     * Converter from a numeric object to Integer. Input is checked to be
     * within range represented by the given number type.
     */
static Integer convertToInt(SessionInterface session, Object a, int type) {
    int value;
    if (a instanceof Integer) {
        if (type == Types.SQL_INTEGER) {
            return (Integer) a;
        }
        value = ((Integer) a).intValue();
    } else if (a instanceof Long) {
        long temp = ((Long) a).longValue();
        if (Integer.MAX_VALUE < temp || temp < Integer.MIN_VALUE) {
            throw Error.error(ErrorCode.X_22003);
        }
        value = (int) temp;
    } else if (a instanceof BigDecimal) {
        BigDecimal bd = ((BigDecimal) a);
        if (bd.compareTo(MAX_INT) > 0 || bd.compareTo(MIN_INT) < 0) {
            throw Error.error(ErrorCode.X_22003);
        }
        value = bd.intValue();
    } else if (a instanceof Double || a instanceof Float) {
        double d = ((Number) a).doubleValue();
        if (session instanceof Session) {
            if (!((Session) session).database.sqlConvertTruncate) {
                d = java.lang.Math.rint(d);
            }
        }
        if (Double.isInfinite(d) || Double.isNaN(d) || d >= (double) Integer.MAX_VALUE + 1 || d <= (double) Integer.MIN_VALUE - 1) {
            throw Error.error(ErrorCode.X_22003);
        }
        value = (int) d;
    } else {
        throw Error.error(ErrorCode.X_42561);
    }
    if (type == Types.TINYINT) {
        if (Byte.MAX_VALUE < value || value < Byte.MIN_VALUE) {
            throw Error.error(ErrorCode.X_22003);
        }
    } else if (type == Types.SQL_SMALLINT) {
        if (Short.MAX_VALUE < value || value < Short.MIN_VALUE) {
            throw Error.error(ErrorCode.X_22003);
        }
    }
    return Integer.valueOf(value);
}
Also used : BigInteger(java.math.BigInteger) BigDecimal(java.math.BigDecimal) Session(org.hsqldb_voltpatches.Session)

Example 15 with Session

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

the class DatabaseInformationMain method SYSTEM_TYPEINFO.

/**
     * Retrieves a <code>Table</code> object describing the
     * result expected by the JDBC DatabaseMetaData interface implementation
     * for system-defined SQL types supported as table columns.
     *
     * <pre class="SqlCodeExample">
     * TYPE_NAME          VARCHAR   the canonical name for DDL statements.
     * DATA_TYPE          SMALLINT  data type code from DITypes.
     * PRECISION          INTEGER   max column size.
     *                              number => max precision.
     *                              character => max characters.
     *                              datetime => max chars incl. frac. component.
     * LITERAL_PREFIX     VARCHAR   char(s) prefixing literal of this type.
     * LITERAL_SUFFIX     VARCHAR   char(s) terminating literal of this type.
     * CREATE_PARAMS      VARCHAR   Localized syntax-order list of domain
     *                              create parameter keywords.
     *                              - for human consumption only
     * NULLABLE           SMALLINT  {No Nulls | Nullable | Unknown}
     * CASE_SENSITIVE     BOOLEAN   case-sensitive in collations/comparisons?
     * SEARCHABLE         SMALLINT  {None | Char (Only WHERE .. LIKE) |
     *                               Basic (Except WHERE .. LIKE) |
     *                               Searchable (All forms)}
     * UNSIGNED_ATTRIBUTE BOOLEAN   {TRUE  (unsigned) | FALSE (signed) |
     *                               NULL (non-numeric or not applicable)}
     * FIXED_PREC_SCALE   BOOLEAN   {TRUE (fixed) | FALSE (variable) |
     *                               NULL (non-numeric or not applicable)}
     * AUTO_INCREMENT     BOOLEAN   automatic unique value generated for
     *                              inserts and updates when no value or
     *                              NULL specified?
     * LOCAL_TYPE_NAME    VARCHAR   localized name of data type;
     *                              - NULL if not supported.
     *                              - for human consuption only
     * MINIMUM_SCALE      SMALLINT  minimum scale supported.
     * MAXIMUM_SCALE      SMALLINT  maximum scale supported.
     * SQL_DATA_TYPE      INTEGER   value expected in SQL CLI SQL_DESC_TYPE
     *                              field of the SQLDA.
     * SQL_DATETIME_SUB   INTEGER   SQL CLI datetime/interval subcode.
     * NUM_PREC_RADIX     INTEGER   numeric base w.r.t # of digits reported in
     *                              PRECISION column (typically 10).
     * TYPE_SUB           INTEGER   From DITypes:
     *                              {TYPE_SUB_DEFAULT | TYPE_SUB_IDENTITY |
     *                               TYPE_SUB_IGNORECASE}
     * </pre> <p>
     *
     * @return a <code>Table</code> object describing the
     *      system-defined SQL types supported as table columns
     */
final Table SYSTEM_TYPEINFO() {
    Table t = sysTables[SYSTEM_TYPEINFO];
    if (t == null) {
        t = createBlankTable(sysTableHsqlNames[SYSTEM_TYPEINFO]);
        //-------------------------------------------
        // required by JDBC:
        // ------------------------------------------
        addColumn(t, "TYPE_NAME", SQL_IDENTIFIER);
        addColumn(t, "DATA_TYPE", Type.SQL_SMALLINT);
        addColumn(t, "PRECISION", Type.SQL_INTEGER);
        addColumn(t, "LITERAL_PREFIX", CHARACTER_DATA);
        addColumn(t, "LITERAL_SUFFIX", CHARACTER_DATA);
        addColumn(t, "CREATE_PARAMS", CHARACTER_DATA);
        addColumn(t, "NULLABLE", Type.SQL_SMALLINT);
        addColumn(t, "CASE_SENSITIVE", Type.SQL_BOOLEAN);
        addColumn(t, "SEARCHABLE", Type.SQL_INTEGER);
        addColumn(t, "UNSIGNED_ATTRIBUTE", Type.SQL_BOOLEAN);
        addColumn(t, "FIXED_PREC_SCALE", Type.SQL_BOOLEAN);
        addColumn(t, "AUTO_INCREMENT", Type.SQL_BOOLEAN);
        addColumn(t, "LOCAL_TYPE_NAME", SQL_IDENTIFIER);
        addColumn(t, "MINIMUM_SCALE", Type.SQL_SMALLINT);
        addColumn(t, "MAXIMUM_SCALE", Type.SQL_SMALLINT);
        addColumn(t, "SQL_DATA_TYPE", Type.SQL_INTEGER);
        addColumn(t, "SQL_DATETIME_SUB", Type.SQL_INTEGER);
        addColumn(t, "NUM_PREC_RADIX", Type.SQL_INTEGER);
        //-------------------------------------------
        // for JDBC sort contract:
        //-------------------------------------------
        addColumn(t, "TYPE_SUB", Type.SQL_INTEGER);
        // order: DATA_TYPE, TYPE_SUB
        // true PK
        HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[SYSTEM_TYPEINFO].name, false, SchemaObject.INDEX);
        t.createPrimaryKey(name, new int[] { 1, 18 }, true);
        return t;
    }
    PersistentStore store = database.persistentStoreCollection.getStore(t);
    Session sys = database.sessionManager.newSysSession(SqlInvariants.INFORMATION_SCHEMA_HSQLNAME, session.getUser());
    Result rs = sys.executeDirectStatement("select TYPE_NAME, DATA_TYPE, PRECISION, LITERAL_PREFIX," + "LITERAL_SUFFIX, CREATE_PARAMS, NULLABLE, CASE_SENSITIVE," + "SEARCHABLE," + "UNSIGNED_ATTRIBUTE, FIXED_PREC_SCALE, AUTO_INCREMENT, LOCAL_TYPE_NAME, MINIMUM_SCALE, " + "MAXIMUM_SCALE, SQL_DATA_TYPE, SQL_DATETIME_SUB, NUM_PREC_RADIX, TYPE_SUB " + "from INFORMATION_SCHEMA.SYSTEM_ALLTYPEINFO  where AS_TAB_COL = true;");
    t.insertSys(store, rs);
    sys.close();
    return t;
}
Also used : Table(org.hsqldb_voltpatches.Table) PersistentStore(org.hsqldb_voltpatches.persist.PersistentStore) HsqlName(org.hsqldb_voltpatches.HsqlNameManager.HsqlName) Session(org.hsqldb_voltpatches.Session) Result(org.hsqldb_voltpatches.result.Result)

Aggregations

Session (org.hsqldb_voltpatches.Session)24 Result (org.hsqldb_voltpatches.result.Result)18 Table (org.hsqldb_voltpatches.Table)17 HsqlName (org.hsqldb_voltpatches.HsqlNameManager.HsqlName)16 PersistentStore (org.hsqldb_voltpatches.persist.PersistentStore)16 TextTable (org.hsqldb_voltpatches.TextTable)15 EOFException (java.io.EOFException)2 IOException (java.io.IOException)2 Constraint (org.hsqldb_voltpatches.Constraint)2 HsqlException (org.hsqldb_voltpatches.HsqlException)2 ScriptReaderBase (org.hsqldb_voltpatches.scriptio.ScriptReaderBase)2 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 LineNumberReader (java.io.LineNumberReader)1 BigDecimal (java.math.BigDecimal)1 BigInteger (java.math.BigInteger)1 SchemaObject (org.hsqldb_voltpatches.SchemaObject)1 Statement (org.hsqldb_voltpatches.Statement)1 DoubleIntIndex (org.hsqldb_voltpatches.lib.DoubleIntIndex)1 HashMappedList (org.hsqldb_voltpatches.lib.HashMappedList)1