[jOOQ/jOOQ#14194] Bad syntax generated when using the Field.collate()

clause in CREATE TABLE statements
This commit is contained in:
Lukas Eder 2022-11-10 10:44:01 +01:00
parent 7c6ab54867
commit 8b9b37e65d
4 changed files with 12 additions and 4 deletions

View File

@ -1299,7 +1299,7 @@ implements
}
TableElement part = add.get(i);
ctx.qualify(false, c -> c.visit(part));
ctx.qualify(false, c -> c.visit(Tools.uncollate(part)));
if (part instanceof Field<?> f) {
ctx.sql(' ');
@ -1329,7 +1329,7 @@ implements
ctx.qualify(false, c -> c.visit(addColumn)).sql(' ');
ctx.qualify(false, c -> c.visit(Tools.uncollate(addColumn))).sql(' ');
toSQLDDLTypeDeclarationForAddition(ctx, addColumnType);

View File

@ -61,7 +61,7 @@ final class Collated extends AbstractField<String> implements QOM.Collated {
private final Collation collation;
Collated(Field<?> field, Collation collation) {
super(field.getQualifiedName(), type(field), field.getCommentPart(), binding(field));
super(field.getQualifiedName(), type(field).collation(collation), field.getCommentPart(), binding(field));
this.field = field;
this.collation = collation;

View File

@ -503,7 +503,7 @@ implements
if (!first)
ctx.sql(',').formatSeparator();
ctx.visit(field);
ctx.visit(Tools.uncollate(field));
if (select == null) {
ctx.sql(' ');

View File

@ -316,6 +316,7 @@ import org.jooq.SelectFieldOrAsterisk;
import org.jooq.SortField;
import org.jooq.Source;
import org.jooq.Table;
import org.jooq.TableElement;
import org.jooq.TableField;
import org.jooq.TableRecord;
import org.jooq.UDT;
@ -6058,6 +6059,13 @@ final class Tools {
return result != null ? result : table;
}
static final TableElement uncollate(TableElement field) {
if (field instanceof QOM.Collated c)
return uncollate(c.$field());
else
return field;
}
static final boolean isScalarSubquery(Field<?> field) {
// TODO: Replace other instanceof checks by this one
return uncoerce(field) instanceof ScalarSubquery;