@@ -421,6 +421,89 @@ class CanonicalSpringKotlinTest {
421
421
assertThat(occupation).isEqualTo(" Brontosaurus Operator" )
422
422
assertThat(addressId).isEqualTo(1 )
423
423
}
424
+
425
+ with (records[2 ]!! ) {
426
+ assertThat(id).isEqualTo(3 )
427
+ assertThat(firstName).isEqualTo(" Pebbles" )
428
+ assertThat(lastName).isEqualTo(" Flintstone" )
429
+ assertThat(birthDate).isNotNull()
430
+ assertThat(employed).isEqualTo(" No" )
431
+ assertThat(occupation).isNull()
432
+ assertThat(addressId).isEqualTo(1 )
433
+ }
434
+ }
435
+
436
+ @Test
437
+ fun testRawSelectWithUnionAndAlias () {
438
+ val selectStatement = select(
439
+ id.`as `(" A_ID" ), firstName, lastName, birthDate, employed, occupation,
440
+ addressId
441
+ ).from(Person ) {
442
+ where(id, isEqualTo(1 ))
443
+ union {
444
+ select(
445
+ id.`as `(" A_ID" ), firstName, lastName, birthDate, employed, occupation,
446
+ addressId
447
+ ).from(Person ) {
448
+ where(id, isEqualTo(2 ))
449
+ }
450
+ }
451
+ union {
452
+ select(
453
+ id.`as `(" A_ID" ), firstName, lastName, birthDate, employed, occupation,
454
+ addressId
455
+ ).from(Person , " p" ) {
456
+ where(id, isEqualTo(3 ))
457
+ }
458
+ }
459
+ }
460
+
461
+ val expected = " select id as A_ID, first_name, last_name, birth_date, employed, occupation, address_id " +
462
+ " from Person " +
463
+ " where id = :p1 " +
464
+ " union " +
465
+ " select id as A_ID, first_name, last_name, birth_date, employed, occupation, address_id " +
466
+ " from Person " +
467
+ " where id = :p2 " +
468
+ " union " +
469
+ " select p.id as A_ID, p.first_name, p.last_name, p.birth_date, p.employed, p.occupation, p.address_id " +
470
+ " from Person p " +
471
+ " where p.id = :p3"
472
+
473
+ assertThat(selectStatement.selectStatement).isEqualTo(expected)
474
+
475
+ val records = template.selectList(selectStatement) { rs, _ ->
476
+ val record = PersonRecord ()
477
+ record.id = rs.getInt(1 )
478
+ record.firstName = rs.getString(2 )
479
+ record.lastName = rs.getString(3 )
480
+ record.birthDate = rs.getTimestamp(4 )
481
+ record.employed = rs.getString(5 )
482
+ record.occupation = rs.getString(6 )
483
+ record.addressId = rs.getInt(7 )
484
+ record
485
+ }
486
+
487
+ assertThat(records).hasSize(3 )
488
+ with (records[0 ]!! ) {
489
+ assertThat(id).isEqualTo(1 )
490
+ assertThat(firstName).isEqualTo(" Fred" )
491
+ assertThat(lastName).isEqualTo(" Flintstone" )
492
+ assertThat(birthDate).isNotNull()
493
+ assertThat(employed).isEqualTo(" Yes" )
494
+ assertThat(occupation).isEqualTo(" Brontosaurus Operator" )
495
+ assertThat(addressId).isEqualTo(1 )
496
+ }
497
+
498
+ with (records[2 ]!! ) {
499
+ assertThat(id).isEqualTo(3 )
500
+ assertThat(firstName).isEqualTo(" Pebbles" )
501
+ assertThat(lastName).isEqualTo(" Flintstone" )
502
+ assertThat(birthDate).isNotNull()
503
+ assertThat(employed).isEqualTo(" No" )
504
+ assertThat(occupation).isNull()
505
+ assertThat(addressId).isEqualTo(1 )
506
+ }
424
507
}
425
508
426
509
@Test
0 commit comments