Search in sources :

Example 36 with Type

use of org.hsqldb_voltpatches.types.Type in project voltdb by VoltDB.

the class ParserRoutine method compileCreateProcedureOrFunction.

// SQL-invoked routine
StatementSchema compileCreateProcedureOrFunction() {
    int routineType = token.tokenType == Tokens.PROCEDURE ? SchemaObject.PROCEDURE : SchemaObject.FUNCTION;
    HsqlName name;
    read();
    name = readNewSchemaObjectNameNoCheck(routineType);
    Routine routine = new Routine(routineType);
    routine.setName(name);
    readThis(Tokens.OPENBRACKET);
    if (token.tokenType == Tokens.CLOSEBRACKET) {
        read();
    } else {
        while (true) {
            ColumnSchema newcolumn = readRoutineParameter(routine);
            routine.addParameter(newcolumn);
            if (token.tokenType == Tokens.COMMA) {
                read();
            } else {
                readThis(Tokens.CLOSEBRACKET);
                break;
            }
        }
    }
    if (routineType != SchemaObject.PROCEDURE) {
        readThis(Tokens.RETURNS);
        if (token.tokenType == Tokens.TABLE) {
            read();
            TableDerived table = new TableDerived(database, name, TableBase.FUNCTION_TABLE);
            readThis(Tokens.OPENBRACKET);
            if (token.tokenType == Tokens.CLOSEBRACKET) {
                read();
            } else {
                while (true) {
                    ColumnSchema newcolumn = readRoutineParameter(routine);
                    table.addColumn(newcolumn);
                    if (token.tokenType == Tokens.COMMA) {
                        read();
                    } else {
                        readThis(Tokens.CLOSEBRACKET);
                        break;
                    }
                }
            }
            routine.setReturnTable(table);
        } else {
            Type type = readTypeDefinition(true);
            routine.setReturnType(type);
        }
    }
    readRoutineCharacteristics(routine);
    if (token.tokenType == Tokens.EXTERNAL) {
        if (routine.getLanguage() != Routine.LANGUAGE_JAVA) {
            throw unexpectedToken();
        }
        read();
        readThis(Tokens.NAME);
        checkIsValue(Types.SQL_CHAR);
        routine.setMethodURL((String) token.tokenValue);
        read();
        if (token.tokenType == Tokens.PARAMETER) {
            read();
            readThis(Tokens.STYLE);
            readThis(Tokens.JAVA);
        }
    } else {
        startRecording();
        Statement statement = readSQLProcedureStatementOrNull(routine, null);
        Token[] tokenList = getRecordedStatement();
        String sql = Token.getSQL(tokenList);
        statement.setSQL(sql);
        routine.setProcedure(statement);
    }
    Object[] args = new Object[] { routine };
    String sql = getLastPart();
    StatementSchema cs = new StatementSchema(sql, StatementTypes.CREATE_ROUTINE, args, null, null);
    return cs;
}
Also used : Type(org.hsqldb_voltpatches.types.Type) HsqlName(org.hsqldb_voltpatches.HsqlNameManager.HsqlName)

Example 37 with Type

use of org.hsqldb_voltpatches.types.Type in project voltdb by VoltDB.

the class ParserRoutine method readLocalVariableDeclarationOrNull.

ColumnSchema readLocalVariableDeclarationOrNull() {
    int position = super.getPosition();
    readThis(Tokens.DECLARE);
    if (isReservedKey()) {
        rewind(position);
        return null;
    }
    HsqlName name = super.readNewSchemaObjectNameNoCheck(SchemaObject.VARIABLE);
    Type type = readTypeDefinition(true);
    Expression def = null;
    if (token.tokenType == Tokens.DEFAULT) {
        read();
        def = readDefaultClause(type);
    }
    ColumnSchema variable = new ColumnSchema(name, type, true, false, def);
    variable.setParameterMode(SchemaObject.ParameterModes.PARAM_INOUT);
    readThis(Tokens.SEMICOLON);
    return variable;
}
Also used : Type(org.hsqldb_voltpatches.types.Type) HsqlName(org.hsqldb_voltpatches.HsqlNameManager.HsqlName)

Example 38 with Type

use of org.hsqldb_voltpatches.types.Type in project voltdb by VoltDB.

the class JDBCPreparedStatement method setTimestamp.

