Project

General

Profile

« Previous | Next » 

Revision 2746

sql_gen.py: Join: mapping param defaults to {} for e.g. CROSS JOINs. to_str(): Omit join_cond if mapping is empty, rather than if join is a specific type.

View differences:

lib/sql_gen.py
400 400
filter_out = object() # tells Join to filter out rows that match the join
401 401

  
402 402
class Join(BasicObject):
403
    def __init__(self, table, mapping, type_=None):
403
    def __init__(self, table, mapping={}, type_=None):
404 404
        '''
405 405
        @param mapping dict(right_table_col=left_table_col, ...)
406 406
            * if left_table_col is join_same: left_table_col = right_table_col
......
443 443
        # Create join condition
444 444
        type_ = self.type_
445 445
        joins = self.mapping
446
        if type_ is not filter_out and reduce(operator.and_,
446
        if joins == {}: join_cond = None
447
        elif type_ is not filter_out and reduce(operator.and_,
447 448
            (v is join_same_not_null for v in joins.itervalues())):
448 449
            # all cols w/ USING, so can use simpler USING syntax
449 450
            cols = (as_Col(v).to_str(db) for v in joins.iterkeys())
......
458 459
        str_ = ''
459 460
        if type_ != None: str_ += type_+' '
460 461
        str_ += 'JOIN '+left_table.to_str(db)
461
        if type_ != 'CROSS': str_ += ' '+join_cond
462
        if join_cond != None: str_ += ' '+join_cond
462 463
        return str_
463 464
    
464 465
    def __repr__(self): return self.to_str(mockDb, '<left_table>')

Also available in: Unified diff