|
1 | 1 | /**
|
2 |
| - * Copyright (c) 2009-2013, Data Geekery GmbH (http://www.datageekery.com) |
| 2 | + * Copyright (c) 2009-2014, Data Geekery GmbH (http://www.datageekery.com) |
3 | 3 | * All rights reserved.
|
4 | 4 | *
|
5 | 5 | * This work is dual-licensed
|
|
59 | 59 | // ...
|
60 | 60 | import static org.jooq.impl.DSL.cast;
|
61 | 61 | import static org.jooq.impl.DSL.castNull;
|
| 62 | +import static org.jooq.impl.DSL.concat; |
62 | 63 | import static org.jooq.impl.DSL.count;
|
63 | 64 | import static org.jooq.impl.DSL.decode;
|
64 | 65 | import static org.jooq.impl.DSL.falseCondition;
|
@@ -1343,4 +1344,75 @@ public void testUpdateJoin() throws Exception {
|
1343 | 1344 | assertEquals("ABC", b21.getValue(TBook_TITLE()));
|
1344 | 1345 | assertEquals("ABC", b22.getValue(TBook_TITLE()));
|
1345 | 1346 | }
|
| 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 | + } |
1346 | 1418 | }
|
0 commit comments