Project

General

Profile

« Previous | Next » 

Revision 2408

sql.py: Added index_col()

View differences:

lib/sql.py
748 748

  
749 749
row_num_col = '_row_num'
750 750

  
751
def index_col(db, col):
752
    '''Adds an index on a column if it doesn't already exist.'''
753
    assert sql_gen.is_table_col(col)
754
    
755
    table = col.table
756
    index = sql_gen.as_Table(clean_name(str(col)))
757
    col = sql_gen.to_name_only_col(col)
758
    try: run_query(db, 'CREATE INDEX '+index.to_str(db)+' ON '+table.to_str(db)
759
        +' ('+col.to_str(db)+')', recover=True)
760
    except DuplicateTableException: pass # index already existed
761

  
751 762
def index_pkey(db, table, recover=None):
752 763
    '''Makes the first column in a table the primary key.
753 764
    @pre The table must not already have a primary key.

Also available in: Unified diff