Project

General

Profile

« Previous | Next » 

Revision 12151

lib/sql.py: create_table(), copy_table_struct(): support custom query options, such as cacheable

View differences:

trunk/lib/sql.py
1495 1495
def drop_table(db, table): drop(db, 'TABLE', table)
1496 1496

  
1497 1497
def create_table(db, table, cols=[], has_pkey=True, col_indexes=True,
1498
    like=None):
1498
    like=None, **query_opts):
1499 1499
    '''Creates a table.
1500 1500
    @param cols [sql_gen.TypedCol,...] The column names and types
1501 1501
    @param has_pkey If set, the first column becomes the primary key.
......
1504 1504
        * If a list reference, [0] will be set to a function to do this.
1505 1505
          This can be used to delay index creation until the table is populated.
1506 1506
    '''
1507
    query_opts.setdefault('cacheable', True)
1508
    
1507 1509
    table = sql_gen.as_Table(table)
1508 1510
    
1509 1511
    if like != None:
......
1525 1527
        str_ += '\n, '.join(c.to_str(db) for c in cols)
1526 1528
        str_ += '\n);'
1527 1529
        
1528
        opts = dict(recover=True, cacheable=True, log_level=2,
1529
            log_ignore_excs=(DuplicateException,))
1530
        opts = dict(recover=True, log_level=2,
1531
            log_ignore_excs=(DuplicateException,), **query_opts)
1530 1532
        try: run_query(db, str_, **opts)
1531 1533
        except InvalidTypeException: # try again as view
1532 1534
            run_query_into(db, mk_select(db, like, limit=0), into=table, **opts)
......
1546 1548
    if isinstance(col_indexes, list): col_indexes[0] = add_indexes_ # defer
1547 1549
    elif col_indexes: add_indexes_() # add now
1548 1550

  
1549
def copy_table_struct(db, src, dest):
1551
def copy_table_struct(db, src, dest, **opts):
1550 1552
    '''Creates a structure-only copy of a table. (Does not copy data.)'''
1551
    create_table(db, dest, has_pkey=False, col_indexes=False, like=src)
1553
    create_table(db, dest, has_pkey=False, col_indexes=False, like=src, **opts)
1552 1554

  
1553 1555
def copy_table(db, src, dest):
1554 1556
    '''Creates a copy of a table, including data'''

Also available in: Unified diff