Changeset 431 for wiki-toolkit/trunk/lib/Wiki/Toolkit/Setup/MySQL.pm
- Timestamp:
- 05/11/08 17:04:41 (4 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
wiki-toolkit/trunk/lib/Wiki/Toolkit/Setup/MySQL.pm
r426 r431 14 14 15 15 my %create_sql = ( 16 schema_info => [ qq|16 schema_info => [ qq| 17 17 CREATE TABLE schema_info ( 18 18 version int(10) NOT NULL default 0 … … 117 117 my %tables = fetch_tables_listing($dbh); 118 118 119 # Do we need to upgrade the schema of existing tables?120 # (Don't check if no tables currently exist)121 my $upgrade_schema;122 my @cur_data;123 if(scalar keys %tables > 0) {124 $upgrade_schema = Wiki::Toolkit::Setup::Database::get_database_upgrade_required($dbh,$VERSION);125 }126 if($upgrade_schema) {127 # Grab current data128 print "Upgrading: $upgrade_schema\n";129 @cur_data = eval("&Wiki::Toolkit::Setup::Database::fetch_upgrade_".$upgrade_schema."(\$dbh)");130 if($@) { warn $@; }119 # Do we need to upgrade the schema of existing tables? 120 # (Don't check if no tables currently exist) 121 my $upgrade_schema; 122 my @cur_data; 123 if(scalar keys %tables > 0) { 124 $upgrade_schema = Wiki::Toolkit::Setup::Database::get_database_upgrade_required($dbh,$VERSION); 125 } 126 if($upgrade_schema) { 127 # Grab current data 128 print "Upgrading: $upgrade_schema\n"; 129 @cur_data = eval("&Wiki::Toolkit::Setup::Database::fetch_upgrade_".$upgrade_schema."(\$dbh)"); 130 if($@) { warn $@; } 131 131 132 132 # Check to make sure we can create, index and drop tables … … 137 137 } 138 138 139 # Drop the current tables140 cleardb($dbh);141 142 # Grab new list of tables143 %tables = fetch_tables_listing($dbh);144 }145 146 # Set up tables if not found139 # Drop the current tables 140 cleardb($dbh); 141 142 # Grab new list of tables 143 %tables = fetch_tables_listing($dbh); 144 } 145 146 # Set up tables if not found 147 147 foreach my $required ( keys %create_sql ) { 148 148 if ( $tables{$required} ) { … … 156 156 } 157 157 158 # If upgrading, load in the new data159 if($upgrade_schema) {160 Wiki::Toolkit::Setup::Database::bulk_data_insert($dbh,@cur_data);161 }158 # If upgrading, load in the new data 159 if($upgrade_schema) { 160 Wiki::Toolkit::Setup::Database::bulk_data_insert($dbh,@cur_data); 161 } 162 162 163 163 # Clean up if we made our own dbh. … … 167 167 # Internal method - what Wiki::Toolkit tables are defined? 168 168 sub fetch_tables_listing { 169 my $dbh = shift;169 my $dbh = shift; 170 170 171 171 # Check what tables exist … … 176 176 exists $create_sql{$table} and $tables{$table} = 1; 177 177 } 178 return %tables;178 return %tables; 179 179 } 180 180 … … 234 234 if ( $args{dbh} ) { 235 235 return $args{dbh}; 236 } else {236 } else { 237 237 return _make_dbh( %args ); 238 238 } … … 259 259 if ( $args{dbh} ) { 260 260 return 0; 261 } else {261 } else { 262 262 return 1; 263 263 } … … 273 273 $dsn .= ";host=$args{dbhost}" if $args{dbhost}; 274 274 my $dbh = DBI->connect($dsn, $args{dbuser}, $args{dbpass}, 275 { PrintError => 1, RaiseError => 1,276 AutoCommit => 1 } )277 or croak DBI::errstr;275 { PrintError => 1, RaiseError => 1, 276 AutoCommit => 1 } ) 277 or croak DBI::errstr; 278 278 return $dbh; 279 279 }
