fix(iris): display %Boolean columns as stored 1/0 values
This commit is contained in:
4 files changed
+100
No files matched your search
@@ -53,6 +53,15 @@ public final class CacheAgent extends ConfiguredJdbcAgent {
|
|||||||
Object value = rs.getBigDecimal(index);
|
Object value = rs.getBigDecimal(index);
|
||||||
return rs.wasNull() ? null : value;
|
return rs.wasNull() ? null : value;
|
||||||
});
|
});
|
||||||
|
case Types.BIT:
|
||||||
|
case Types.BOOLEAN:
|
||||||
|
// Caché has no boolean type: %Boolean is stored as 1/0 and only
|
||||||
|
// the JDBC driver turns it into a Java boolean, which would
|
||||||
|
// surface as true/false in the grid. Report the stored 1/0.
|
||||||
|
return unchecked(() -> {
|
||||||
|
int value = rs.getInt(index);
|
||||||
|
return rs.wasNull() ? null : value;
|
||||||
|
});
|
||||||
case Types.OTHER:
|
case Types.OTHER:
|
||||||
return unchecked(() -> JdbcExecutor.normalizeResultValue(rs.getObject(index)));
|
return unchecked(() -> JdbcExecutor.normalizeResultValue(rs.getObject(index)));
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -159,6 +159,47 @@ class CacheAgentTest {
|
|||||||
assertEquals(Collections.singletonList("getObject"), calls);
|
assertEquals(Collections.singletonList("getObject"), calls);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void readsBitColumnsAsStoredNumbers() {
|
||||||
|
for (int sqlType : new int[] {Types.BIT, Types.BOOLEAN}) {
|
||||||
|
List<String> calls = new ArrayList<>();
|
||||||
|
ResultSet resultSet = proxy(ResultSet.class, (method, args) -> {
|
||||||
|
if ("getInt".equals(method.getName())) {
|
||||||
|
calls.add("getInt");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (method.getName().startsWith("get")) {
|
||||||
|
calls.add(method.getName());
|
||||||
|
throw new AssertionError("Caché %Boolean must not be read as a Java boolean");
|
||||||
|
}
|
||||||
|
if ("wasNull".equals(method.getName())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return defaultValue(method.getReturnType());
|
||||||
|
});
|
||||||
|
|
||||||
|
Object value = new CacheAgent().resultValue(resultSet, 1, sqlType);
|
||||||
|
|
||||||
|
assertEquals(1, value);
|
||||||
|
assertEquals(Collections.singletonList("getInt"), calls);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void preservesNullForBitColumns() {
|
||||||
|
ResultSet resultSet = proxy(ResultSet.class, (method, args) -> {
|
||||||
|
if ("getInt".equals(method.getName())) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if ("wasNull".equals(method.getName())) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return defaultValue(method.getReturnType());
|
||||||
|
});
|
||||||
|
|
||||||
|
assertNull(new CacheAgent().resultValue(resultSet, 1, Types.BIT));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void readsColumnsAndUsesInlinePrimaryKey() {
|
void readsColumnsAndUsesInlinePrimaryKey() {
|
||||||
List<String> calls = new ArrayList<>();
|
List<String> calls = new ArrayList<>();
|
||||||
|
|||||||
@@ -78,6 +78,15 @@ public final class IrisAgent extends ConfiguredJdbcAgent {
|
|||||||
Object value = rs.getBigDecimal(index);
|
Object value = rs.getBigDecimal(index);
|
||||||
return rs.wasNull() ? null : value;
|
return rs.wasNull() ? null : value;
|
||||||
});
|
});
|
||||||
|
case Types.BIT:
|
||||||
|
case Types.BOOLEAN:
|
||||||
|
// IRIS has no boolean type: %Boolean is stored as 1/0 and only
|
||||||
|
// the JDBC driver turns it into a Java boolean, which would
|
||||||
|
// surface as true/false in the grid. Report the stored 1/0.
|
||||||
|
return unchecked(() -> {
|
||||||
|
int value = rs.getInt(index);
|
||||||
|
return rs.wasNull() ? null : value;
|
||||||
|
});
|
||||||
case Types.OTHER:
|
case Types.OTHER:
|
||||||
return unchecked(() -> JdbcExecutor.normalizeResultValue(rs.getObject(index)));
|
return unchecked(() -> JdbcExecutor.normalizeResultValue(rs.getObject(index)));
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -147,6 +147,47 @@ class IrisAgentTest {
|
|||||||
assertEquals(Collections.singletonList("getObject"), calls);
|
assertEquals(Collections.singletonList("getObject"), calls);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void readsBitColumnsAsStoredNumbers() {
|
||||||
|
for (int sqlType : new int[] {Types.BIT, Types.BOOLEAN}) {
|
||||||
|
List<String> calls = new ArrayList<>();
|
||||||
|
ResultSet resultSet = proxy(ResultSet.class, (method, args) -> {
|
||||||
|
if ("getInt".equals(method.getName())) {
|
||||||
|
calls.add("getInt");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (method.getName().startsWith("get")) {
|
||||||
|
calls.add(method.getName());
|
||||||
|
throw new AssertionError("IRIS %Boolean must not be read as a Java boolean");
|
||||||
|
}
|
||||||
|
if ("wasNull".equals(method.getName())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return defaultValue(method.getReturnType());
|
||||||
|
});
|
||||||
|
|
||||||
|
Object value = new IrisAgent().resultValue(resultSet, 1, sqlType);
|
||||||
|
|
||||||
|
assertEquals(1, value);
|
||||||
|
assertEquals(Collections.singletonList("getInt"), calls);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void preservesNullForBitColumns() {
|
||||||
|
ResultSet resultSet = proxy(ResultSet.class, (method, args) -> {
|
||||||
|
if ("getInt".equals(method.getName())) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if ("wasNull".equals(method.getName())) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return defaultValue(method.getReturnType());
|
||||||
|
});
|
||||||
|
|
||||||
|
assertNull(new IrisAgent().resultValue(resultSet, 1, Types.BIT));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void readsColumnsAndUsesInlinePrimaryKey() {
|
void readsColumnsAndUsesInlinePrimaryKey() {
|
||||||
List<String> calls = new ArrayList<>();
|
List<String> calls = new ArrayList<>();
|
||||||
|
|||||||
Reference in new issue
Block a user