googleapis / java-spanner-jdbc

Apache License 2.0
64 stars 48 forks source link

fix: support getShort for DATA_TYPE in TypeInfo #1691

Closed olavloite closed 2 months ago

olavloite commented 3 months ago

The ResultSet that is returned by DatabaseMetadata#getTypeInfo has a column at index 2 with the name DATA_TYPE. This field should contain one of the java.sql.Types constants, or a vendor-specific type code. The JDBC specification states that this column should be a short (although the constants in java.sql.Types are of type int).

Cloud Spanner (at the time of writing) does not support any int16 fields. The type code is therefore returned as an int64. The codes that are used for vendor-specific types by Spanner exceed the max value of a short, and therefore resulted in an OUT_OF_RANGE exception if you tried to call ResultSet#getShort(int) on this column for any of the Spanner-specific types (e.g. JSON).

This change fixes that by adding an additional vendor type code for these types that does fit in a short. This value is returned when getShort(int) is called on the ResultSet.

Fixes #1688