[jOOQ/jOOQ#19004] Adding a DDL comment to aliased columns produces wrong SQL, or does not maintain comment after execution

This commit is contained in:
Lukas Eder 2025-09-08 13:53:52 +02:00
parent 6bc46e6645
commit 595676a2fb
2 changed files with 15 additions and 5 deletions

View File

@ -253,8 +253,8 @@ implements
@SuppressWarnings("unchecked")
@Override
public Field<T> as(Name alias) {
return new FieldAlias<>((Field<T>) (this instanceof Condition c ? DSL.field(c) : this), alias);
public /* non-final */ Field<T> as(Name alias) {
return new FieldAlias<>((Field<T>) (this instanceof Condition c ? DSL.field(c) : this), alias, getCommentPart());
}
@Override
@ -277,7 +277,7 @@ implements
}
@Override
public final Field<T> comment(Comment comment) {
public /* non-final */ Field<T> comment(Comment comment) {
return DSL.field(getQualifiedName(), getDataType(), comment);
}

View File

@ -41,6 +41,7 @@ package org.jooq.impl;
import java.util.Objects;
import org.jooq.Clause;
import org.jooq.Comment;
import org.jooq.Context;
import org.jooq.Field;
import org.jooq.Name;
@ -65,7 +66,11 @@ implements
private final Alias<Field<T>> alias;
FieldAlias(Field<T> field, Name alias) {
super(alias, field.getDataType());
this(field, alias, null);
}
FieldAlias(Field<T> field, Name alias, Comment comment) {
super(alias, field.getDataType(), comment);
this.alias = new Alias<>(field, this, alias);
}
@ -87,7 +92,12 @@ implements
@Override
public final Field<T> as(Name as) {
return alias.wrapped().as(as);
return new FieldAlias<>(alias.wrapped(), as, getCommentPart());
}
@Override
public final Field<T> comment(Comment comment) {
return new FieldAlias<>(alias.wrapped(), alias.alias, comment);
}
@Override