[#2464] Bad SQL rendered from DELETE statements with aliased tables
This commit is contained in:
parent
c958209a9d
commit
d1458dfea4
@ -38,6 +38,7 @@ package org.jooq.test._.testcases;
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static junit.framework.Assert.assertNull;
|
||||
import static org.jooq.impl.DSL.select;
|
||||
import static org.jooq.impl.DSL.selectFrom;
|
||||
import static org.jooq.impl.DSL.selectOne;
|
||||
import static org.jooq.impl.DSL.selectZero;
|
||||
import static org.jooq.impl.DSL.table;
|
||||
@ -189,4 +190,16 @@ extends BaseTest<A, AP, B, S, B2S, BS, L, X, DATE, BOOL, D, T, U, UU, I, IPK, T7
|
||||
assertEquals(0, r1.getValue("b"));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAliasingDelete() throws Exception {
|
||||
jOOQAbstractTest.reset = false;
|
||||
Table<B2S> b = TBookToBookStore().as("b");
|
||||
|
||||
assertEquals(2, create().delete(b).where(b.field(TBookToBookStore_BOOK_ID()).eq(1)).execute());
|
||||
assertEquals(4, create().fetchCount(selectFrom(TBookToBookStore())));
|
||||
|
||||
assertEquals(4, create().delete(b).execute());
|
||||
assertEquals(0, create().fetchCount(selectFrom(TBookToBookStore())));
|
||||
}
|
||||
}
|
||||
|
||||
@ -1800,6 +1800,11 @@ public abstract class jOOQAbstractTest<
|
||||
new AliasTests(this).testAliasingJoins();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAliasingDelete() throws Exception {
|
||||
new AliasTests(this).testAliasingDelete();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAliasingPivot() throws Exception {
|
||||
new ExoticTests(this).testAliasingPivot();
|
||||
|
||||
@ -99,8 +99,12 @@ class DeleteQueryImpl<R extends Record> extends AbstractQuery implements DeleteQ
|
||||
|
||||
@Override
|
||||
public final void toSQL(RenderContext context) {
|
||||
boolean declare = context.declareTables();
|
||||
|
||||
context.keyword("delete from ");
|
||||
context.sql(getFrom());
|
||||
context.declareTables(true)
|
||||
.sql(getFrom())
|
||||
.declareTables(declare);
|
||||
|
||||
if (!(getWhere() instanceof TrueCondition)) {
|
||||
context.formatSeparator()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user