Skip to content

Commit

Permalink
Revert "BigDecimal Precision/Scale Fix (#1912)"
Browse files Browse the repository at this point in the history
This reverts commit 05ef7c0.
  • Loading branch information
lilgreenbird committed Sep 26, 2022
1 parent 05ef7c0 commit 01058f1
Show file tree
Hide file tree
Showing 2 changed files with 227 additions and 351 deletions.
37 changes: 14 additions & 23 deletions src/main/java/com/microsoft/sqlserver/jdbc/Parameter.java
Original file line number Diff line number Diff line change
Expand Up @@ -426,14 +426,13 @@ final class GetTypeDefinitionOp extends DTVExecuteOp {

private final Parameter param;
private final SQLServerConnection con;
private BigDecimal providedDecimal;

GetTypeDefinitionOp(Parameter param, SQLServerConnection con) {
this.param = param;
this.con = con;
}

private void setTypeDefinition(DTV dtv) throws SQLServerException {
private void setTypeDefinition(DTV dtv) {
switch (dtv.getJdbcType()) {
case TINYINT:
param.typeDefinition = SSType.TINYINT.toString();
Expand Down Expand Up @@ -506,42 +505,34 @@ private void setTypeDefinition(DTV dtv) throws SQLServerException {
// so, here, if the decimal parameter is encrypted and it is null and it is not outparameter
// then we set precision as the default precision instead of max precision
if (!isOutput()) {
param.typeDefinition = SSType.DECIMAL.toString() + "("
+ SQLServerConnection.defaultDecimalPrecision + ", " + scale + ")";
param.typeDefinition = "decimal(" + SQLServerConnection.defaultDecimalPrecision + ", "
+ scale + ")";
}
} else {
if (SQLServerConnection.defaultDecimalPrecision >= valueLength) {
param.typeDefinition = SSType.DECIMAL.toString() + "("
+ SQLServerConnection.defaultDecimalPrecision + "," + scale + ")";
param.typeDefinition = "decimal(" + SQLServerConnection.defaultDecimalPrecision + ","
+ scale + ")";

if (SQLServerConnection.defaultDecimalPrecision < (valueLength + scale)) {
param.typeDefinition = SSType.DECIMAL.toString() + "("
+ (SQLServerConnection.defaultDecimalPrecision + scale) + "," + scale + ")";
param.typeDefinition = "decimal("
+ (SQLServerConnection.defaultDecimalPrecision + scale) + "," + scale + ")";
}
} else {
param.typeDefinition = SSType.DECIMAL.toString() + "("
+ SQLServerConnection.maxDecimalPrecision + "," + scale + ")";
param.typeDefinition = "decimal(" + SQLServerConnection.maxDecimalPrecision + ","
+ scale + ")";
}
}

if (isOutput()) {
param.typeDefinition = SSType.DECIMAL.toString() + "("
+ SQLServerConnection.maxDecimalPrecision + ", " + scale + ")";
param.typeDefinition = "decimal(" + SQLServerConnection.maxDecimalPrecision + ", " + scale
+ ")";
}

if (userProvidesPrecision) {
param.typeDefinition = SSType.DECIMAL.toString() + "(" + valueLength + "," + scale + ")";
param.typeDefinition = "decimal(" + valueLength + "," + scale + ")";
}
} else if (dtv.getJavaType() == JavaType.BIGDECIMAL
&& (providedDecimal = (BigDecimal) dtv.getValue(dtv.getJdbcType(), scale, null, null,
typeInfo, cryptoMeta, null, null)) != null
&& providedDecimal.precision() >= scale) {
param.typeDefinition = SSType.DECIMAL.toString() + "(" + providedDecimal.precision()
+ "," + scale + ")";
} else {
param.typeDefinition = SSType.DECIMAL.toString() + "("
+ SQLServerConnection.maxDecimalPrecision + "," + scale + ")";
}
} else
param.typeDefinition = "decimal(" + SQLServerConnection.maxDecimalPrecision + "," + scale + ")";

break;

Expand Down
Loading

0 comments on commit 01058f1

Please sign in to comment.