Lino Website

Documentation · Modules · adamo · Features · Automatic SQL generation

Even for complex queries

Lino automatically generates joined queries. The following code examples check whether the city named 'Eupen' is in a nation named 'Belgium', using two different methods, both legal but one more efficient.

The first method does it without specifying columnNames:

    qry=sess.query(City)
    home=qry.findone(name="Eupen")
    self.assertEqual(home.nation.name,"Belgium")

The second method specifies "in advance" that we are interested in the joined column 'nation.name'.

    qry=sess.query(City,"id name nation.name")
    home=qry.findone(name=Eupen)
    self.assertEqual(home.nation.name,"Belgium")

The first method is more resource-intensive: it uses only one instead of two SQL statements because we

Method 1 generates 2 SQL statements:

    SELECT nation_id, id, name, zipCode, inhabitants
    FROM Cities
    WHERE name = 'Eupen';

SELECT id, name_en, area, population, curr, isocode FROM Nations WHERE id = 'be';

Method 2 generates only one SQL statement:

    SELECT lead.nation_id, lead.id, lead.name,
           nation.id, nation.name_en
    FROM Cities AS lead
      LEFT JOIN Nations AS nation ON (lead.nation_id = nation.id)
    WHERE name = 'Eupen';

(Tested in 80)

Refering articles:

Copyright 2001-2007 Luc Saffre.
http://lino.saffre-rumma.ee
Generated 2007-06-07 16:23:47