Project

General

Profile

« Previous | Next » 

Revision 3085

sql.py: create_table(): Support creating temp tables. This fixes a bug in copy_table_struct() where the created table was not a temp table if the source table was. copy_table_struct(): Removed no longer needed versioning because that is now handled by create_table().

View differences:

lib/sql.py
1175 1175
        cols[0] = pkey = copy.copy(cols[0]) # don't modify input!
1176 1176
        pkey.constraints = 'PRIMARY KEY'
1177 1177
    
1178
    str_ = 'CREATE TABLE '+table.to_str(db)+' (\n'
1179
    str_ += '\n, '.join(c.to_str(db) for c in cols)
1180
    str_ += '\n);\n'
1181
    run_query(db, str_, cacheable=True, log_level=2)
1178
    temp = table.is_temp and not db.debug_temp
1179
        # temp tables permanent in debug_temp mode
1182 1180
    
1181
    # Create table
1182
    while True:
1183
        str_ = 'CREATE'
1184
        if temp: str_ += ' TEMP'
1185
        str_ += ' TABLE '+table.to_str(db)+' (\n'
1186
        str_ += '\n, '.join(c.to_str(db) for c in cols)
1187
        str_ += '\n);\n'
1188
        
1189
        try:
1190
            run_query(db, str_, cacheable=True, log_level=2,
1191
                log_ignore_excs=(DuplicateException,))
1192
            break
1193
        except DuplicateException:
1194
            table.name = next_version(table.name)
1195
            # try again with next version of name
1196
    
1183 1197
    # Add indexes
1184 1198
    if has_pkey: has_pkey = already_indexed
1185 1199
    def add_indexes_(): add_indexes(db, table, has_pkey)
......
1188 1202

  
1189 1203
def copy_table_struct(db, src, dest):
1190 1204
    '''Creates a structure-only copy of a table. (Does not copy data.)'''
1191
    while True:
1192
        try:
1193
            create_table(db, dest, has_pkey=False, col_indexes=False, like=src)
1194
            break
1195
        except DuplicateException:
1196
            table.name = next_version(table.name)
1197
            # try again with next version of name
1205
    create_table(db, dest, has_pkey=False, col_indexes=False, like=src)
1198 1206

  
1199 1207
### Data
1200 1208

  

Also available in: Unified diff