/**
     * <!-- start generic documentation -->
     * Sets the designated parameter to the given <code>java.sql.Timestamp</code> value,
     * using the given <code>Calendar</code> object.  The driver uses
     * the <code>Calendar</code> object to construct an SQL <code>TIMESTAMP</code> value,
     * which the driver then sends to the database.  With a
     *  <code>Calendar</code> object, the driver can calculate the timestamp
     * taking into account a custom timezone.  If no
     * <code>Calendar</code> object is specified, the driver uses the default
     * timezone, which is that of the virtual machine running the application.
     * <!-- end generic documentation -->
     * <div class="ReleaseSpecificDocumentation">
     * <h3>HSQLDB-Specific Information:</h3> <p>
     *
     * When a setXXX method is used to set a parameter of type
     * TIMESTAMP WITH TIME ZONE or TIME WITH TIME ZONE the time zone (including
     * Daylight Saving Time) of the Calendar is used as time zone.<p>
     *
     * When this method is used to set a parameter of type TIME or
     * TIME WITH TIME ZONE, then the nanosecond value of the Timestamp object
     * is used if the TIME parameter accepts fractional seconds.
     *
     * </div>
     * <!-- end release-specific documentation -->
     *
     * @param parameterIndex the first parameter is 1, the second is 2, ...
     * @param x the parameter value
     * @param cal the <code>Calendar</code> object the driver will use
     *            to construct the timestamp
     * @exception SQLException if a database access error occurs or
     * this method is called on a closed <code>PreparedStatement</code>
     * @since JDK 1.2 (JDK 1.1.x developers: read the overview for
     *   JDBCParameterMetaData)
     */
public synchronized void setTimestamp(int parameterIndex, Timestamp x, Calendar cal) throws SQLException {
    checkSetParameterIndex(parameterIndex, false);
    int i = parameterIndex - 1;
    if (x == null) {
        parameterValues[i] = null;
        return;
    }
    Type outType = parameterTypes[i];
    long millis = x.getTime();
    int zoneOffset = 0;
    if (cal != null) {
        zoneOffset = HsqlDateTime.getZoneMillis(cal, millis);
    }
    switch(outType.typeCode) {
        case Types.SQL_TIMESTAMP:
            millis += zoneOffset;
            zoneOffset = 0;
        // $FALL-THROUGH$
        case Types.SQL_TIMESTAMP_WITH_TIME_ZONE:
            parameterValues[i] = new TimestampData(millis / 1000, x.getNanos(), zoneOffset / 1000);
            break;
        case Types.SQL_TIME:
            millis += zoneOffset;
            zoneOffset = 0;
        // $FALL-THROUGH$
        case Types.SQL_TIME_WITH_TIME_ZONE:
            parameterValues[i] = new TimeData((int) (millis / 1000), x.getNanos(), zoneOffset / 1000);
            break;
        default:
            throw Util.sqlException(ErrorCode.X_42561);
    }
}
Also used : Type(org.hsqldb_voltpatches.types.Type) TimestampData(org.hsqldb_voltpatches.types.TimestampData) TimeData(org.hsqldb_voltpatches.types.TimeData)

Example 39 with Type

use of org.hsqldb_voltpatches.types.Type in project voltdb by VoltDB.

the class JDBCPreparedStatement method setClob.

/**
     * <!-- start generic documentation -->
     * Sets the designated parameter to the given <code>java.sql.Clob</code> object.
     * The driver converts this to an SQL <code>CLOB</code> value when it
     * sends it to the database.
     * <!-- end generic documentation -->
     *
     * <!-- start release-specific documentation -->
     * <div class="ReleaseSpecificDocumentation">
     * <h3>HSQLDB-Specific Information:</h3> <p>
     *
     * For parameters of type Clob, setClob works normally.<p>
     *
     * In addition since 1.7.2, setClob is supported for CHARACTER and VARCHAR
     * parameters. In this context, the Clob object is
     * hard-limited to those of length less than or equal to Integer.MAX_VALUE.
     * In practice, soft limits such as available heap and maximum disk usage
     * per file (such as the transaction log) dictate a much smaller maximum
     * length. <p>
     *
     * For CHARACTER and VARCHAR parameter types setClob(i,x) is roughly
     * equivalent (null and length handling not shown) to:<p>
     *
     * <pre class="JavaCodeExample">
     * <b>setCharacterStream</b>(i, x.<b>getCharacterStream</b>(), (<span class="JavaKeyWord">int</span>) x.<b>length</b>());
     * </pre></div>
     * <!-- end release-specific documentation -->
     * @param parameterIndex the first parameter is 1, the second is 2, ...
     * @param x a <code>Clob</code> object that maps an SQL <code>CLOB</code> value
     * @exception SQLException if a database access error occurs or
     * this method is called on a closed <code>PreparedStatement</code>
     * @throws SQLFeatureNotSupportedException  if the JDBC driver does not support this method
     * @since JDK 1.2 (JDK 1.1.x developers: read the overview for
     *  JDBCParameterMetaData)
     */
