Project

General

Profile

« Previous | Next » 

Revision 2352

sql_gen.py: Renamed join_using to join_same to reflect that it can also be used without USING

View differences:

lib/sql_gen.py
172 172

  
173 173
##### Joins
174 174

  
175
join_using = object() # tells Join to join the column with USING
175
join_same = object() # tells Join the left and right columns have the same name
176 176

  
177 177
filter_out = object() # tells Join to filter out rows that match the join
178 178

  
......
180 180
    def __init__(self, table, mapping, type_=None):
181 181
        '''
182 182
        @param mapping dict(right_table_col=left_table_col, ...)
183
            * if left_table_col is join_using: left_table_col = right_table_col
183
            * if left_table_col is join_same: left_table_col = right_table_col
184 184
        @param type_ None (for plain join)|str (e.g. 'LEFT')|filter_out
185 185
            * filter_out: equivalent to 'LEFT' with the query filtered by
186 186
              `table_pkey IS NULL` (indicating no match)
......
199 199
            # Note that right_table_col is on the left in the comparison
200 200
            
201 201
            # Parse special values
202
            if left_table_col is join_using: left_table_col = right_table_col
202
            if left_table_col is join_same: left_table_col = right_table_col
203 203
            
204 204
            cond = as_ValueCond(left_table_col, left_table)
205 205
            return cond.to_str(db, as_Col(right_table_col, self.table))
......
208 208
        type_ = self.type_
209 209
        joins = self.mapping
210 210
        if type_ is not filter_out and reduce(operator.and_,
211
            (v is join_using for v in joins.itervalues())):
211
            (v is join_same for v in joins.itervalues())):
212 212
            # all cols w/ USING, so can use simpler USING syntax
213 213
            cols = (as_Col(v).to_str(db) for v in joins.iterkeys())
214 214
            join_cond = 'USING ('+(', '.join(cols))+')'
lib/sql.py
755 755
    in_tables0 = in_tables.pop(0) # first table is separate
756 756
    in_pkey = pkey(db, in_tables0, recover=True)
757 757
    in_pkey_col = sql_gen.as_Col(in_pkey, in_tables0)
758
    input_joins = [in_tables0]+[sql_gen.Join(v, {in_pkey: sql_gen.join_using})
758
    input_joins = [in_tables0]+[sql_gen.Join(v, {in_pkey: sql_gen.join_same})
759 759
        for v in in_tables]
760 760
    
761 761
    out_pkey = pkey(db, out_table, recover=True)
......
857 857
                db.log_debug('Joining together output and input pkeys')
858 858
                run_query_into_pkeys(*mk_select(db, [in_pkeys_ref[0],
859 859
                    sql_gen.Join(out_pkeys_ref[0],
860
                    {row_num_col: sql_gen.join_using})], pkeys, start=0))
860
                    {row_num_col: sql_gen.join_same})], pkeys, start=0))
861 861
            
862 862
            db.log_debug("Setting missing rows' pkeys to NULL")
863 863
            missing_rows_joins = input_joins+[sql_gen.Join(pkeys_ref[0],

Also available in: Unified diff