/[rserv]/bin/MasterAddTable
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /bin/MasterAddTable

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

revision 1.6 by dpavlin, Wed Oct 29 18:00:18 2003 UTC revision 1.8 by dpavlin, Sun Nov 2 10:31:44 2003 UTC
# Line 6  eval '(exit $?0)' && eval 'exec perl -S Line 6  eval '(exit $?0)' && eval 'exec perl -S
6      & eval 'exec perl -S $0 $argv:q'      & eval 'exec perl -S $0 $argv:q'
7      if 0;      if 0;
8    
9    BEGIN {
10            my $basedir = $0; $basedir =~ s#/[^/]+$##;
11            unshift(@INC, "$basedir/../share");
12    }
13    
14  use strict;  use strict;
15  use Pg;  use Pg;
16  use Getopt::Long;  use Getopt::Long;
17    use RServ;
18    
19  $| = 1;  $| = 1;
20    
# Line 38  my $dbname = $ARGV[0]; Line 44  my $dbname = $ARGV[0];
44  my $table = $ARGV[1];  my $table = $ARGV[1];
45  my $keyname = $ARGV[2];  my $keyname = $ARGV[2];
46    
47  my $minfo = "dbname=$dbname";  my $minfo = MkInfo($dbname,$masterhost,$masterport,$masteruser,$masterpassword);
 $minfo = "$minfo host=$masterhost" if (defined($masterhost));  
 $minfo = "$minfo port=$masterport" if (defined($masterport));  
 $minfo = "$minfo user=$masteruser" if (defined($masteruser));  
 $minfo = "$minfo password=$masterpassword" if (defined($masterpassword));  
48    
49  print STDERR "master server nr: $mserver\n" if ($debug);  print STDERR "master server nr: $mserver\n" if ($debug);
50    
51  my $conn = Pg::connectdb($minfo);  my $mconn = Pg::connectdb($minfo);
52  if ($conn->status != PGRES_CONNECTION_OK) {  if ($mconn->status != PGRES_CONNECTION_OK) {
53      print STDERR "Failed opening $minfo\n";      print STDERR "Failed opening $minfo\n";
54      exit 1;      exit 1;
55  }  }
56    
57  $result = $conn->exec("BEGIN");  $result = $mconn->exec("BEGIN");
58  die $conn->errorMessage if $result->resultStatus ne PGRES_COMMAND_OK;  die $mconn->errorMessage if $result->resultStatus ne PGRES_COMMAND_OK;
59    
60  $result = $conn->exec("select pgc.oid, pga.attnum from pg_class pgc" .  $result = $mconn->exec("select pgc.oid, pga.attnum from pg_class pgc" .
61                        ", pg_attribute pga where pgc.relname = '$table'" .                        ", pg_attribute pga where pgc.relname = '$table'" .
62                        " and pgc.oid = pga.attrelid" .                        " and pgc.oid = pga.attrelid" .
63                        " and pga.attname = '$keyname'");                        " and pga.attname = '$keyname'");
64  die $conn->errorMessage if $result->resultStatus ne PGRES_TUPLES_OK;  die $mconn->errorMessage if $result->resultStatus ne PGRES_TUPLES_OK;
65    
66  my @row = $result->fetchrow;  my @row = $result->fetchrow;
67  die "Can't find key '$keyname' for table '$table' in database '$dbname'\n" if ! defined $row[0] || ! defined $row[1];  die "Can't find key '$keyname' for table '$table' in database '$dbname'\n" if ! defined $row[0] || ! defined $row[1];
68    
69  $result = $conn->exec("create trigger _RSERV_TRIGGER_T_ after" .  $result = $mconn->exec("create trigger _RSERV_TRIGGER_T_ after" .
70                        " insert or update or delete on \"$table\"" .                        " insert or update or delete on \"$table\"" .
71                        " for each row execute procedure" .                        " for each row execute procedure" .
72                        " _rserv_log_('$row[1]',$mserver)");                        " _rserv_log_('$row[1]',$mserver)");
73  die $conn->errorMessage if $result->resultStatus ne PGRES_COMMAND_OK;  die $mconn->errorMessage if $result->resultStatus ne PGRES_COMMAND_OK;
74    
75  $result = $conn->exec("insert into _RSERV_TABLES_ (tname, cname, reloid, key)" .  $result = $mconn->exec("insert into _RSERV_TABLES_ (tname, cname, reloid, key)" .
76                        " values ('$table', '$keyname', $row[0], $row[1])");                        " values ('$table', '$keyname', $row[0], $row[1])");
77  die $conn->errorMessage if $result->resultStatus ne PGRES_COMMAND_OK;  die $mconn->errorMessage if $result->resultStatus ne PGRES_COMMAND_OK;
78    
79  $result = $conn->exec("COMMIT");  $result = $mconn->exec("COMMIT");
80  die $conn->errorMessage if $result->resultStatus ne PGRES_COMMAND_OK;  die $mconn->errorMessage if $result->resultStatus ne PGRES_COMMAND_OK;
81    
82  exit(0);  exit(0);

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.8

  ViewVC Help
Powered by ViewVC 1.1.26