Search in sources :

Example 1 with VariableSizeDataValue

use of org.apache.derby.iapi.types.VariableSizeDataValue in project derby by apache.

the class EmbedPreparedStatement method setScale.

/**
 * Set the scale of a parameter.
 *
 * @param parameterIndex The first parameter is 1, the second is 2, ...
 * @param scale	The scale
 * @exception SQLException thrown on failure.
 */
private void setScale(int parameterIndex, int scale) throws SQLException {
    checkStatus();
    if (scale < 0)
        throw newSQLException(SQLState.BAD_SCALE_VALUE, scale);
    try {
        ParameterValueSet pvs = getParms();
        /* JDBC is one-based, DBMS is zero-based */
        DataValueDescriptor value = pvs.getParameter(parameterIndex - 1);
        int origvaluelen = value.getLength();
        ((VariableSizeDataValue) value).setWidth(VariableSizeDataValue.IGNORE_PRECISION, scale, false);
        if (value.getLength() < origvaluelen) {
            activation.addWarning(StandardException.newWarning(SQLState.LANG_VALUE_TRUNCATED, value.getString()));
        }
    } catch (StandardException t) {
        throw EmbedResultSet.noStateChangeException(t);
    }
}
Also used : ParameterValueSet(org.apache.derby.iapi.sql.ParameterValueSet) StandardException(org.apache.derby.shared.common.error.StandardException) VariableSizeDataValue(org.apache.derby.iapi.types.VariableSizeDataValue) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor)

Example 2 with VariableSizeDataValue

use of org.apache.derby.iapi.types.VariableSizeDataValue in project derby by apache.

the class EmbedResultSet method adjustScale.

/**
 * <p>
 * Adjust the scale of a type.
 * </p>
 */
protected void adjustScale(int columnIndex, int scale) throws SQLException {
    /*
		* If the parameter type is DECIMAL or NUMERIC, then
		* we need to set them to the passed scale.
		*/
    int colType = getColumnType(columnIndex);
    if ((colType == Types.DECIMAL) || (colType == Types.NUMERIC)) {
        if (scale < 0)
            throw newSQLException(SQLState.BAD_SCALE_VALUE, scale);
        try {
            DataValueDescriptor value = updateRow.getColumn(columnIndex);
            int origvaluelen = value.getLength();
            ((VariableSizeDataValue) value).setWidth(VariableSizeDataValue.IGNORE_PRECISION, scale, false);
        } catch (StandardException t) {
            throw EmbedResultSet.noStateChangeException(t);
        }
    }
}
Also used : StandardException(org.apache.derby.shared.common.error.StandardException) VariableSizeDataValue(org.apache.derby.iapi.types.VariableSizeDataValue) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor)

Example 3 with VariableSizeDataValue

use of org.apache.derby.iapi.types.VariableSizeDataValue in project derby by apache.

the class VTIResultSet method castDecimal.

/**
 * <p>
 * Set the correct precision and scale for a decimal value.
 * </p>
 */
private void castDecimal(DataTypeDescriptor dtd, DataValueDescriptor dvd) throws StandardException {
    VariableSizeDataValue vsdv = (VariableSizeDataValue) dvd;
    vsdv.setWidth(dtd.getPrecision(), dtd.getScale(), false);
}
Also used : VariableSizeDataValue(org.apache.derby.iapi.types.VariableSizeDataValue)

Example 4 with VariableSizeDataValue

use of org.apache.derby.iapi.types.VariableSizeDataValue in project derby by apache.

the class VTIResultSet method cast.

/**
 * <p>
 * Cast the value coming out of the user-coded ResultSet. The
 * rules are described in CastNode.getDataValueConversion().
 * </p>
 */
private void cast(DataTypeDescriptor dtd, DataValueDescriptor dvd) throws StandardException {
    TypeId typeID = dtd.getTypeId();
    if (!typeID.isBlobTypeId() && !typeID.isClobTypeId()) {
        if (typeID.isLongVarcharTypeId()) {
            castLongvarchar(dtd, dvd);
        } else if (typeID.isLongVarbinaryTypeId()) {
            castLongvarbinary(dtd, dvd);
        } else if (typeID.isDecimalTypeId()) {
            castDecimal(dtd, dvd);
        } else {
            Object o = dvd.getObject();
            dvd.setObjectForCast(o, true, typeID.getCorrespondingJavaTypeName());
            if (typeID.variableLength()) {
                VariableSizeDataValue vsdv = (VariableSizeDataValue) dvd;
                int width;
                if (typeID.isNumericTypeId()) {
                    width = dtd.getPrecision();
                } else {
                    width = dtd.getMaximumWidth();
                }
                vsdv.setWidth(width, dtd.getScale(), false);
            }
        }
    }
}
Also used : TypeId(org.apache.derby.iapi.types.TypeId) VariableSizeDataValue(org.apache.derby.iapi.types.VariableSizeDataValue)

Aggregations

VariableSizeDataValue (org.apache.derby.iapi.types.VariableSizeDataValue)4 DataValueDescriptor (org.apache.derby.iapi.types.DataValueDescriptor)2 StandardException (org.apache.derby.shared.common.error.StandardException)2 ParameterValueSet (org.apache.derby.iapi.sql.ParameterValueSet)1 TypeId (org.apache.derby.iapi.types.TypeId)1