def test_join_typed(engine): sql = m.Join( e.Identifier('person'), 'natural left', e.Identifier('detail'), ) assert sql.__sql__(engine) == Sql('"person" NATURAL LEFT JOIN "detail"')
def test_join_not_allowed(engine): with pytest.raises(UnsupportedParameterError) as ctx: m.Join( e.Identifier('person'), '; DELETE FROM person --', e.Identifier('detail'), ) assert str(ctx.value) == "unsupported join type '; DELETE FROM person --'"
def test_select_join_right_using(engine): statement = s.Select( c.Select(n.star), c.From(m.Join( e.Identifier('person'), 'RIGHT', e.Identifier('detail'), c.Using(m.List(e.Identifier('person_id'))), )), ) assert statement.__sql__(engine) == Sql(''' SELECT * FROM "person" RIGHT JOIN "detail" USING ("person_id") '''.strip())
def test_select_join_cross(engine): statement = s.Select( c.Select(n.star), c.From(m.Join( e.Identifier('person'), 'CROSS', e.Identifier('detail'), )), ) assert statement.__sql__(engine) == Sql(''' SELECT * FROM "person" CROSS JOIN "detail" '''.strip())
def test_select_join_natural(engine): statement = s.Select( c.Select(n.star), c.From(m.Join( e.Identifier('person'), 'NATURAL', e.Identifier('detail'), )), ) assert statement.__sql__(engine) == Sql(''' SELECT * FROM "person" NATURAL JOIN "detail" '''.strip())
def test_select_join_inner_on(engine): statement = s.Select( c.Select(n.star), c.From(m.Join( e.Identifier('person'), 'INNER', e.Identifier('detail'), c.On(e.Equal( e.Identifier('person', 'person_id'), e.Identifier('detail', 'person_id'), )), )), ) assert statement.__sql__(engine) == Sql( 'SELECT * FROM "person" ' 'INNER JOIN "detail" ON "person"."person_id" = "detail"."person_id"' )
def test_join(engine): sql = m.Join(e.Identifier('person'), '', e.Identifier('detail')) assert sql.__sql__(engine) == Sql('"person" JOIN "detail"')