public synchronized void setClob(int parameterIndex, Clob x) throws SQLException {
    checkSetParameterIndex(parameterIndex, false);
    Type outType = parameterTypes[parameterIndex - 1];
    switch(outType.typeCode) {
        case Types.SQL_CHAR:
        case Types.SQL_VARCHAR:
            setClobForStringParameter(parameterIndex, x);
            return;
        case Types.SQL_CLOB:
            setClobParameter(parameterIndex, x);
            return;
        default:
            throw Util.invalidArgument();
    }
}
Also used : Type(org.hsqldb_voltpatches.types.Type)

Example 40 with Type

use of org.hsqldb_voltpatches.types.Type in project voltdb by VoltDB.

the class JDBCResultSet method getObject.

/**
     * <!-- start generic documentation -->
     * <p>Gets the value of the designated column in the current row
     * of this <code>ResultSet</code> object as
     * an <code>Object</code> in the Java programming language.
     *
     * <p>This method will return the value of the given column as a
     * Java object.  The type of the Java object will be the default
     * Java object type corresponding to the column's SQL type,
     * following the mapping for built-in types specified in the JDBC
     * specification. If the value is an SQL <code>NULL</code>,
     * the driver returns a Java <code>null</code>.
     *
     * <p>This method may also be used to read database-specific
     * abstract data types.
     *
     * In the JDBC 2.0 API, the behavior of method
     * <code>getObject</code> is extended to materialize
     * data of SQL user-defined types.
     * <p>
     * If <code>Connection.getTypeMap</code> does not throw a
     * <code>SQLFeatureNotSupportedException</code>,
     * then when a column contains a structured or distinct value,
     * the behavior of this method is as
     * if it were a call to: <code>getObject(columnIndex,
     * this.getStatement().getConnection().getTypeMap())</code>.
     *
     * If <code>Connection.getTypeMap</code> does throw a
     * <code>SQLFeatureNotSupportedException</code>,
     * then structured values are not supported, and distinct values
     * are mapped to the default Java class as determined by the
     * underlying SQL type of the DISTINCT type.
     * <!-- end generic documentation -->
     *
     * @param columnIndex the first column is 1, the second is 2, ...
     * @return a <code>java.lang.Object</code> holding the column value
     * @exception SQLException if a database access error occurs or this method is
     *            called on a closed result set
     */
public Object getObject(int columnIndex) throws SQLException {
    checkColumn(columnIndex);
    Type sourceType = resultMetaData.columnTypes[columnIndex - 1];
    switch(sourceType.typeCode) {
        case Types.SQL_DATE:
            return getDate(columnIndex);
        case Types.SQL_TIME:
        case Types.SQL_TIME_WITH_TIME_ZONE:
            return getTime(columnIndex);
        case Types.SQL_TIMESTAMP:
        case Types.SQL_TIMESTAMP_WITH_TIME_ZONE:
            return getTimestamp(columnIndex);
        case Types.SQL_BINARY:
        case Types.SQL_VARBINARY:
            return getBytes(columnIndex);
        case Types.OTHER:
        case Types.JAVA_OBJECT:
            {
                Object o = getColumnInType(columnIndex, sourceType);
                if (o == null) {
                    return null;
                }
                try {
                    return ((JavaObjectData) o).getObject();
                } catch (HsqlException e) {
                    throw Util.sqlException(e);
                }
            }
        default:
            return getColumnInType(columnIndex, sourceType);
    }
}
Also used : Type(org.hsqldb_voltpatches.types.Type) HsqlException(org.hsqldb_voltpatches.HsqlException)

Aggregations

Type (org.hsqldb_voltpatches.types.Type)72 HsqlName (org.hsqldb_voltpatches.HsqlNameManager.HsqlName)20 CharacterType (org.hsqldb_voltpatches.types.CharacterType)20 NumberType (org.hsqldb_voltpatches.types.NumberType)14 SchemaObject (org.hsqldb_voltpatches.SchemaObject)11 Table (org.hsqldb_voltpatches.Table)9 Iterator (org.hsqldb_voltpatches.lib.Iterator)9 WrapperIterator (org.hsqldb_voltpatches.lib.WrapperIterator)9 IntervalType (org.hsqldb_voltpatches.types.IntervalType)9 Constraint (org.hsqldb_voltpatches.Constraint)8 PersistentStore (org.hsqldb_voltpatches.persist.PersistentStore)8 HsqlException (org.hsqldb_voltpatches.HsqlException)7 TextTable (org.hsqldb_voltpatches.TextTable)6 HsqlArrayList (org.hsqldb_voltpatches.lib.HsqlArrayList)6 DTIType (org.hsqldb_voltpatches.types.DTIType)6 ColumnSchema (org.hsqldb_voltpatches.ColumnSchema)4 DateTimeType (org.hsqldb_voltpatches.types.DateTimeType)4 OrderedHashSet (org.hsqldb_voltpatches.lib.OrderedHashSet)3 IOException (java.io.IOException)2 Method (java.lang.reflect.Method)2