[#8328] { UPDATE | DELETE } .. LIMIT isn't emulated correctly in the absence of unique key meta information
This commit is contained in:
parent
4b9c055784
commit
4c3efa0cec
@ -84,14 +84,13 @@ import org.jooq.Condition;
|
||||
import org.jooq.Configuration;
|
||||
import org.jooq.Context;
|
||||
import org.jooq.DeleteQuery;
|
||||
import org.jooq.Field;
|
||||
import org.jooq.Operator;
|
||||
import org.jooq.OrderField;
|
||||
import org.jooq.Param;
|
||||
import org.jooq.Record;
|
||||
import org.jooq.SQLDialect;
|
||||
import org.jooq.Table;
|
||||
import org.jooq.TableField;
|
||||
import org.jooq.UniqueKey;
|
||||
|
||||
/**
|
||||
* @author Lukas Eder
|
||||
@ -172,6 +171,7 @@ final class DeleteQueryImpl<R extends Record> extends AbstractDMLQuery<R> implem
|
||||
limit = numberOfRows;
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
@Override
|
||||
final void accept0(Context<?> ctx) {
|
||||
boolean declare = ctx.declareTables();
|
||||
@ -195,18 +195,20 @@ final class DeleteQueryImpl<R extends Record> extends AbstractDMLQuery<R> implem
|
||||
.declareTables(declare)
|
||||
.end(DELETE_DELETE);
|
||||
|
||||
if (limit != null && NO_SUPPORT_LIMIT.contains(ctx.family()) && !table().getKeys().isEmpty()) {
|
||||
UniqueKey<?> key = table().getPrimaryKey() != null ? table().getPrimaryKey() : table().getKeys().get(0);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
TableField<?, Object>[] keyFields = (TableField<?, Object>[]) key.getFieldsArray();
|
||||
if (limit != null && NO_SUPPORT_LIMIT.contains(ctx.family())) {
|
||||
Field<?>[] keyFields =
|
||||
table().getKeys().isEmpty()
|
||||
? new Field[] { table().rowid() }
|
||||
: (table().getPrimaryKey() != null
|
||||
? table().getPrimaryKey()
|
||||
: table().getKeys().get(0)).getFieldsArray();
|
||||
|
||||
ctx.start(DELETE_WHERE)
|
||||
.formatSeparator()
|
||||
.visit(K_WHERE).sql(' ');
|
||||
|
||||
if (keyFields.length == 1)
|
||||
ctx.visit(keyFields[0].in(select(keyFields[0]).from(table()).where(getWhere()).orderBy(orderBy).limit(limit)));
|
||||
ctx.visit(keyFields[0].in(select((Field) keyFields[0]).from(table()).where(getWhere()).orderBy(orderBy).limit(limit)));
|
||||
else
|
||||
ctx.visit(row(keyFields).in(select(keyFields).from(table()).where(getWhere()).orderBy(orderBy).limit(limit)));
|
||||
|
||||
|
||||
@ -142,9 +142,7 @@ import org.jooq.RowN;
|
||||
import org.jooq.SQLDialect;
|
||||
import org.jooq.Select;
|
||||
import org.jooq.Table;
|
||||
import org.jooq.TableField;
|
||||
import org.jooq.TableLike;
|
||||
import org.jooq.UniqueKey;
|
||||
import org.jooq.UpdateQuery;
|
||||
|
||||
/**
|
||||
@ -507,6 +505,7 @@ final class UpdateQueryImpl<R extends Record> extends AbstractStoreQuery<R> impl
|
||||
return condition.hasWhere();
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
@Override
|
||||
final void accept0(Context<?> ctx) {
|
||||
boolean declareTables = ctx.declareTables();
|
||||
@ -645,18 +644,20 @@ final class UpdateQueryImpl<R extends Record> extends AbstractStoreQuery<R> impl
|
||||
break;
|
||||
}
|
||||
|
||||
if (limit != null && NO_SUPPORT_LIMIT.contains(ctx.family()) && !table().getKeys().isEmpty()) {
|
||||
UniqueKey<?> key = table().getPrimaryKey() != null ? table().getPrimaryKey() : table().getKeys().get(0);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
TableField<?, Object>[] keyFields = (TableField<?, Object>[]) key.getFieldsArray();
|
||||
if (limit != null && NO_SUPPORT_LIMIT.contains(ctx.family())) {
|
||||
Field<?>[] keyFields =
|
||||
table().getKeys().isEmpty()
|
||||
? new Field[] { table().rowid() }
|
||||
: (table().getPrimaryKey() != null
|
||||
? table().getPrimaryKey()
|
||||
: table().getKeys().get(0)).getFieldsArray();
|
||||
|
||||
ctx.start(UPDATE_WHERE)
|
||||
.formatSeparator()
|
||||
.visit(K_WHERE).sql(' ');
|
||||
|
||||
if (keyFields.length == 1)
|
||||
ctx.visit(keyFields[0].in(select(keyFields[0]).from(table()).where(getWhere()).orderBy(orderBy).limit(limit)));
|
||||
ctx.visit(keyFields[0].in(select((Field) keyFields[0]).from(table()).where(getWhere()).orderBy(orderBy).limit(limit)));
|
||||
else
|
||||
ctx.visit(row(keyFields).in(select(keyFields).from(table()).where(getWhere()).orderBy(orderBy).limit(limit)));
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user