Skip to content

Commit d5bf671

Browse files
committed
[jOOQ#1018] Add support for PostgreSQL and SQL Server non-standard UPDATE .. FROM clause
1 parent 7507fb0 commit d5bf671

File tree

9 files changed

+3553
-3210
lines changed

9 files changed

+3553
-3210
lines changed

jOOQ-test/src/org/jooq/test/_/testcases/InsertUpdateTests.java

+73-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright (c) 2009-2013, Data Geekery GmbH (http://www.datageekery.com)
2+
* Copyright (c) 2009-2014, Data Geekery GmbH (http://www.datageekery.com)
33
* All rights reserved.
44
*
55
* This work is dual-licensed
@@ -59,6 +59,7 @@
5959
// ...
6060
import static org.jooq.impl.DSL.cast;
6161
import static org.jooq.impl.DSL.castNull;
62+
import static org.jooq.impl.DSL.concat;
6263
import static org.jooq.impl.DSL.count;
6364
import static org.jooq.impl.DSL.decode;
6465
import static org.jooq.impl.DSL.falseCondition;
@@ -1343,4 +1344,75 @@ public void testUpdateJoin() throws Exception {
13431344
assertEquals("ABC", b21.getValue(TBook_TITLE()));
13441345
assertEquals("ABC", b22.getValue(TBook_TITLE()));
13451346
}
1347+
1348+
@Test
1349+
public void testUpdateFrom() throws Exception {
1350+
switch (dialect().family()) {
1351+
/* [pro] xx
1352+
xxxx xxxxxxx
1353+
xxxx xxxx
1354+
xxxx xxxxxxx
1355+
xx [/pro] */
1356+
1357+
case CUBRID:
1358+
case DERBY:
1359+
case FIREBIRD:
1360+
case H2:
1361+
case HSQLDB:
1362+
case MARIADB:
1363+
case MYSQL:
1364+
case SQLITE:
1365+
log.info("SKIPPING", "UPDATE .. FROM integration test. This syntax is not supported by " + dialect());
1366+
return;
1367+
}
1368+
1369+
jOOQAbstractTest.reset = false;
1370+
1371+
switch (dialect().family()) {
1372+
/* [pro] xx
1373+
xx xxxxxx xxx xxx xxxxxxx xxxxxxxxxxxxx xx xxxx xxxx xxxxxxx
1374+
xxxx xxxxxxx
1375+
xx [/pro] */
1376+
1377+
case POSTGRES:
1378+
Table<B> b1 = TBook().as("b1");
1379+
1380+
assertEquals(4,
1381+
create().update(b1)
1382+
.set(b1.field(TBook_TITLE()), concat(TAuthor_FIRST_NAME(), inline(" "), TAuthor_LAST_NAME(), inline(": "), TBook_TITLE()))
1383+
.from(TBook().join(
1384+
TAuthor()).on(TBook_AUTHOR_ID().eq(TAuthor_ID())
1385+
.and(TBook_ID().lt(5))))
1386+
.where(TBook_ID().eq(b1.field(TBook_ID())))
1387+
.execute());
1388+
break;
1389+
1390+
/* [pro] xx
1391+
xxxx xxxxxxxxxx
1392+
xxxx xxxxxxx
1393+
xx [/pro] */
1394+
1395+
default:
1396+
assertEquals(4,
1397+
create().update(TBook())
1398+
.set(TBook_TITLE(), concat(TAuthor_FIRST_NAME(), inline(" "), TAuthor_LAST_NAME(), inline(": "), TBook_TITLE()))
1399+
.from(TBook().join(
1400+
TAuthor()).on(TBook_AUTHOR_ID().eq(TAuthor_ID())
1401+
.and(TBook_ID().lt(5))))
1402+
.execute());
1403+
1404+
break;
1405+
}
1406+
1407+
Result<B> result =
1408+
create().selectFrom(TBook())
1409+
.orderBy(TBook_ID())
1410+
.fetch();
1411+
1412+
assertEquals(BOOK_AUTHOR_IDS, result.getValues(TBook_AUTHOR_ID()));
1413+
assertEquals(AUTHOR_FIRST_NAMES.get(0) + " " + AUTHOR_LAST_NAMES.get(0) + ": " + BOOK_TITLES.get(0), result.get(0).getValue(TBook_TITLE()));
1414+
assertEquals(AUTHOR_FIRST_NAMES.get(0) + " " + AUTHOR_LAST_NAMES.get(0) + ": " + BOOK_TITLES.get(1), result.get(1).getValue(TBook_TITLE()));
1415+
assertEquals(AUTHOR_FIRST_NAMES.get(1) + " " + AUTHOR_LAST_NAMES.get(1) + ": " + BOOK_TITLES.get(2), result.get(2).getValue(TBook_TITLE()));
1416+
assertEquals(AUTHOR_FIRST_NAMES.get(1) + " " + AUTHOR_LAST_NAMES.get(1) + ": " + BOOK_TITLES.get(3), result.get(3).getValue(TBook_TITLE()));
1417+
}
13461418
}

jOOQ-test/src/org/jooq/test/jOOQAbstractTest.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright (c) 2009-2013, Data Geekery GmbH (http://www.datageekery.com)
2+
* Copyright (c) 2009-2014, Data Geekery GmbH (http://www.datageekery.com)
33
* All rights reserved.
44
*
55
* This work is dual-licensed
@@ -1701,6 +1701,11 @@ public void testUpdateJoin() throws Exception {
17011701
new InsertUpdateTests(this).testUpdateJoin();
17021702
}
17031703

1704+
@Test
1705+
public void testUpdateFrom() throws Exception {
1706+
new InsertUpdateTests(this).testUpdateFrom();
1707+
}
1708+
17041709
@Test
17051710
public void testInsertOnDuplicateKeyUpdate() throws Exception {
17061711
new InsertUpdateTests(this).testInsertOnDuplicateKeyUpdate();

0 commit comments

Comments
 (0)