[jOOQ/jOOQ#10052] Added parser support for MERGE .. DELETE WHERE
This commit is contained in:
parent
651af3bbea
commit
8407d26bc8
@ -98,7 +98,7 @@ public interface MergeMatchedDeleteStep<R extends Record> extends MergeMatchedSt
|
||||
* htm</a> for a full definition of the Oracle <code>MERGE</code> statement
|
||||
*/
|
||||
@Support({ DERBY, FIREBIRD, H2, HSQLDB })
|
||||
MergeNotMatchedStep<R> deleteWhere(Condition condition);
|
||||
MergeMatchedStep<R> deleteWhere(Condition condition);
|
||||
|
||||
/**
|
||||
* Add an additional <code>DELETE WHERE</code> clause to the preceding
|
||||
@ -110,7 +110,7 @@ public interface MergeMatchedDeleteStep<R extends Record> extends MergeMatchedSt
|
||||
* htm</a> for a full definition of the Oracle <code>MERGE</code> statement
|
||||
*/
|
||||
@Support({ DERBY, FIREBIRD, H2, HSQLDB })
|
||||
MergeNotMatchedStep<R> deleteWhere(Field<Boolean> condition);
|
||||
MergeMatchedStep<R> deleteWhere(Field<Boolean> condition);
|
||||
|
||||
/**
|
||||
* Add an additional <code>DELETE WHERE</code> clause to the preceding
|
||||
@ -132,5 +132,5 @@ public interface MergeMatchedDeleteStep<R extends Record> extends MergeMatchedSt
|
||||
*/
|
||||
@Deprecated
|
||||
@Support({ DERBY, FIREBIRD, H2, HSQLDB })
|
||||
MergeNotMatchedStep<R> deleteWhere(Boolean condition);
|
||||
MergeMatchedStep<R> deleteWhere(Boolean condition);
|
||||
}
|
||||
|
||||
@ -456,7 +456,9 @@ import org.jooq.LikeEscapeStep;
|
||||
// ...
|
||||
import org.jooq.Merge;
|
||||
import org.jooq.MergeFinalStep;
|
||||
import org.jooq.MergeMatchedDeleteStep;
|
||||
import org.jooq.MergeMatchedStep;
|
||||
import org.jooq.MergeMatchedWhereStep;
|
||||
import org.jooq.MergeUsingStep;
|
||||
import org.jooq.Meta;
|
||||
import org.jooq.Name;
|
||||
@ -2048,6 +2050,7 @@ final class ParserImpl implements Parser {
|
||||
Map<Field<?>, Object> updateSet = null;
|
||||
Condition updateAnd = null;
|
||||
Condition updateWhere = null;
|
||||
Condition deleteWhere = null;
|
||||
|
||||
MergeUsingStep<?> s1 = (with == null ? ctx.dsl.mergeInto(target) : with.mergeInto(target));
|
||||
MergeMatchedStep<?> s2 = s1.using(usingTable).on(on);
|
||||
@ -2071,11 +2074,17 @@ final class ParserImpl implements Parser {
|
||||
if (updateAnd == null && parseKeywordIf(ctx, "WHERE"))
|
||||
updateWhere = parseCondition(ctx);
|
||||
|
||||
s2 = updateAnd != null
|
||||
? s2.whenMatchedAnd(updateAnd).thenUpdate().set(updateSet)
|
||||
: updateWhere != null
|
||||
? s2.whenMatchedThenUpdate().set(updateSet).where(updateWhere)
|
||||
: s2.whenMatchedThenUpdate().set(updateSet);
|
||||
if (updateAnd == null && parseKeywordIf(ctx, "DELETE WHERE"))
|
||||
deleteWhere = parseCondition(ctx);
|
||||
|
||||
if (updateAnd != null) {
|
||||
s2.whenMatchedAnd(updateAnd).thenUpdate().set(updateSet);
|
||||
}
|
||||
else {
|
||||
MergeMatchedWhereStep<?> s3 = s2.whenMatchedThenUpdate().set(updateSet);
|
||||
MergeMatchedDeleteStep<?> s4 = updateWhere != null ? s3.where(updateWhere) : s3;
|
||||
s2 = deleteWhere != null ? s4.deleteWhere(deleteWhere) : s3;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (!insert && (insert = parseKeywordIf(ctx, "WHEN NOT MATCHED"))) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user