/[papo]/papo/zot/zot2sql.pl
ViewVC logotype

Diff of /papo/zot/zot2sql.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by charlie, Fri Jun 28 20:08:34 2002 UTC revision 1.2 by jlenton, Thu Sep 5 23:08:33 2002 UTC
# Line 7  use Carp; Line 7  use Carp;
7  use DBI;  use DBI;
8  use zot;  use zot;
9    
10    our %config = ();
11    
12  sub usage  sub usage
13  {  {
14      print STDERR "Usage: zot2sql \"database identifier string\" [ driver-specific options ] file\n";      print STDERR "Usage: zot2sql \"database identifier string\" [ driver-specific options ] file\n";
15      print STDERR " e.g.: zot2sql \"\$( pg_config --version )\" testdb file\n";      print STDERR " e.g.: zot2sql \"\$( pg_config --version )\" testdb file\n";
16      print STDERR @_;      if (@_)
17        {
18            print STDERR @_;
19        }
20        else
21        {
22            print STDERR "Currently supported database identifiers are:\n";
23            print "\t$_\n"
24                foreach (sort keys %config);
25        }
26      exit 1;      exit 1;
27  }  }
28    
 sub delay() { system('sync'); select(undef, undef, undef, 0.5) }  
   
   
 our %config = ();  
   
29  $config{'^PostgreSQL 7\.1\.'} =  $config{'^PostgreSQL 7\.1\.'} =
30  {  {
31      'driver' => sub      'driver' => sub
# Line 34  $config{'^PostgreSQL 7\.1\.'} = Line 40  $config{'^PostgreSQL 7\.1\.'} =
40      {      {
41          'bigserial' => 'serial',          'bigserial' => 'serial',
42      },      },
43        'delay' => sub { system('sync'); select(undef, undef, undef, 0.5) },
44  };  };
45    
46  $config{'^PostgreSQL 7\.2\.'} =  $config{'^PostgreSQL 7\.2\.'} =
47  {  {
48      'driver' => $config{'^PostgreSQL 7\.1\.'}{'driver'},      'driver' => $config{'^PostgreSQL 7\.1\.'}{'driver'},
49      'datatypes' => {},      'datatypes' => {},
50        'delay' => $config{'^PostgreSQL 7\.1\.'}{'delay'},
51    };
52    
53    $config{'stdout'} =
54    {
55        'driver' => sub { return "dbi:stdout:" },
56        'datatypes' => {},
57        'delay' => sub { },
58  };  };
59    
60  usage() if (@ARGV < 3);  usage() if (@ARGV < 2);
61    
62  our $file = pop @ARGV;  our $file = pop @ARGV;
63  our $db_conf = shift @ARGV;  our $db_conf = shift @ARGV;
# Line 121  foreach my $table (sort keys %structure) Line 136  foreach my $table (sort keys %structure)
136    
137      print $sql;      print $sql;
138      $db->do( $sql );      $db->do( $sql );
139      delay;      $config{$db_conf}{'delay'}->();
140  }  }
141    
142  foreach my $table (keys %structure)  foreach my $table (keys %structure)
# Line 131  foreach my $table (keys %structure) Line 146  foreach my $table (keys %structure)
146          my $sql = "ALTER TABLE $table ADD FOREIGN KEY ($rel) REFERENCES $structure{$table}{REL}{$rel};\n";          my $sql = "ALTER TABLE $table ADD FOREIGN KEY ($rel) REFERENCES $structure{$table}{REL}{$rel};\n";
147          print $sql;          print $sql;
148          $db->do($sql);          $db->do($sql);
149          delay;          $config{$db_conf}{'delay'}->();
150      }      }
151  }  }

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26