Changeset 230


Ignore:
Timestamp:
Apr 20, 2006, 5:04:42 PM (14 years ago)
Author:
nick
Message:

Refresh db table listing after the drops

Location:
wiki-toolkit/trunk/lib/Wiki/Toolkit/Setup
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • wiki-toolkit/trunk/lib/Wiki/Toolkit/Setup/MySQL.pm

    r209 r230  
    115115
    116116    # Check whether tables exist
    117     my $sth = $dbh->prepare("SHOW TABLES") or croak $dbh->errstr;
    118     $sth->execute;
    119     my %tables;
    120     while ( my $table = $sth->fetchrow_array ) {
    121         $tables{$table} = 1;
    122     }
     117    my %tables = fetch_tables_listing($dbh);
    123118
    124119        # Do we need to upgrade the schema of existing tables?
     
    136131                # Drop the current tables
    137132                cleardb($dbh);
     133
     134                # Grab new list of tables
     135                %tables = fetch_tables_listing($dbh);
    138136        }
    139137
     
    159157}
    160158
     159# Internal method - what tables are defined?
     160sub fetch_tables_listing {
     161        my $dbh = shift;
     162
     163    # Check what tables exist
     164    my $sth = $dbh->prepare("SHOW TABLES") or croak $dbh->errstr;
     165    $sth->execute;
     166    my %tables;
     167    while ( my $table = $sth->fetchrow_array ) {
     168        $tables{$table} = 1;
     169    }
     170        return %tables;
     171}
     172
    161173=item B<cleardb>
    162174
  • wiki-toolkit/trunk/lib/Wiki/Toolkit/Setup/SQLite.pm

    r209 r230  
    102102
    103103    # Check whether tables exist, set them up if not.
    104     my $sql = "SELECT name FROM sqlite_master
    105                WHERE type='table' AND name in ("
    106             . join( ",", map { $dbh->quote($_) } keys %create_sql ) . ")";
    107     my $sth = $dbh->prepare($sql) or croak $dbh->errstr;
    108     $sth->execute;
    109     my %tables;
    110     while ( my $table = $sth->fetchrow_array ) {
    111         $tables{$table} = 1;
    112     }
     104    my %tables = fetch_tables_listing($dbh);
    113105
    114106        # Do we need to upgrade the schema?
     
    126118                # Drop the current tables
    127119                cleardb($dbh);
     120
     121                # Grab new list of tables
     122                %tables = fetch_tables_listing($dbh);
    128123        }
    129124
     
    151146}
    152147
     148# Internal method - what tables are defined?
     149sub fetch_tables_listing {
     150        my $dbh = shift;
     151
     152    # Check whether tables exist, set them up if not.
     153    my $sql = "SELECT name FROM sqlite_master
     154               WHERE type='table' AND name in ("
     155            . join( ",", map { $dbh->quote($_) } keys %create_sql ) . ")";
     156    my $sth = $dbh->prepare($sql) or croak $dbh->errstr;
     157    $sth->execute;
     158    my %tables;
     159    while ( my $table = $sth->fetchrow_array ) {
     160        $tables{$table} = 1;
     161    }
     162        return %tables;
     163}
     164
    153165=item B<cleardb>
    154166
Note: See TracChangeset for help on using the changeset viewer.