(self)
| 2535 | ) |
| 2536 | |
| 2537 | def test_compound_selects(self): |
| 2538 | assert_raises_message( |
| 2539 | exc.CompileError, |
| 2540 | "All selectables passed to CompoundSelect " |
| 2541 | "must have identical numbers of columns; " |
| 2542 | "select #1 has 2 columns, select #2 has 3", |
| 2543 | union(table3.select(), table1.select()).compile, |
| 2544 | ) |
| 2545 | |
| 2546 | x = union( |
| 2547 | select(table1).where(table1.c.myid == 5), |
| 2548 | select(table1).where(table1.c.myid == 12), |
| 2549 | ).order_by(table1.c.myid) |
| 2550 | |
| 2551 | self.assert_compile( |
| 2552 | x, |
| 2553 | "SELECT mytable.myid, mytable.name, " |
| 2554 | "mytable.description " |
| 2555 | "FROM mytable WHERE " |
| 2556 | "mytable.myid = :myid_1 UNION " |
| 2557 | "SELECT mytable.myid, mytable.name, mytable.description " |
| 2558 | "FROM mytable WHERE mytable.myid = :myid_2 " |
| 2559 | "ORDER BY myid", |
| 2560 | ) |
| 2561 | |
| 2562 | x = union(select(table1), select(table1)) |
| 2563 | x = union(x, select(table1)) |
| 2564 | self.assert_compile( |
| 2565 | x, |
| 2566 | "(SELECT mytable.myid, mytable.name, mytable.description " |
| 2567 | "FROM mytable UNION SELECT mytable.myid, mytable.name, " |
| 2568 | "mytable.description FROM mytable) UNION SELECT mytable.myid," |
| 2569 | " mytable.name, mytable.description FROM mytable", |
| 2570 | ) |
| 2571 | |
| 2572 | u1 = union( |
| 2573 | select(table1.c.myid, table1.c.name), |
| 2574 | select(table2), |
| 2575 | select(table3), |
| 2576 | ).order_by("name") |
| 2577 | self.assert_compile( |
| 2578 | u1, |
| 2579 | "SELECT mytable.myid, mytable.name " |
| 2580 | "FROM mytable UNION SELECT myothertable.otherid, " |
| 2581 | "myothertable.othername FROM myothertable " |
| 2582 | "UNION SELECT thirdtable.userid, thirdtable.otherstuff " |
| 2583 | "FROM thirdtable ORDER BY name", |
| 2584 | ) |
| 2585 | |
| 2586 | u1s = u1.subquery() |
| 2587 | assert u1s.corresponding_column(table2.c.otherid) is u1s.c.myid |
| 2588 | |
| 2589 | self.assert_compile( |
| 2590 | union(select(table1.c.myid, table1.c.name), select(table2)) |
| 2591 | .order_by("myid") |
| 2592 | .offset(10) |
| 2593 | .limit(5), |
| 2594 | # note table name is omitted here. The CompoundSelect, inside of |
nothing calls this directly
no test coverage detected