[#2464] Bad SQL rendered from DELETE statements with aliased tables

This commit is contained in:
Lukas Eder 2013-05-22 21:12:05 +02:00
parent c958209a9d
commit d1458dfea4
3 changed files with 23 additions and 1 deletions

View File

@ -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())));
}
}

View File

@ -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();

View File

@ -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()