[#3455] UPDATE .. FROM statement renders incorrect SQL for derived tables or aliased tables

This commit is contained in:
Lukas Eder 2014-07-25 17:45:07 +02:00
parent 44ac987073
commit acdb108b83
2 changed files with 20 additions and 6 deletions

View File

@ -69,6 +69,7 @@ import static org.jooq.impl.DSL.max;
import static org.jooq.impl.DSL.row;
import static org.jooq.impl.DSL.select;
import static org.jooq.impl.DSL.selectCount;
import static org.jooq.impl.DSL.selectFrom;
import static org.jooq.impl.DSL.selectOne;
import static org.jooq.impl.DSL.tableByName;
import static org.jooq.impl.DSL.trueCondition;
@ -1400,12 +1401,21 @@ extends BaseTest<A, AP, B, S, B2S, BS, L, X, DATE, BOOL, D, T, U, UU, I, IPK, T7
case POSTGRES:
Table<B> b1 = TBook().as("b1");
// [#3455] Ensure also that this works for derived (aliased) tables
Table<A> a1 = selectFrom(TAuthor()).asTable("a1");
assertEquals(4,
create().update(b1)
.set(b1.field(TBook_TITLE()), concat(TAuthor_FIRST_NAME(), inline(" "), TAuthor_LAST_NAME(), inline(": "), TBook_TITLE()))
.from(TBook().join(
TAuthor()).on(TBook_AUTHOR_ID().eq(TAuthor_ID())
.and(TBook_ID().lt(5))))
.set(b1.field(TBook_TITLE()), concat(
a1.field(TAuthor_FIRST_NAME()),
inline(" "),
a1.field(TAuthor_LAST_NAME()),
inline(": "),
TBook_TITLE()
))
.from(TBook().join(a1)
.on(TBook_AUTHOR_ID().eq(a1.field(TAuthor_ID()))
.and(TBook_ID().lt(5))))
.where(TBook_ID().eq(b1.field(TBook_ID())))
.execute());
break;

View File

@ -481,7 +481,9 @@ class UpdateQueryImpl<R extends Record> extends AbstractStoreQuery<R> implements
xx xxxxxxxxxxxxxxxxx x
xxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxx xx
xxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxx
x
xxxxxxxxxxxxxxxxxxxxx
@ -554,7 +556,9 @@ class UpdateQueryImpl<R extends Record> extends AbstractStoreQuery<R> implements
if (!from.isEmpty()) {
ctx.formatSeparator()
.keyword("from").sql(" ")
.visit(from);
.declareTables(true)
.visit(from)
.declareTables(false);
}
ctx.end(UPDATE_FROM);