Skip to content
Open
Show file tree
Hide file tree
Changes from all 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 @@ -413,11 +413,14 @@ public String paramDefinition(Object value) {
@Override
public void encodeParam(ByteBuf byteBuf, String name, boolean out, Object value) {
BigDecimal bigDecimal = (BigDecimal) value;
if (bigDecimal.scale() < 0) {
bigDecimal = bigDecimal.setScale(0);
}
writeParamDescription(byteBuf, name, out, id);
writeParamSize(byteBuf, 17, 38);
int sign = bigDecimal.signum() < 0 ? 0 : 1;
byte[] bytes = (sign == 0 ? bigDecimal.negate() : bigDecimal).unscaledValue().toByteArray();
byteBuf.writeByte(Math.max(0, bigDecimal.scale()));
byteBuf.writeByte(bigDecimal.scale());
byteBuf.writeByte(1 + bytes.length);
byteBuf.writeByte(sign);
for (int i = bytes.length - 1; i >= 0; i--) byteBuf.writeByte(bytes[i]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ public void testEncodeDecimal(TestContext ctx) {
testEncodeNumber(ctx, "test_decimal", new BigDecimal("123456789"));
}

@Test
public void testEncodeDecimalWithNegativeScale(TestContext ctx) {
testPreparedQueryEncodeGeneric(ctx, "not_nullable_datatype", "test_decimal", new BigDecimal("1500").stripTrailingZeros(), row -> {
checkNumber(row, "test_decimal", new BigDecimal("1500"));
});
}

@Test
public void testEncodeBit(TestContext ctx) {
testPreparedQueryEncodeGeneric(ctx, "not_nullable_datatype", "test_boolean", false, row -> {
Expand Down