def iter_fields(expression):
    r"""iter_fields

        >>> ima = NamedSource('ima')
        >>> wko = NamedSource('wko')
        >>> join = And(ima.IMA_ItemID == wko.WKO_ItemID,
        ...            ima.IMA_UnitMeasure == wko.WKO_UnitMeasure,
        ...            Or(ima.IMA_ItemPrice.is_null, wko.WKO_WorkOrderDate == 3))
        ...
        >>> print '\n'.join([str(x) for x in iter_fields(join)])
        ima.IMA_ItemID
        wko.WKO_ItemID
        ima.IMA_UnitMeasure
        wko.WKO_UnitMeasure
        ima.IMA_ItemPrice
        wko.WKO_WorkOrderDate
    """
    if isinstance(expression, Field):
        yield expression
    elif isinstance(expression, UnaryOperated) and isinstance(expression, Expression):
        for x in iter_fields(expression.element):
            yield x
    elif isinstance(expression, BinaryOperated) and isinstance(expression, Expression):
        for expr in expression.elements:
            for x in iter_fields(expr):
                yield x
iter_fields

        >>> ima = NamedSource('ima')
        >>> wko = NamedSource('wko')
        >>> join = And(ima.IMA_ItemID == wko.WKO_ItemID,
        ...            ima.IMA_UnitMeasure == wko.WKO_UnitMeasure,
        ...            Or(ima.IMA_ItemPrice.is_null, wko.WKO_WorkOrderDate == 3))
        ...
        >>> print '\n'.join([str(x) for x in iter_fields(join)])
        ima.IMA_ItemID
        wko.WKO_ItemID
        ima.IMA_UnitMeasure
        wko.WKO_UnitMeasure
        ima.IMA_ItemPrice
        wko.WKO_WorkOrderDate
    
recipes/Python/415345_write_sql_via_python/recipe-415345.py