Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[CONJ-399] resultSet getLong() for BIGINT column fails if value is Lo…
…ng.MIN_VALUE
  • Loading branch information
rusher committed Dec 12, 2016
1 parent 764285c commit a52646d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
Expand Up @@ -3232,6 +3232,8 @@ private long parseLong(byte[] rawBytes, ColumnInformation columnInfo) throws SQL
}
//specific for BIGINT : if value > Long.MAX_VALUE , will become negative until -1
if (result < 0) {
//CONJ-399 : handle specifically Long.MIN_VALUE that has absolute value +1 compare to LONG.MAX_VALUE
if (result == Long.MIN_VALUE && negate) return Long.MIN_VALUE;
throw new SQLException("Out of range value for column '" + columnInfo.getName() + "' : value "
+ new String(rawBytes, StandardCharsets.UTF_8)
+ " is not in Long range", "22003", 1264);
Expand Down
31 changes: 31 additions & 0 deletions src/test/java/org/mariadb/jdbc/DatatypeTest.java
Expand Up @@ -862,4 +862,35 @@ public void testNullTimePreparedStatement() throws Exception {
}
}
}

@Test
public void longMinValueSpecificity() throws SQLException {
createTable("longMinValueSpecificity", "ii BIGINT");
try (Statement statement = sharedConnection.createStatement()) {

try (PreparedStatement preparedStatement = sharedConnection.prepareStatement(
"INSERT INTO longMinValueSpecificity values (?)")) {
preparedStatement.setLong(1, Long.MAX_VALUE);
preparedStatement.executeQuery();
preparedStatement.setLong(1, Long.MIN_VALUE);
preparedStatement.executeQuery();
}

try (PreparedStatement preparedStatement = sharedConnection.prepareStatement(
"SELECT * from longMinValueSpecificity")) {
ResultSet resultSet = preparedStatement.executeQuery();
Assert.assertTrue(resultSet.next());
Assert.assertEquals(Long.MAX_VALUE, resultSet.getLong(1));
Assert.assertTrue(resultSet.next());
Assert.assertEquals(Long.MIN_VALUE, resultSet.getLong(1));
}

ResultSet resultSet = statement.executeQuery("SELECT * from longMinValueSpecificity");
Assert.assertTrue(resultSet.next());
Assert.assertEquals(Long.MAX_VALUE, resultSet.getLong(1));
Assert.assertTrue(resultSet.next());
Assert.assertEquals(Long.MIN_VALUE, resultSet.getLong(1));
}
}

}

0 comments on commit a52646d

Please sign in to comment.