Project

General

Profile

« Previous | Next » 

Revision 2115

sql.py: Added cleanup_table()

View differences:

sql.py
623 623
        
624 624
        return pkeys_table
625 625
    except DuplicateKeyException, e: raise
626

  
627
##### Data cleanup
628

  
629
def cleanup_table(db, table, cols, table_is_esc=False):
630
    def esc_name_(name): return esc_name(db, name)
631
    
632
    if not table_is_esc: check_name(table)
633
    cols = map(esc_name_, cols)
634
    
635
    run_query(db, 'UPDATE '+table+' SET\n'+(',\n'.join(('\n'+col
636
        +' = nullif(nullif(trim(both from '+col+"), %(null0)s), %(null1)s)"
637
            for col in cols))),
638
        dict(null0='', null1=r'\N'))

Also available in: Unified diff