Skip to content
This repository was archived by the owner on Mar 26, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/main/java/com/google/cloud/spanner/jdbc/JdbcResultSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,9 @@ public byte getByte(int columnIndex) throws SQLException {
case ENUM:
return isNull ? (byte) 0 : checkedCastToByte(spanner.getLong(spannerIndex));
case NUMERIC:
return isNull ? (byte) 0 : checkedCastToByte(spanner.getBigDecimal(spannerIndex));
return isNull
? (byte) 0
: checkedCastToByte(spanner.getBigDecimal(spannerIndex).toBigInteger());
case PG_NUMERIC:
return isNull
? (byte) 0
Expand Down Expand Up @@ -354,7 +356,9 @@ public short getShort(int columnIndex) throws SQLException {
}
return isNull ? 0 : checkedCastToShort(spanner.getLong(spannerIndex));
case NUMERIC:
return isNull ? 0 : checkedCastToShort(spanner.getBigDecimal(spannerIndex));
return isNull
? (short) 0
: checkedCastToShort(spanner.getBigDecimal(spannerIndex).toBigInteger());
case PG_NUMERIC:
return isNull
? 0
Expand Down Expand Up @@ -395,7 +399,7 @@ public int getInt(int columnIndex) throws SQLException {
case ENUM:
return isNull ? 0 : checkedCastToInt(spanner.getLong(spannerIndex));
case NUMERIC:
return isNull ? 0 : checkedCastToInt(spanner.getBigDecimal(spannerIndex));
return isNull ? 0 : checkedCastToInt(spanner.getBigDecimal(spannerIndex).toBigInteger());
case PG_NUMERIC:
return isNull
? 0
Expand Down Expand Up @@ -432,7 +436,7 @@ public long getLong(int columnIndex) throws SQLException {
case ENUM:
return isNull ? 0L : spanner.getLong(spannerIndex);
case NUMERIC:
return isNull ? 0 : checkedCastToLong(parseBigDecimal(spanner.getString(spannerIndex)));
return isNull ? 0L : checkedCastToLong(spanner.getBigDecimal(spannerIndex).toBigInteger());
case PG_NUMERIC:
return isNull
? 0L
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,46 +116,65 @@ static Object convert(Object value, Type type, Class<?> targetType) throws SQLEx
}
if (type.getCode() == Code.FLOAT64) return (Double) value != 0d;
if (type.getCode() == Code.NUMERIC) return !value.equals(BigDecimal.ZERO);
if (type.getCode() == Code.PG_NUMERIC)
return !AbstractJdbcWrapper.parseBigDecimal((String) value).equals(BigDecimal.ZERO);
}
if (targetType.equals(BigDecimal.class)) {
if (type.getCode() == Code.BOOL) return (Boolean) value ? BigDecimal.ONE : BigDecimal.ZERO;
if (type.getCode() == Code.INT64 || type.getCode() == Code.ENUM)
return BigDecimal.valueOf((Long) value);
if (type.getCode() == Code.NUMERIC) return value;
if (type.getCode() == Code.PG_NUMERIC)
return AbstractJdbcWrapper.parseBigDecimal((String) value);
}
if (targetType.equals(Long.class)) {
if (type.getCode() == Code.BOOL) return (Boolean) value ? 1L : 0L;
if (type.getCode() == Code.INT64 || type.getCode() == Code.ENUM) return value;
if (type.getCode() == Code.NUMERIC)
return AbstractJdbcWrapper.checkedCastToLong((BigDecimal) value);
return AbstractJdbcWrapper.checkedCastToLong(((BigDecimal) value).toBigInteger());
if (type.getCode() == Code.PG_NUMERIC)
return AbstractJdbcWrapper.checkedCastToLong(
AbstractJdbcWrapper.parseBigDecimal((String) value).toBigInteger());
}
if (targetType.equals(Integer.class)) {
if (type.getCode() == Code.BOOL) return (Boolean) value ? 1 : 0;
if (type.getCode() == Code.INT64 || type.getCode() == Code.ENUM)
return AbstractJdbcWrapper.checkedCastToInt((Long) value);
if (type.getCode() == Code.NUMERIC)
return AbstractJdbcWrapper.checkedCastToInt((BigDecimal) value);
return AbstractJdbcWrapper.checkedCastToInt(((BigDecimal) value).toBigInteger());
if (type.getCode() == Code.PG_NUMERIC)
return AbstractJdbcWrapper.checkedCastToInt(
AbstractJdbcWrapper.parseBigDecimal((String) value).toBigInteger());
}
if (targetType.equals(Short.class)) {
if (type.getCode() == Code.BOOL) return (Boolean) value ? 1 : 0;
if (type.getCode() == Code.INT64 || type.getCode() == Code.ENUM)
return AbstractJdbcWrapper.checkedCastToShort((Long) value);
if (type.getCode() == Code.NUMERIC)
return AbstractJdbcWrapper.checkedCastToShort((BigDecimal) value);
return AbstractJdbcWrapper.checkedCastToShort(((BigDecimal) value).toBigInteger());
if (type.getCode() == Code.PG_NUMERIC)
return AbstractJdbcWrapper.checkedCastToShort(
AbstractJdbcWrapper.parseBigDecimal((String) value).toBigInteger());
}
if (targetType.equals(Byte.class)) {
if (type.getCode() == Code.BOOL) return (Boolean) value ? 1 : 0;
if (type.getCode() == Code.INT64 || type.getCode() == Code.ENUM)
return AbstractJdbcWrapper.checkedCastToByte((Long) value);
if (type.getCode() == Code.NUMERIC)
return AbstractJdbcWrapper.checkedCastToByte((BigDecimal) value);
return AbstractJdbcWrapper.checkedCastToByte(((BigDecimal) value).toBigInteger());
if (type.getCode() == Code.PG_NUMERIC)
return AbstractJdbcWrapper.checkedCastToByte(
AbstractJdbcWrapper.parseBigDecimal((String) value).toBigInteger());
}
if (targetType.equals(BigInteger.class)) {
if (type.getCode() == Code.BOOL) return (Boolean) value ? BigInteger.ONE : BigInteger.ZERO;
if (type.getCode() == Code.INT64 || type.getCode() == Code.ENUM)
return BigInteger.valueOf((Long) value);
if (type.getCode() == Code.NUMERIC)
return AbstractJdbcWrapper.checkedCastToBigInteger((BigDecimal) value);
if (type.getCode() == Code.PG_NUMERIC)
return AbstractJdbcWrapper.checkedCastToBigInteger(
AbstractJdbcWrapper.parseBigDecimal((String) value));
}
if (targetType.equals(Float.class)) {
if (type.getCode() == Code.BOOL)
Expand All @@ -166,6 +185,8 @@ static Object convert(Object value, Type type, Class<?> targetType) throws SQLEx
if (type.getCode() == Code.FLOAT64)
return AbstractJdbcWrapper.checkedCastToFloat((Double) value);
if (type.getCode() == Code.NUMERIC) return ((BigDecimal) value).floatValue();
if (type.getCode() == Code.PG_NUMERIC)
return AbstractJdbcWrapper.parseFloat((String) value);
}
if (targetType.equals(Double.class)) {
if (type.getCode() == Code.BOOL)
Expand All @@ -174,6 +195,8 @@ static Object convert(Object value, Type type, Class<?> targetType) throws SQLEx
return value;
}
if (type.getCode() == Code.NUMERIC) return ((BigDecimal) value).doubleValue();
if (type.getCode() == Code.PG_NUMERIC)
return AbstractJdbcWrapper.parseDouble((String) value);
}
if (targetType.equals(java.sql.Date.class)) {
if (type.getCode() == Code.DATE) return value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public static void startEmulator() {
new GenericContainer<>(
DockerImageName.parse("gcr.io/cloud-spanner-emulator/emulator:latest"))
.withExposedPorts(9010)
.waitingFor(Wait.forListeningPorts(9010));
.waitingFor(Wait.forLogMessage(".*gRPC server listening at.*\\n", 1));
emulator.start();
properties = new Properties();
properties.setProperty("autoConfigEmulator", "true");
Expand Down
Loading
Loading