Project

General

Profile

« Previous | Next » 

Revision 3042

sql.py: add_col(): Added comment param which can be used to distinguish columns of the same name from each other when they contain different data, to allow the ADD COLUMN query (and related queries, such as adding indexes) to be cached

View differences:

lib/sql.py
1111 1111
        cols = cols[1:]
1112 1112
    for col in cols: add_index(db, col, table)
1113 1113

  
1114
def add_col(db, table, col, **kw_args):
1114
def add_col(db, table, col, comment=None, **kw_args):
1115 1115
    '''
1116
    @param col Name may be versioned, so be sure to propagate any renaming back
1117
        to any source column for the TypedCol.
1116
    @param col TypedCol Name may be versioned, so be sure to propagate any
1117
        renaming back to any source column for the TypedCol.
1118
    @param comment None|str SQL comment used to distinguish columns of the same
1119
        name from each other when they contain different data, to allow the
1120
        ADD COLUMN query to be cached. If not set, query will not be cached.
1118 1121
    '''
1119 1122
    assert isinstance(col, sql_gen.TypedCol)
1120 1123
    
1121 1124
    while True:
1125
        str_ = 'ALTER TABLE '+table.to_str(db)+' ADD COLUMN '+col.to_str(db)
1126
        if comment != None: str_ += ' '+sql_gen.esc_comment(comment)
1127
        
1122 1128
        try:
1123
            run_query(db, 'ALTER TABLE '+table.to_str(db)+' ADD COLUMN '
1124
                +col.to_str(db), recover=True, cacheable=True, **kw_args)
1129
            run_query(db, str_, recover=True, cacheable=True, **kw_args)
1125 1130
            break
1126 1131
        except DuplicateException:
1127 1132
            col.name = next_version(col.name)

Also available in: Unified diff