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

Contents of /bin/SlaveAddTable

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (show annotations)
Tue Aug 5 21:10:28 2003 UTC (20 years, 9 months ago) by dpavlin
Branch: MAIN
Changes since 1.3: +22 -17 lines
command line options cleanup and cosistency fix, modification to work
under "use strict;"

1 #!/usr/bin/perl -w
2 # SlaveAddTable
3 # Vadim Mikheev, (c) 2000, PostgreSQL Inc.
4
5 eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}'
6 & eval 'exec perl -S $0 $argv:q'
7 if 0;
8
9 use strict;
10 use Pg;
11 use Getopt::Long;
12
13 $| = 1;
14
15 my ($debug,$verbose) = (0,0);
16 my ($help,$slavehost,$slaveport,$slaveuser,$slavepassword);
17
18 my $result = GetOptions(
19 "debug!" => \$debug, "verbose!" => \$verbose, "help" => \$help,
20 "slavehost=s" => \$slavehost, "slaveport=i" => \$slaveport,
21 "slaveuser=s" => \$slaveuser, "slavepassword=s" => \$slavepassword,
22 );
23
24 if (defined($help) || (scalar(@ARGV) < 3)) {
25 print "Usage: $0 [options] slavedb table column
26 Options:
27 --slavehost=hostname --slaveport=port
28 --slaveuser=username --slavepassword=string
29 ";
30 exit ((scalar(@ARGV) < 3)? 1:0);
31 }
32
33 my $dbname = $ARGV[0];
34 my $table = $ARGV[1];
35 my $keyname = $ARGV[2];
36
37 my $sinfo = "dbname=$dbname";
38 $sinfo = "$sinfo host=$slavehost" if (defined($slavehost));
39 $sinfo = "$sinfo port=$slaveport" if (defined($slaveport));
40 $sinfo = "$sinfo user=$slaveuser" if (defined($slaveuser));
41 $sinfo = "$sinfo password=$slavepassword" if (defined($slavepassword));
42
43 my $conn = Pg::connectdb($sinfo);
44 if ($conn->status != PGRES_CONNECTION_OK) {
45 print STDERR "Failed opening $sinfo\n";
46 exit 1;
47 }
48
49 $result = $conn->exec("BEGIN");
50 die $conn->errorMessage if $result->resultStatus ne PGRES_COMMAND_OK;
51
52 $result = $conn->exec("select pgc.oid, pga.attnum from pg_class pgc" .
53 ", pg_attribute pga" .
54 " where pgc.relname = '$table' and pgc.oid = pga.attrelid" .
55 " and pga.attname = '$keyname'");
56 die $conn->errorMessage if $result->resultStatus ne PGRES_TUPLES_OK;
57
58 my @row = $result->fetchrow;
59 die "Can't find table/key\n" if ! defined $row[0] || ! defined $row[1];
60
61 $result = $conn->exec("insert into _RSERV_SLAVE_TABLES_ (tname, cname, reloid, key)" .
62 " values ('$table', '$keyname', $row[0], $row[1])");
63 die $conn->errorMessage if $result->resultStatus ne PGRES_COMMAND_OK;
64
65 $result = $conn->exec("COMMIT");
66 die $conn->errorMessage if $result->resultStatus ne PGRES_COMMAND_OK;
67
68 exit(0);

  ViewVC Help
Powered by ViewVC 1.1.26