Project

General

Profile

« Previous | Next » 

Revision 3056

sql.py: mk_update(): Added in_place param

View differences:

sql.py
755 755
    
756 756
    return insert_select(db, table, cols, query, *args, **kw_args)
757 757

  
758
def mk_update(db, table, changes=None, cond=None):
758
def mk_update(db, table, changes=None, cond=None, in_place=False):
759 759
    '''
760 760
    @param changes [(col, new_value),...]
761 761
        * container can be any iterable type
762 762
        * col: sql_gen.Code|str (for col name)
763 763
        * new_value: sql_gen.Code|literal value
764 764
    @param cond sql_gen.Code WHERE condition. e.g. use sql_gen.*Cond objects.
765
    @param in_place If set, locks the table and updates rows in place.
766
        This avoids creating dead rows in PostgreSQL.
767
        * changes may only change one column
768
        * cond must be None
765 769
    @return str query
766 770
    '''
771
    if in_place:
772
        assert len(changes) == 1
773
        assert cond == None
774
    
767 775
    query = 'UPDATE '+sql_gen.as_Table(table).to_str(db)+'\nSET\n'
768 776
    query += ',\n'.join((sql_gen.to_name_only_col(col, table).to_str(db)+' = '
769 777
        +sql_gen.as_Value(new_value).to_str(db) for col, new_value in changes))

Also available in: Unified diff