Skip to content

Commit bfdd805

Browse files
committed
Decode SMALLMONEY with four decimal places
SMALLMONEY is stored in ten-thousandths, but the decoder rounded it up to two decimals, so 214748.3647 was returned as 214748.37. MONEY already uses four. Signed-off-by: Sharang Gupta <sharang@sharanggupta.dev> Assisted-by: Anthropic Claude (claude-opus-5-5)
1 parent fc82e01 commit bfdd805

5 files changed

Lines changed: 21 additions & 11 deletions

File tree

‎vertx-mssql-client/src/main/java/io/vertx/mssqlclient/impl/codec/DataType.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ public TypeInfo decodeTypeInfo(ByteBuf byteBuf) {
219219

220220
@Override
221221
public Object decodeValue(ByteBuf byteBuf, TypeInfo typeInfo) {
222-
return new BigDecimal(byteBuf.readIntLE()).divide(new BigDecimal("10000"), 2, RoundingMode.UP);
222+
return new BigDecimal(byteBuf.readIntLE()).divide(new BigDecimal("10000"), 4, RoundingMode.UP);
223223
}
224224

225225
@Override

‎vertx-mssql-client/src/test/java/io/vertx/tests/mssqlclient/data/MSSQLFullDataTypeTestBase.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public void testDecodeAllColumns(TestContext ctx) {
5353
ctx.assertEquals(Buffer.buffer("venice of the north"), row.getValue("test_varbinary_max"));
5454
ctx.assertEquals(Buffer.buffer("paris of the west"), row.getValue("test_image"));
5555
ctx.assertEquals(new BigDecimal("12.3456"), row.getValue("test_money"));
56-
ctx.assertEquals(new BigDecimal("12.34"), row.getValue("test_smallmoney"));
56+
ctx.assertEquals(new BigDecimal("12.3400"), row.getValue("test_smallmoney"));
5757
});
5858
}
5959

@@ -266,7 +266,7 @@ public void testDecodeMoney(TestContext ctx) {
266266
@Test
267267
public void testDecodeSmallMoney(TestContext ctx) {
268268
testDecodeNotNullValue(ctx, "test_smallmoney", row -> {
269-
checkNumber(row, "test_smallmoney", new BigDecimal("12.34"));
269+
checkNumber(row, "test_smallmoney", new BigDecimal("12.3400"));
270270
});
271271
}
272272

‎vertx-mssql-client/src/test/java/io/vertx/tests/mssqlclient/data/MSSQLPreparedQueryNotNullableDataTypeTest.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ public void testEncodeMoney(TestContext ctx) {
319319
@Test
320320
public void testEncodeSmallMoney(TestContext ctx) {
321321
testPreparedQueryEncodeGeneric(ctx, "not_nullable_datatype", "test_smallmoney", "€12.12", row -> {
322-
checkNumber(row, "test_smallmoney", new BigDecimal("12.12"));
322+
checkNumber(row, "test_smallmoney", new BigDecimal("12.1200"));
323323
});
324324
}
325325

‎vertx-mssql-client/src/test/java/io/vertx/tests/mssqlclient/data/MSSQLPreparedQueryNullableDataTypeTest.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ public void testEncodeNullMoney(TestContext ctx) {
460460

461461
@Test
462462
public void testEncodeNullSmallMoney(TestContext ctx) {
463-
testEncodeNumber(ctx, "test_smallmoney", new BigDecimal("123.13"));
463+
testEncodeNumber(ctx, "test_smallmoney", new BigDecimal("123.1313"));
464464
}
465465

466466
private void testEncodeBufferValue(TestContext ctx, String columnName, Object value, Object expected) {

‎vertx-mssql-client/src/test/java/io/vertx/tests/mssqlclient/data/MSSQLSmallMoneyDataTypeTest.java‎

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,31 +23,41 @@ public class MSSQLSmallMoneyDataTypeTest extends MSSQLDataTypeTestBase {
2323

2424
@Test
2525
public void testQueryLargeMoney(TestContext ctx) {
26-
testQueryDecodeGenericWithoutTable(ctx, "test_smallmoney", "SMALLMONEY", "214748.36", new BigDecimal("214748.36"));
26+
testQueryDecodeGenericWithoutTable(ctx, "test_smallmoney", "SMALLMONEY", "214748.36", new BigDecimal("214748.3600"));
27+
}
28+
29+
@Test
30+
public void testQueryMaxMoney(TestContext ctx) {
31+
testQueryDecodeGenericWithoutTable(ctx, "test_smallmoney", "SMALLMONEY", "214748.3647", new BigDecimal("214748.3647"));
2732
}
2833

2934
@Test
3035
public void testQueryLargeNegativeMoney(TestContext ctx) {
31-
testQueryDecodeGenericWithoutTable(ctx, "test_smallmoney", "SMALLMONEY", "-214748.36", new BigDecimal("-214748.36"));
36+
testQueryDecodeGenericWithoutTable(ctx, "test_smallmoney", "SMALLMONEY", "-214748.36", new BigDecimal("-214748.3600"));
3237
}
3338

3439
@Test
3540
public void testQueryMoneyWithCurrency(TestContext ctx) {
36-
testQueryDecodeGenericWithoutTable(ctx, "test_smallmoney", "SMALLMONEY", "$12.34", new BigDecimal("12.34"));
41+
testQueryDecodeGenericWithoutTable(ctx, "test_smallmoney", "SMALLMONEY", "$12.34", new BigDecimal("12.3400"));
3742
}
3843

3944
@Test
4045
public void testPreparedQueryLargeMoney(TestContext ctx) {
41-
testPreparedQueryDecodeGenericWithoutTable(ctx, "test_smallmoney", "SMALLMONEY", "214748.36", new BigDecimal("214748.36"));
46+
testPreparedQueryDecodeGenericWithoutTable(ctx, "test_smallmoney", "SMALLMONEY", "214748.36", new BigDecimal("214748.3600"));
47+
}
48+
49+
@Test
50+
public void testPreparedQueryMaxMoney(TestContext ctx) {
51+
testPreparedQueryDecodeGenericWithoutTable(ctx, "test_smallmoney", "SMALLMONEY", "214748.3647", new BigDecimal("214748.3647"));
4252
}
4353

4454
@Test
4555
public void testPreparedQueryLargeNegativeMoney(TestContext ctx) {
46-
testPreparedQueryDecodeGenericWithoutTable(ctx, "test_smallmoney", "SMALLMONEY", "-214748.36", new BigDecimal("-214748.36"));
56+
testPreparedQueryDecodeGenericWithoutTable(ctx, "test_smallmoney", "SMALLMONEY", "-214748.36", new BigDecimal("-214748.3600"));
4757
}
4858

4959
@Test
5060
public void testPreparedQueryMoneyWithCurrency(TestContext ctx) {
51-
testPreparedQueryDecodeGenericWithoutTable(ctx, "test_smallmoney", "SMALLMONEY", "$12.34", new BigDecimal("12.34"));
61+
testPreparedQueryDecodeGenericWithoutTable(ctx, "test_smallmoney", "SMALLMONEY", "$12.34", new BigDecimal("12.3400"));
5262
}
5363
}

0 commit comments

Comments
 (0)