diff --git a/jOOQ/src/main/java/org/jooq/impl/MetaImpl.java b/jOOQ/src/main/java/org/jooq/impl/MetaImpl.java index eb64d424c1..f2323734b5 100644 --- a/jOOQ/src/main/java/org/jooq/impl/MetaImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/MetaImpl.java @@ -125,7 +125,9 @@ import org.jooq.Table; import org.jooq.TableField; import org.jooq.UniqueKey; import org.jooq.exception.DataAccessException; +import org.jooq.exception.DataTypeException; import org.jooq.exception.SQLDialectNotSupportedException; +import org.jooq.tools.JooqLogger; import org.jooq.tools.StringUtils; /** @@ -139,6 +141,7 @@ import org.jooq.tools.StringUtils; final class MetaImpl extends AbstractMeta { private static final long serialVersionUID = 3582980783173033809L; + private static final JooqLogger log = JooqLogger.getLogger(MetaImpl.class); private static final EnumSet INVERSE_SCHEMA_CATALOG = EnumSet.of(MYSQL, MARIADB); private static final EnumSet CURRENT_TIMESTAMP_COLUMN_DEFAULT = EnumSet.of(MYSQL, MARIADB); private static final EnumSet EXPRESSION_COLUMN_DEFAULT = EnumSet.of(H2); @@ -797,17 +800,26 @@ final class MetaImpl extends AbstractMeta { type = type.nullable(false); // [#6883] Default values may be present - if (!StringUtils.isEmpty(defaultValue)) + if (!StringUtils.isEmpty(defaultValue)) { + try { - // [#7194] Some databases report all default values as expressions, not as values - if (EXPRESSION_COLUMN_DEFAULT.contains(configuration.family())) - type = type.defaultValue(DSL.field(defaultValue, type)); + // [#7194] Some databases report all default values as expressions, not as values + if (EXPRESSION_COLUMN_DEFAULT.contains(configuration.family())) + type = type.defaultValue(DSL.field(defaultValue, type)); - // [#5574] MySQL mixes constant value expressions with other column expressions here - else if (CURRENT_TIMESTAMP_COLUMN_DEFAULT.contains(configuration.family()) && "CURRENT_TIMESTAMP".equalsIgnoreCase(defaultValue)) - type = type.defaultValue(DSL.field(defaultValue, type)); - else - type = type.defaultValue(DSL.inline(defaultValue, type)); + // [#5574] MySQL mixes constant value expressions with other column expressions here + else if (CURRENT_TIMESTAMP_COLUMN_DEFAULT.contains(configuration.family()) && "CURRENT_TIMESTAMP".equalsIgnoreCase(defaultValue)) + type = type.defaultValue(DSL.field(defaultValue, type)); + else + type = type.defaultValue(DSL.inline(defaultValue, type)); + } + + // [#8469] Rather than catching exceptions after conversions, we should use the + // parser to parse default values, if they're expressions + catch (DataTypeException e) { + log.warn("Default value", "Could not load default value: " + defaultValue + " for type: " + type, e); + } + } } catch (SQLDialectNotSupportedException e) { type = SQLDataType.OTHER;