getExpectedJdbcType

open override fun getExpectedJdbcType(tableColumnMetadata: TableColumnMetadata): KType

MSSQL-specific deviations from the default type mapping, all of them cases where the default mapping and the values ResultSet.getObject returns disagreed (see #2087):

  • DATETIMEOFFSET is reported with the driver-specific JDBC type -155 and microsoft.sql.DateTimeOffset as its column class, which the default mapping has no entry for, so it fell back to String while the driver returned a DateTimeOffset. It is read as OffsetDateTime: a JDK type that keeps the UTC offset of the value, and the one the default mapping already uses for java.sql.Types.TIMESTAMP_WITH_TIMEZONE. The driver produces it directly, see getValueFromResultSet.

  • Any column the driver reports java.lang.Short for is read as Short, because that is what it then returns, while the default mapping declared it Int. Under MSSQL those columns are SMALLINT and TINYINT; Short is also the smallest Kotlin type that fits MSSQL's TINYINT, which — unlike in most databases — is unsigned (0..255) and so does not fit a Byte. This branch deliberately keys on the reported column class and not on TableColumnMetadata.jdbcType: H2 in MSSQL mode delegates its mapping here, and its SMALLINT is reported as java.sql.Types.SMALLINT too but comes back as an Integer, so keying on the JDBC type would type that column Short and make reading it throw.

  • SQL_VARIANT holds a value of any base type, and the class of that value differs from row to row (an Int for CAST(1 AS SQL_VARIANT), a String for a string), so the column can only honestly be typed Any. The default mapping declared it String.