From: Mike G. v. a. <we...@ma...> - 2005-07-20 18:27:06
|
Log Message: ----------- Fixed error that kept the script from working on courses whose names contained an underscore. Added ` ` around course names to handle courses whose names have hyphens in them (and other weird characters) Added print comments so that you see a running commentary of what is being changed. Once this script is debugged we might want to turn these off. Modified Files: -------------- webwork-modperl/bin: wwdb_addgw Revision Data ------------- Index: wwdb_addgw =================================================================== RCS file: /webwork/cvs/system/webwork-modperl/bin/wwdb_addgw,v retrieving revision 1.1 retrieving revision 1.2 diff -Lbin/wwdb_addgw -Lbin/wwdb_addgw -u -r1.1 -r1.2 --- bin/wwdb_addgw +++ bin/wwdb_addgw @@ -171,7 +171,8 @@ my $rowRef = $st->fetchall_arrayref(); foreach my $r ( @$rowRef ) { $_ = $r->[0]; - my ($crs, $tbl) = ( /^([^_]+)_(.*)$/ ); + #my ($crs, $tbl) = ( /^([^_]+)_(.*)$/ ); # this fails on courses with underscores in their names + my ($crs) = (/^(.*)_key$/); # match the key table $courses{$crs} = 1 if ( defined( $crs ) ); } die("Error: found now sql_single WeBWorK courses\n") if ( ! %courses ); @@ -252,13 +253,13 @@ # give some sense of progress select STDOUT; $| = 1; # unbuffer output - print "doing update."; + print "doing update for $dbtype databases.\n"; # list of added fields to check for classes that don't need updating my @newFields = keys( %addFields ); foreach my $crs ( @$crsRef ) { - print "."; + print "updating $crs.\n"; my $colRef; if ( $dbtype eq 'sql' ) { @@ -276,7 +277,8 @@ } else { # for sql_single we already have a database handle; get the set table # columns and proceed - my $cmd = "show columns from ${crs}_set"; + my $cmd = "show columns from `${crs}_set`"; + print "$cmd\n"; my $st = $dbh->prepare( $cmd ) or die( $dbh->errstr() ); $st->execute(); $colRef = $st->fetchall_arrayref(); @@ -301,17 +303,19 @@ $cmd1 = 'alter table set_not_a_keyword add column'; $cmd2 = 'alter table set_user add column'; } else { - $cmd1 = "alter table ${crs}_set add column"; - $cmd2 = "alter table ${crs}_set_user add column"; + $cmd1 = "alter table `${crs}_set` add column"; + $cmd2 = "alter table `${crs}_set_user` add column"; } foreach my $f ( keys %addFields ) { + print "$cmd1 $f $addFields{$f}\n"; my $st = $dbh->prepare( "$cmd1 $f $addFields{$f}" ) or die( $dbh->errstr() ); $st->execute() or die( $st->errstr() ); } foreach my $f ( keys %addFields ) { + print "$cmd2 $f $addFields{$f}\n"; my $st = $dbh->prepare( "$cmd2 $f $addFields{$f}" ) or die( $dbh->errstr() ); $st->execute() or die( $st->errstr() ); |