Skip to content

Commit

Permalink
fix wrong return type of getBlob()
Browse files Browse the repository at this point in the history
  • Loading branch information
tuohai666 committed Aug 15, 2019
1 parent cdae579 commit 22fdf53
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
Expand Up @@ -73,10 +73,6 @@ public static Object getValueByColumnType(final ResultSet resultSet, final int c
case Types.VARCHAR:
case Types.LONGVARCHAR:
return resultSet.getString(columnIndex);
case Types.BINARY:
case Types.VARBINARY:
case Types.LONGVARBINARY:
return resultSet.getBytes(columnIndex);
case Types.DATE:
return resultSet.getDate(columnIndex);
case Types.TIME:
Expand All @@ -86,6 +82,9 @@ public static Object getValueByColumnType(final ResultSet resultSet, final int c
case Types.CLOB:
return resultSet.getClob(columnIndex);
case Types.BLOB:
case Types.BINARY:
case Types.VARBINARY:
case Types.LONGVARBINARY:
return resultSet.getBlob(columnIndex);
default:
return resultSet.getObject(columnIndex);
Expand Down
Expand Up @@ -150,23 +150,26 @@ public void assertGetValueByLongVarchar() throws SQLException {

@Test
public void assertGetValueByBinary() throws SQLException {
Blob blob = mock(Blob.class);
when(resultSetMetaData.getColumnType(1)).thenReturn(Types.BINARY);
when(resultSet.getBytes(1)).thenReturn("xxxxx".getBytes());
assertThat((byte[]) QueryResultUtil.getValue(resultSet, 1), is("xxxxx".getBytes()));
when(resultSet.getBlob(1)).thenReturn(blob);
assertThat((Blob) QueryResultUtil.getValue(resultSet, 1), is(blob));
}

@Test
public void assertGetValueByVarBinary() throws SQLException {
Blob blob = mock(Blob.class);
when(resultSetMetaData.getColumnType(1)).thenReturn(Types.VARBINARY);
when(resultSet.getBytes(1)).thenReturn("xxxxx".getBytes());
assertThat((byte[]) QueryResultUtil.getValue(resultSet, 1), is("xxxxx".getBytes()));
when(resultSet.getBlob(1)).thenReturn(blob);
assertThat((Blob) QueryResultUtil.getValue(resultSet, 1), is(blob));
}

@Test
public void assertGetValueByLongVarBinary() throws SQLException {
Blob blob = mock(Blob.class);
when(resultSetMetaData.getColumnType(1)).thenReturn(Types.LONGVARBINARY);
when(resultSet.getBytes(1)).thenReturn("xxxxx".getBytes());
assertThat((byte[]) QueryResultUtil.getValue(resultSet, 1), is("xxxxx".getBytes()));
when(resultSet.getBlob(1)).thenReturn(blob);
assertThat((Blob) QueryResultUtil.getValue(resultSet, 1), is(blob));
}

@Test
Expand Down

0 comments on commit 22fdf53

Please sign in to comment.