(self)
| 2559 | ) |
| 2560 | |
| 2561 | def test_compound_selects(self): |
| 2562 | assert_raises_message( |
| 2563 | exc.CompileError, |
| 2564 | "All selectables passed to CompoundSelect " |
| 2565 | "must have identical numbers of columns; " |
| 2566 | "select #1 has 2 columns, select #2 has 3", |
| 2567 | union(table3.select(), table1.select()).compile, |
| 2568 | ) |
| 2569 | |
| 2570 | x = union( |
| 2571 | select(table1).where(table1.c.myid == 5), |
| 2572 | select(table1).where(table1.c.myid == 12), |
| 2573 | ).order_by(table1.c.myid) |
| 2574 | |
| 2575 | self.assert_compile( |
| 2576 | x, |
| 2577 | "SELECT mytable.myid, mytable.name, " |
| 2578 | "mytable.description " |
| 2579 | "FROM mytable WHERE " |
| 2580 | "mytable.myid = :myid_1 UNION " |
| 2581 | "SELECT mytable.myid, mytable.name, mytable.description " |
| 2582 | "FROM mytable WHERE mytable.myid = :myid_2 " |
| 2583 | "ORDER BY myid", |
| 2584 | ) |
| 2585 | |
| 2586 | x = union(select(table1), select(table1)) |
| 2587 | x = union(x, select(table1)) |
| 2588 | self.assert_compile( |
| 2589 | x, |
| 2590 | "(SELECT mytable.myid, mytable.name, mytable.description " |
| 2591 | "FROM mytable UNION SELECT mytable.myid, mytable.name, " |
| 2592 | "mytable.description FROM mytable) UNION SELECT mytable.myid," |
| 2593 | " mytable.name, mytable.description FROM mytable", |
| 2594 | ) |
| 2595 | |
| 2596 | u1 = union( |
| 2597 | select(table1.c.myid, table1.c.name), |
| 2598 | select(table2), |
| 2599 | select(table3), |
| 2600 | ).order_by("name") |
| 2601 | self.assert_compile( |
| 2602 | u1, |
| 2603 | "SELECT mytable.myid, mytable.name " |
| 2604 | "FROM mytable UNION SELECT myothertable.otherid, " |
| 2605 | "myothertable.othername FROM myothertable " |
| 2606 | "UNION SELECT thirdtable.userid, thirdtable.otherstuff " |
| 2607 | "FROM thirdtable ORDER BY name", |
| 2608 | ) |
| 2609 | |
| 2610 | u1s = u1.subquery() |
| 2611 | assert u1s.corresponding_column(table2.c.otherid) is u1s.c.myid |
| 2612 | |
| 2613 | self.assert_compile( |
| 2614 | union(select(table1.c.myid, table1.c.name), select(table2)) |
| 2615 | .order_by("myid") |
| 2616 | .offset(10) |
| 2617 | .limit(5), |
| 2618 | # note table name is omitted here. The CompoundSelect, inside of |
nothing calls this directly
no test coverage detected