Fix broken DatabaseMetaData.getColumns() on older server versions #182
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
On older versions of MariaDB and MySQL, DatabaseMetaData.getColumns() will fail with the error
Unknown column 'DATETIME_PRECISION' in 'field list'. This is due to theDATETIME_PRECISIONcolumn not being present in theINFORMATION_SCHEMA.COLUMNStable. This column was introduced as part of the introduction of microsecond precision in TIME/DATETIME/TIMESTAMP types, in MariaDB 5.3.0 (I believe) and MySQL 5.6.4.The proposed fix adjusts the metadata query for the relevant older server versions. The fixed behavior in these cases is as if the DATETIME_PRECISION field had a value of 0, which is consistent with the fact that these older database versions did not support any fractional seconds digits.
Similar conditional logic already exist in the MySQL project's JDBC driver.
(This bug was reported by a user of Ultorg, a graphical database client. To test the modified MariaDB JDBC driver, I ran Ultorg's integration test suite with it while connecting to MariaDB 10.6.11, MySQL 5.5.62, and MySQL 8.0.26.)