/[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.2 by jlenton, Thu Sep 5 23:08:33 2002 UTC revision 1.3 by jlenton, Mon Sep 16 20:11:01 2002 UTC
# Line 26  sub usage Line 26  sub usage
26      exit 1;      exit 1;
27  }  }
28    
29    #
30    # config for postgres 7.2
31    #  basically just pump everything in
32  $config{'^PostgreSQL 7\.1\.'} =  $config{'^PostgreSQL 7\.1\.'} =
33  {  {
34      'driver' => sub      'driver' => sub
# Line 36  $config{'^PostgreSQL 7\.1\.'} = Line 39  $config{'^PostgreSQL 7\.1\.'} =
39          return( ( sprintf("dbi:Pg:dbname=%s;host=%s", $db_name, $db_host),          return( ( sprintf("dbi:Pg:dbname=%s;host=%s", $db_name, $db_host),
40                    $user, $password, { 'RaiseError' => 1 } ) );                    $user, $password, { 'RaiseError' => 1 } ) );
41      },      },
     'datatypes' =>  
     {  
         'bigserial' => 'serial',  
     },  
42      'delay' => sub { system('sync'); select(undef, undef, undef, 0.5) },      'delay' => sub { system('sync'); select(undef, undef, undef, 0.5) },
43        'datatypes' => {},
44        'relational' => sub {
45            my $table = shift;
46            my $fkey = shift;
47            my $ref = shift;
48            "ALTER TABLE $table ADD FOREIGN KEY ($fkey) REFERENCES $ref;\n";
49        }
50  };  };
51    
52  $config{'^PostgreSQL 7\.2\.'} =  #
53    #  config for postgres 7.1
54    #   only difference is it doesn't have a bigserial type
55    #
56    $config{'^PostgreSQL 7\.1\.'} =
57  {  {
58      'driver' => $config{'^PostgreSQL 7\.1\.'}{'driver'},      'driver' => $config{'^PostgreSQL 7\.2\.'}{'driver'},
59      'datatypes' => {},      'datatypes' =>
60      'delay' => $config{'^PostgreSQL 7\.1\.'}{'delay'},      {
61            'bigserial' => 'serial',
62        },
63        'delay' => $config{'^PostgreSQL 7\.2\.'}{'delay'},
64        'relational' => $config{'^PostgreSQL 7\.2\.'}{'relational'},
65  };  };
66    
67  $config{'stdout'} =  $config{'stdout'} =
# Line 55  $config{'stdout'} = Line 69  $config{'stdout'} =
69      'driver' => sub { return "dbi:stdout:" },      'driver' => sub { return "dbi:stdout:" },
70      'datatypes' => {},      'datatypes' => {},
71      'delay' => sub { },      'delay' => sub { },
72        'relational' => $config{'^PostgreSQL 7\.1\.'}{'relational'},
73  };  };
74    
75  usage() if (@ARGV < 2);  usage() if (@ARGV < 2);
# Line 139  foreach my $table (sort keys %structure) Line 154  foreach my $table (sort keys %structure)
154      $config{$db_conf}{'delay'}->();      $config{$db_conf}{'delay'}->();
155  }  }
156    
157  foreach my $table (keys %structure)  if ($config{$db_conf}{'relational'})
158  {  {
159      foreach my $rel (keys %{ $structure{$table}{REL} })      foreach my $table (keys %structure)
160      {      {
161          my $sql = "ALTER TABLE $table ADD FOREIGN KEY ($rel) REFERENCES $structure{$table}{REL}{$rel};\n";          foreach my $rel (keys %{ $structure{$table}{REL} })
162          print $sql;          {
163          $db->do($sql);              my $sql = $config{$db_conf}{'relational'}->($table, $rel, $structure{$table}{REL}{$rel});
164          $config{$db_conf}{'delay'}->();              print $sql;
165                $db->do($sql);
166                $config{$db_conf}{'delay'}->();
167            }
168      }      }
169  }  }

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

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