Lino Website

Documentation · Modules · adamo · Examples

filters1.py

This example shows how to use the NotEmpty filter for a Detail column, which leads to a nested SELECT in the SQL code.

Source code:

from lino.apps.contacts.contacts_demo import startup
from lino.apps.contacts.contacts_tables import Nation
from lino.adamo.filters import NotEmpty

dbc = startup() # big=True)
        
qry=dbc.query(Nation,"id name cities")
qry.addColFilter('cities',NotEmpty)
qry.show(columnWidths="2 15 20")

print
print qry.getSqlSelect()

del dbc, qry

Output:

Nations where 'cities' not empty
================================
id|name           |cities              
--+---------------+--------------------
ee|Estonia        |10 Cities           
be|Belgium        |9 Cities            
de|Germany        |7 Cities            

SELECT id, name_en FROM Nations WHERE EXISTS (SELECT * FROM Cities WHERE nation_id=Nations.id)

Refering articles:

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