[jOOQ/jOOQ#17803] Avoid CAST expression in DDL DEFAULT where unsupported
This commit is contained in:
parent
662243d51b
commit
3c80bdb8f7
@ -1236,6 +1236,8 @@ final class Tools {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// XXX: Record constructors and related methods
|
||||
// ------------------------------------------------------------------------
|
||||
@ -5994,26 +5996,36 @@ final class Tools {
|
||||
Field<?> v = type.defaultValue();
|
||||
ctx.sql(' ').visit(K_DEFAULT).sql(' ');
|
||||
|
||||
// [#15943] Some dialects require parentheses around expressions. We can't use AbstractField::parenthesised
|
||||
// as that just declares whether an expression requires additional parentheses in operator
|
||||
// expressions, not if actual parentheses are rendered.
|
||||
if (REQUIRES_PARENTHESISED_DEFAULT.contains(ctx.dialect()))
|
||||
ctx.sql('(').visit(v).sql(')');
|
||||
|
||||
// [#16853] MySQL LOB types can't have defaults. Except if we parenthesise them, then they can o_O
|
||||
else if (REQUIRES_PARENTHESISED_DEFAULT_FOR_LOBS.contains(ctx.dialect()) && (type.isLob() || type.isJSON() || type.isSpatial()))
|
||||
ctx.sql('(').visit(v).sql(')');
|
||||
|
||||
// [#16498] Special cases where the standard datetime literal prefix needs to be omitted
|
||||
// See: https://bugs.mysql.com/bug.php?id=114450
|
||||
else if (NO_SUPPORT_DEFAULT_DATETIME_LITERAL_PREFIX.contains(ctx.dialect()) && type.isDateTime())
|
||||
ctx.data(DATA_OMIT_DATETIME_LITERAL_PREFIX, true, c -> c.visit(v));
|
||||
|
||||
else
|
||||
ctx.visit(v);
|
||||
|
||||
|
||||
|
||||
visitDefault(ctx, type, v);
|
||||
}
|
||||
}
|
||||
|
||||
private static final void visitDefault(Context<?> ctx, DataType<?> type, Field<?> v) {
|
||||
// [#15943] Some dialects require parentheses around expressions. We can't use AbstractField::parenthesised
|
||||
// as that just declares whether an expression requires additional parentheses in operator
|
||||
// expressions, not if actual parentheses are rendered.
|
||||
if (REQUIRES_PARENTHESISED_DEFAULT.contains(ctx.dialect()))
|
||||
ctx.sql('(').visit(v).sql(')');
|
||||
|
||||
// [#16853] MySQL LOB types can't have defaults. Except if we parenthesise them, then they can o_O
|
||||
else if (REQUIRES_PARENTHESISED_DEFAULT_FOR_LOBS.contains(ctx.dialect()) && (type.isLob() || type.isJSON() || type.isSpatial()))
|
||||
ctx.sql('(').visit(v).sql(')');
|
||||
|
||||
// [#16498] Special cases where the standard datetime literal prefix needs to be omitted
|
||||
// See: https://bugs.mysql.com/bug.php?id=114450
|
||||
else if (NO_SUPPORT_DEFAULT_DATETIME_LITERAL_PREFIX.contains(ctx.dialect()) && type.isDateTime())
|
||||
ctx.data(DATA_OMIT_DATETIME_LITERAL_PREFIX, true, c -> c.visit(v));
|
||||
|
||||
else
|
||||
ctx.visit(v);
|
||||
}
|
||||
|
||||
static final void toSQLDDLTypeDeclaration(Context<?> ctx, DataType<?> type) {
|
||||
// [#10376] TODO: Move some of this logic into DataType
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user