[#8468] DataTypeException when org.jooq.Meta accesses PostgreSQL array column with default expression

This commit is contained in:
lukaseder 2019-03-29 16:03:41 +01:00
parent d21a6877ce
commit 3dcba4ea21

View File

@ -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<SQLDialect> INVERSE_SCHEMA_CATALOG = EnumSet.of(MYSQL, MARIADB);
private static final EnumSet<SQLDialect> CURRENT_TIMESTAMP_COLUMN_DEFAULT = EnumSet.of(MYSQL, MARIADB);
private static final EnumSet<SQLDialect> 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;