Project

General

Profile

« Previous | Next » 

Revision 3148

sql.py: add_index(): Don't generate a unique name for the index because the database does that automatically

View differences:

lib/sql.py
1112 1112
        cols.append(col)
1113 1113
    
1114 1114
    table = sql_gen.as_Table(table)
1115
    index = sql_gen.Table(str(sql_gen.Col(','.join(map(str, cols)), table)))
1116 1115
    
1117 1116
    # Add index
1118
    while True:
1119
        str_ = 'CREATE'
1120
        if unique: str_ += ' UNIQUE'
1121
        str_ += ' INDEX '+index.to_str(db)+' ON '+table.to_str(db)+' ('+(
1122
            ', '.join((v.to_str(db) for v in exprs)))+')'
1123
        
1124
        try:
1125
            run_query(db, str_, recover=True, cacheable=True, log_level=3,
1126
                log_ignore_excs=(DuplicateException,))
1127
            break
1128
        except DuplicateException:
1129
            index.name = next_version(index.name)
1130
            # try again with next version of name
1117
    str_ = 'CREATE'
1118
    if unique: str_ += ' UNIQUE'
1119
    str_ += ' INDEX ON '+table.to_str(db)+' ('+(
1120
        ', '.join((v.to_str(db) for v in exprs)))+')'
1121
    run_query(db, str_, recover=True, cacheable=True, log_level=3)
1131 1122

  
1132 1123
def add_index_col(db, col, suffix, expr, nullable=True):
1133 1124
    if sql_gen.index_col(col) != None: return # already has index col

Also available in: Unified diff