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);
}
}
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);
}
}
}
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);
}
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);
}
}
}
}
Aggregations