[Koha-cvs] CVS: koha/updater updatedatabase,1.4.2.20,1.4.2.21

Steve Tonnesen tonnesen at users.sourceforge.net
Wed Sep 18 00:01:39 CEST 2002


Update of /cvsroot/koha/koha/updater
In directory usw-pr-cvs1:/tmp/cvs-serv18210

Modified Files:
      Tag: rel-1-2
	updatedatabase 
Log Message:
Added a routine to check the definitions of individual fields in a table.


Index: updatedatabase
===================================================================
RCS file: /cvsroot/koha/koha/updater/updatedatabase,v
retrieving revision 1.4.2.20
retrieving revision 1.4.2.21
diff -C2 -r1.4.2.20 -r1.4.2.21
*** updatedatabase	9 Sep 2002 19:45:40 -0000	1.4.2.20
--- updatedatabase	17 Sep 2002 22:01:36 -0000	1.4.2.21
***************
*** 154,157 ****
--- 154,164 ----
  
  
+ my %fielddefinitions=(
+ printers => [
+ 	{ field => 'printername', type => 'char(40)', null => '', key => 'PRI', default => '' },
+ 	],
+ );
+ 
+ 
  
  #-------------------
***************
*** 247,250 ****
--- 254,295 ----
  } # foreach table
  
+ #my %fielddefinitions=(
+ #printers => [
+ #	{ field => 'printername', type => 'char(40)', null => '', key => 'PRI', default='' },
+ #);
+ foreach $table ( keys %fielddefinitions ) {
+     print "Check table $table\n" if $debug;
+     $sth=$dbh->prepare("show columns from $table");
+     $sth->execute();
+     my $definitions;
+     while ( ($column, $type, $null, $key, $default, $extra) = $sth->fetchrow) {
+ 	$definitions->{$column}->{type}=$type;
+ 	$definitions->{$column}->{null}=$null;
+ 	$definitions->{$column}->{key}=$key;
+ 	$definitions->{$column}->{default}=$default;
+ 	$definitions->{$column}->{extra}=$extra;
+     } # while 
+     my $fieldrow=$fielddefinitions{$table};
+     foreach my $row ( @$fieldrow )  {
+ 	my $field = $row->{field};
+ 	my $type = $row->{type};
+ 	my $null = $row->{null};
+ 	my $key = $row->{key};
+ 	my $default = $row->{default};
+ 	my $def=$definitions->{$field};
+ 	unless ($type eq $def->{type} && $null eq $def->{null} && $key eq $def->{key} && $default eq $def->{default}) {
+ 	    if ($null eq '') {
+ 		$null='NOT NULL';
+ 	    }
+ 	    if ($key eq 'PRI') {
+ 		$key ='PRIMARY KEY';
+ 	    }
+ 	    my $sth=$dbh->prepare("alter table $table change $field $field $type $null $key default ?");
+ 	    $sth->execute($default);
+ 	    print "  Alter $field in $table\n";
+ 	}
+     }
+ }
+ 
  # Get list of columns from items table
  my %itemtypes;
***************
*** 355,358 ****
--- 400,406 ----
  
  # $Log$
+ # Revision 1.4.2.21  2002/09/17 22:01:36  tonnesen
+ # Added a routine to check the definitions of individual fields in a table.
+ #
  # Revision 1.4.2.20  2002/09/09 19:45:40  uid41696
  # Adding authentication calls to intranet scripts





More information about the Koha-cvs mailing list