Skip to content

Commit

Permalink
#3725, fix MemoryQueryResult wrong data type (#3728)
Browse files Browse the repository at this point in the history
  • Loading branch information
tuohai666 authored and terrymanu committed Dec 12, 2019
1 parent 2ad2608 commit 44069f5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
Expand Up @@ -75,9 +75,15 @@ private Object getRowValue(final ResultSet resultSet, final int columnIndex) thr
case Types.SMALLINT:
return resultSet.getInt(columnIndex);
case Types.INTEGER:
return metaData.isSigned(columnIndex) ? resultSet.getInt(columnIndex) : resultSet.getLong(columnIndex);
if (metaData.isSigned(columnIndex)) {
return resultSet.getInt(columnIndex);
}
return resultSet.getLong(columnIndex);
case Types.BIGINT:
return metaData.isSigned(columnIndex) ? resultSet.getLong(columnIndex) : resultSet.getBigDecimal(columnIndex).toBigInteger();
if (metaData.isSigned(columnIndex)) {
return resultSet.getLong(columnIndex);
}
return resultSet.getBigDecimal(columnIndex).toBigInteger();
case Types.NUMERIC:
case Types.DECIMAL:
return resultSet.getBigDecimal(columnIndex);
Expand Down
Expand Up @@ -114,20 +114,43 @@ public void assertGetValueBySignedInteger() throws SQLException {
when(resultSet.getMetaData().isSigned(1)).thenReturn(true);
MemoryQueryResult actual = new MemoryQueryResult(resultSet);
assertTrue(actual.next());
assertThat(actual.getValue(1, int.class), is((Object) 1L));
assertThat(actual.getValue(1, int.class), is((Object) 1));
assertFalse(actual.next());
}

@Test
public void assertGetValueByUnsignedInteger() throws SQLException {
ResultSet resultSet = getMockedResultSet(Types.INTEGER);
when(resultSet.getLong(1)).thenReturn(1L);
when(resultSet.getMetaData().isSigned(1)).thenReturn(false);
MemoryQueryResult actual = new MemoryQueryResult(resultSet);
assertTrue(actual.next());
assertThat(actual.getValue(1, int.class), is((Object) 1L));
assertFalse(actual.next());
}

@Test
public void assertGetValueBySignedBigInt() throws SQLException {
ResultSet resultSet = getMockedResultSet(Types.BIGINT);
when(resultSet.getLong(1)).thenReturn(1L);
when(resultSet.getMetaData().isSigned(1)).thenReturn(true);
MemoryQueryResult actual = new MemoryQueryResult(resultSet);
assertTrue(actual.next());
assertThat(actual.getValue(1, long.class), is((Object) 1L));
assertFalse(actual.next());
}

@Test
public void assertGetValueByUnsignedBigInt() throws SQLException {
ResultSet resultSet = getMockedResultSet(Types.BIGINT);
when(resultSet.getBigDecimal(1)).thenReturn(new BigDecimal("1"));
when(resultSet.getMetaData().isSigned(1)).thenReturn(false);
MemoryQueryResult actual = new MemoryQueryResult(resultSet);
assertTrue(actual.next());
assertThat(actual.getValue(1, long.class), is((Object) new BigDecimal("1").toBigInteger()));
assertFalse(actual.next());
}

@Test
public void assertGetValueByNumeric() throws SQLException {
ResultSet resultSet = getMockedResultSet(Types.NUMERIC);
Expand Down Expand Up @@ -297,7 +320,7 @@ private ResultSet getMockedResultSet(final int columnTypes) throws SQLException
public void assertGetCalendarValue() throws SQLException {
MemoryQueryResult queryResult = new MemoryQueryResult(getResultSet());
queryResult.next();
assertThat(queryResult.getCalendarValue(1, Integer.class, Calendar.getInstance()), Is.<Object>is(1L));
assertThat(queryResult.getCalendarValue(1, Integer.class, Calendar.getInstance()), Is.<Object>is(1));
}

@Test
Expand Down

0 comments on commit 44069f5

Please sign in to comment.