Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes error message to be thrown when data out of range for DECIMAL/NUMERIC types #796

Merged
merged 5 commits into from
Sep 25, 2018
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ enum SQLState {
STATEMENT_CANCELED("HY008"),
DATA_EXCEPTION_NOT_SPECIFIC("22000"),
DATA_EXCEPTION_DATETIME_FIELD_OVERFLOW("22008"),
NUMERIC_DATA_OUT_OF_RANGE("22003"),
DATA_EXCEPTION_LENGTH_MISMATCH("22026"),
COL_NOT_FOUND("42S22");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ protected Object[][] getContents() {
{"R_invalidProperty", "This property is not supported: {0}."},
{"R_referencingFailedTSP", "The DataSource trustStore password needs to be set."},
{"R_valueOutOfRange", "One or more values is out of range of values for the {0} SQL Server data type."},
{"R_valueOutOfRangeSQLType", "One or more values is out of range of values for the {0} SQL type."},
{"R_integratedAuthenticationFailed", "Integrated authentication failed."},
{"R_permissionDenied", "Security violation. Permission to target \"{0}\" denied."},
{"R_getSchemaError", "Error getting default schema name."},
Expand Down
16 changes: 12 additions & 4 deletions src/main/java/com/microsoft/sqlserver/jdbc/dtv.java
Original file line number Diff line number Diff line change
Expand Up @@ -1083,8 +1083,16 @@ void execute(DTV dtv, Double doubleValue) throws SQLServerException {

void execute(DTV dtv, BigDecimal bigDecimalValue) throws SQLServerException {
if (DDC.exceedsMaxRPCDecimalPrecisionOrScale(bigDecimalValue)) {
String strValue = bigDecimalValue.toString();
tdsWriter.writeRPCStringUnicode(name, strValue, isOutParam, collation);
if (JDBCType.DECIMAL == dtv.getJdbcType() || JDBCType.NUMERIC == dtv.getJdbcType()) {
// Throw exception for DECIMAL and NUMERIC Datatypes
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_valueOutOfRangeSQLType"));
Object[] msgArgs = {JDBCType.DECIMAL == dtv.getJdbcType() ? SSType.DECIMAL : SSType.NUMERIC};
ulvii marked this conversation as resolved.
Show resolved Hide resolved
throw new SQLServerException(form.format(msgArgs), SQLState.NUMERIC_DATA_OUT_OF_RANGE,
DriverError.NOT_SET, null);
} else {
String strValue = bigDecimalValue.toString();
tdsWriter.writeRPCStringUnicode(name, strValue, isOutParam, collation);
}
} else {
tdsWriter.writeRPCBigDecimal(name, bigDecimalValue, outScale, isOutParam);
}
Expand Down Expand Up @@ -1758,7 +1766,7 @@ else if ((JDBCType.VARCHAR == jdbcTypeSetByUser) || (JDBCType.CHAR == jdbcTypeSe
SQLServerException.getErrString("R_valueOutOfRange"));
Object[] msgArgs = {cryptoMeta.getBaseTypeInfo().getSSTypeName()};
throw new SQLServerException(form.format(msgArgs),
SQLState.DATA_EXCEPTION_DATETIME_FIELD_OVERFLOW, DriverError.NOT_SET, null);
SQLState.NUMERIC_DATA_OUT_OF_RANGE, DriverError.NOT_SET, null);
}
} else {
// if the precision that user provides is smaller than the precision of the actual
Expand All @@ -1772,7 +1780,7 @@ else if ((JDBCType.VARCHAR == jdbcTypeSetByUser) || (JDBCType.CHAR == jdbcTypeSe
SQLServerException.getErrString("R_valueOutOfRange"));
Object[] msgArgs = {SSType.DECIMAL};
throw new SQLServerException(form.format(msgArgs),
SQLState.DATA_EXCEPTION_DATETIME_FIELD_OVERFLOW, DriverError.NOT_SET, null);
SQLState.NUMERIC_DATA_OUT_OF_RANGE, DriverError.NOT_SET, null);
}
}

Expand Down