diff --git a/jOOQ/src/main/java/org/jooq/impl/MetaImpl.java b/jOOQ/src/main/java/org/jooq/impl/MetaImpl.java index 7d417d47f9..0a93ea2bd0 100644 --- a/jOOQ/src/main/java/org/jooq/impl/MetaImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/MetaImpl.java @@ -41,6 +41,8 @@ package org.jooq.impl; // ... // ... import static org.jooq.SQLDialect.H2; +import static org.jooq.SQLDialect.HSQLDB; +// ... import static org.jooq.SQLDialect.MARIADB; // ... import static org.jooq.SQLDialect.MYSQL; @@ -111,6 +113,8 @@ final class MetaImpl extends AbstractMeta { private static final Set INVERSE_SCHEMA_CATALOG = SQLDialect.supportedBy(MARIADB, MYSQL); private static final Set CURRENT_TIMESTAMP_COLUMN_DEFAULT = SQLDialect.supportedBy(MARIADB, MYSQL); private static final Set EXPRESSION_COLUMN_DEFAULT = SQLDialect.supportedBy(H2); + private static final Set ENCODED_TIMESTAMP_PRECISION = SQLDialect.supportedBy(HSQLDB, MARIADB); + private static final Set NO_SUPPORT_TIMESTAMP_PRECISION = SQLDialect.supportedBy(MYSQL, SQLITE); @@ -843,7 +847,6 @@ final class MetaImpl extends AbstractMeta { String typeName = column.get(5, String.class); // TYPE_NAME int precision = column.get(6, int.class); // COLUMN_SIZE int scale = column.get(8, int.class); // DECIMAL_DIGITS - Integer nullableScale = column.get(8, Integer.class); // DECIMAL_DIGITS int nullable = column.get(10, int.class); // NULLABLE String remarks = column.get(11, String.class); // REMARKS String defaultValue = column.get(12, String.class); // COLUMN_DEF @@ -865,9 +868,11 @@ final class MetaImpl extends AbstractMeta { if (type.hasPrecision() && type.hasScale()) type = type.precision(precision, scale); - // [#9590] Timestamp precision is in the scale column + // [#9590] Timestamp precision is in the scale column in some dialects else if (type.hasPrecision() && type.isDateTime()) { - if (nullableScale != null) + if (ENCODED_TIMESTAMP_PRECISION.contains(dialect())) + type = type.precision(decodeTimestampPrecision(precision)); + else if (!NO_SUPPORT_TIMESTAMP_PRECISION.contains(dialect())) type = type.precision(scale); } else if (type.hasPrecision()) @@ -915,6 +920,12 @@ final class MetaImpl extends AbstractMeta { createField(name(columnName), type, this, remarks); } } + + private final int decodeTimestampPrecision(int precision) { + + // [#9590] Discovered empirically from COLUMN_SIZE + return Math.max(0, precision - 20); + } } private final class MetaPrimaryKey extends AbstractKey implements UniqueKey {