Project

General

Profile

« Previous | Next » 

Revision 2406

sql.py: Added index_pkey()

View differences:

lib/sql.py
748 748

  
749 749
row_num_col = '_row_num'
750 750

  
751
def index_pkey(db, table, recover=None):
752
    '''Makes the first column in a table the primary key.
753
    @pre The table must not already have a primary key.
754
    '''
755
    table = sql_gen.as_Table(table)
756
    
757
    index = sql_gen.as_Table(table.name+'_pkey')
758
    col = sql_gen.to_name_only_col(pkey(db, table, recover))
759
    run_query(db, 'ALTER TABLE '+table.to_str(db)+' ADD CONSTRAINT '
760
        +index.to_str(db)+' PRIMARY KEY('+col.to_str(db)+')', recover=recover)
761

  
751 762
def add_row_num(db, table):
752 763
    '''Adds a row number column to a table. Its name is in row_num_col. It will
753 764
    be the primary key.'''

Also available in: Unified diff