unimarc to marc21
[webpac2] / sql / mkindex.pl
index 7730620..2cb05e6 100755 (executable)
@@ -34,9 +34,9 @@ while (<>) {
                $out->{inherits}->{$table} = $1;
        }
 
-       if (s/^\s*(\S+)(.+?)references\s+(\S+)\s*\((\S+)\)/\t$1$2/i) {
+       if (s/^\s*(\S+)(.+?)references\s+(\S+)\s*\((\S+)\)([^,]*)([,\s]*)$/\t$1$2$6/i) {
 #      if (/^\s*(\S+)(.+?)references\s+(\S+)\s*\((\S+)\)/) {
-               @{ $out->{references}->{$table}->{$1} } = ( $3, $4 );
+               @{ $out->{references}->{$table}->{$1} } = ( $3, $4, $5 );
        }
 
        print "$_\n";
@@ -47,8 +47,8 @@ while (<>) {
 print STDERR Dumper($out);
 
 foreach my $table (keys %{ $out->{inherits} }) {
-       my $parent = $out->{inherits}->{$table} || die;
-       my $pk = $out->{table_pk}->{$parent} || die;
+       my $parent = $out->{inherits}->{$table} || die "$table doesn't inherit anything";
+       my $pk = $out->{table_pk}->{$parent} || die "$parent doesn't have primary key";
        my $seq = $parent . '_' . $pk . '_seq';
        print qq{alter table $table alter column $pk set default nextval('$seq');\n};
 }