From e57a4ff263c56055447cc0f6878f67919834a0b8 Mon Sep 17 00:00:00 2001 From: Yohei Ueki Date: Mon, 6 Jan 2025 17:12:58 +0900 Subject: [PATCH] Fixed for Bug#109339, BIGINT UNSIGNED column fails to accept its maximum supported value --- .../cj/protocol/a/NumberValueEncoder.java | 2 +- .../regression/NumbersRegressionTest.java | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/main/protocol-impl/java/com/mysql/cj/protocol/a/NumberValueEncoder.java b/src/main/protocol-impl/java/com/mysql/cj/protocol/a/NumberValueEncoder.java index c18bfe1b8..0c614f8dc 100644 --- a/src/main/protocol-impl/java/com/mysql/cj/protocol/a/NumberValueEncoder.java +++ b/src/main/protocol-impl/java/com/mysql/cj/protocol/a/NumberValueEncoder.java @@ -56,7 +56,7 @@ public String getString(BindValue binding) { case INT_UNSIGNED: case BIGINT: case BIGINT_UNSIGNED: - return String.valueOf(x.longValue()); + return x.toString(); case FLOAT: case FLOAT_UNSIGNED: return StringUtils.fixDecimalExponent(Float.toString(x.floatValue())); diff --git a/src/test/java/testsuite/regression/NumbersRegressionTest.java b/src/test/java/testsuite/regression/NumbersRegressionTest.java index 8711ccd5c..11dd86867 100644 --- a/src/test/java/testsuite/regression/NumbersRegressionTest.java +++ b/src/test/java/testsuite/regression/NumbersRegressionTest.java @@ -24,6 +24,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import java.math.BigDecimal; +import java.math.BigInteger; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSetMetaData; @@ -270,4 +271,25 @@ public void testBug105915() throws Exception { } while ((useSPS = !useSPS) || (useCursorFetch = !useCursorFetch)); } + /** + * Tests fix for BUG#109339, BIGINT UNSIGNED column fails to accept its maximum supported value. + * + * @throws Exception + */ + @Test + public void testBug109339() throws Exception { + BigInteger value = new BigInteger("18446744073709551615"); // 2^64-1 - maximum value supported by BIGINT UNSIGNED + + createTable("testBug109339", "(field1 BIGINT UNSIGNED)"); + + PreparedStatement ps = this.conn.prepareStatement("INSERT INTO testBug109339 VALUES (?)"); + ps.setObject(1, value); + ps.executeUpdate(); + + this.rs = this.conn.prepareStatement("SELECT * FROM testBug109339").executeQuery(); + this.rs.next(); + + assertTrue(this.rs.getObject(1).toString().equals(value.toString())); + } + }