~ubuntu-branches/debian/sid/sqlalchemy/sid

« back to all changes in this revision

Viewing changes to test/sql/test_join_rewriting.py

  • Committer: Package Import Robot
  • Author(s): Piotr Ożarowski
  • Date: 2014-06-27 20:17:13 UTC
  • mfrom: (1.4.28)
  • Revision ID: package-import@ubuntu.com-20140627201713-g6p1kq8q1qenztrv
Tags: 0.9.6-1
* New upstream release
* Remove Python 3.X build tag files, thanks to Matthias Urlichs for the
  patch (closes: #747852)
* python-fdb isn't in the Debian archive yet so default dialect for firebird://
  URLs is changed to obsolete kinterbasdb, thanks to Russell Stuart for the
  patch (closes: #752145)

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
        Column('a_id', Integer, ForeignKey('a.id'))
17
17
    )
18
18
 
 
19
b_a = Table('b_a', m,
 
20
        Column('id', Integer, primary_key=True),
 
21
    )
 
22
 
19
23
b1 = Table('b1', m,
20
24
        Column('id', Integer, primary_key=True),
21
25
        Column('a_id', Integer, ForeignKey('a.id'))
201
205
            self._b_ab1_union_c_ab2
202
206
        )
203
207
 
 
208
    def test_b_a_id_double_overlap_annotated(self):
 
209
        # test issue #3057
 
210
        # this involves annotations so try to loop those in.
 
211
        j1 = b.join(b_a, b.c.id == b_a.c.id)
 
212
        annot = [
 
213
                    b.c.id._annotate({}),
 
214
                    b.c.a_id._annotate({}),
 
215
                    b_a.c.id._annotate({})
 
216
                ]
 
217
 
 
218
        s = select(annot).select_from(j1).apply_labels().alias()
 
219
 
 
220
        s = select(list(s.c)).apply_labels()
 
221
 
 
222
        self._test(
 
223
            s,
 
224
            self._b_a_id_double_overlap_annotated
 
225
        )
204
226
 
205
227
class JoinRewriteTest(_JoinRewriteTestBase, fixtures.TestBase):
206
228
    """test rendering of each join with right-nested rewritten as
320
342
        "FROM a JOIN b2 ON a.id = b2.a_id) AS anon_2 ON anon_2.a_id = b.a_id)"
321
343
    )
322
344
 
 
345
    _b_a_id_double_overlap_annotated = (
 
346
        "SELECT anon_1.b_id AS anon_1_b_id, anon_1.b_a_id AS anon_1_b_a_id, "
 
347
        "anon_1.id_1 AS anon_1_id_1 "
 
348
        "FROM (SELECT b.id AS b_id, b.a_id AS b_a_id, b_a.id AS id_1 "
 
349
        "FROM b JOIN b_a ON b.id = b_a.id) AS anon_1"
 
350
    )
 
351
 
323
352
class JoinPlainTest(_JoinRewriteTestBase, fixtures.TestBase):
324
353
    """test rendering of each join with normal nesting."""
325
354
    @util.classproperty
413
442
        "JOIN (a JOIN b2 ON a.id = b2.a_id) ON a.id = b.a_id)"
414
443
    )
415
444
 
 
445
    _b_a_id_double_overlap_annotated = (
 
446
        "SELECT anon_1.b_id AS anon_1_b_id, anon_1.b_a_id AS anon_1_b_a_id, "
 
447
        "anon_1.id_1 AS anon_1_id_1 FROM "
 
448
        "(SELECT b.id AS b_id, b.a_id AS b_a_id, b_a.id AS id_1 "
 
449
        "FROM b JOIN b_a ON b.id = b_a.id) AS anon_1"
 
450
    )
 
451
 
416
452
class JoinNoUseLabelsTest(_JoinRewriteTestBase, fixtures.TestBase):
417
453
    @util.classproperty
418
454
    def __dialect__(cls):
506
542
        "FROM b JOIN (a JOIN b2 ON a.id = b2.a_id) ON a.id = b.a_id)"
507
543
    )
508
544
 
 
545
    _b_a_id_double_overlap_annotated = (
 
546
        "SELECT anon_1.b_id, anon_1.b_a_id, anon_1.id_1 FROM "
 
547
        "(SELECT b.id AS b_id, b.a_id AS b_a_id, b_a.id AS id_1 "
 
548
        "FROM b JOIN b_a ON b.id = b_a.id) AS anon_1"
 
549
    )
 
550
 
509
551
class JoinExecTest(_JoinRewriteTestBase, fixtures.TestBase):
510
552
    """invoke the SQL on the current backend to ensure compatibility"""
511
553
 
513
555
 
514
556
    _a_bc = _a_bc_comma_a1_selbc = _a__b_dc = _a_bkeyassoc = \
515
557
        _a_bkeyassoc_aliased = _a_atobalias_balias_c_w_exists = \
516
 
        _a_atobalias_balias = _b_ab1_union_c_ab2 = None
 
558
        _a_atobalias_balias = _b_ab1_union_c_ab2 = \
 
559
        _b_a_id_double_overlap_annotated = None
517
560
 
518
561
    @classmethod
519
562
    def setup_class(cls):