/[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.1 - (show annotations)
Wed Dec 20 17:22:35 2000 UTC (23 years, 4 months ago) by dpavlin
Branch: MAIN
Branch point for: DbP
Initial revision

1 # -*- perl -*-
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 Pg;
10 use Getopt::Long;
11
12 $| = 1;
13
14 $result = GetOptions("debug!", "verbose!", "help",
15 "host=s", "user=s", "password=s");
16
17 my $debug = $opt_debug || 0;
18 my $verbose = $opt_verbose || 0;
19
20 if (defined($opt_help) || (scalar(@ARGV) < 3)) {
21 print "Usage: $0 --host=name --user=name --password=string slavedb table column\n";
22 exit ((scalar(@ARGV) < 3)? 1: 0);
23 }
24
25 my $dbname = $ARGV[0];
26 my $table = $ARGV[1];
27 my $keyname = $ARGV[2];
28
29 my $sinfo = "dbname=$dbname";
30 $sinfo = "$sinfo host=$opt_host" if (defined($opt_host));
31 $sinfo = "$sinfo user=$opt_user" if (defined($opt_user));
32 $sinfo = "$sinfo password=$opt_password" if (defined($opt_password));
33
34 my $dbname = $ARGV[0];
35 my $table = $ARGV[1];
36 my $keyname = $ARGV[2];
37
38 my $conn = Pg::connectdb($sinfo);
39
40 my $result = $conn->exec("BEGIN");
41 die $conn->errorMessage if $result->resultStatus ne PGRES_COMMAND_OK;
42
43 $result = $conn->exec("select pgc.oid, pga.attnum from pg_class pgc" .
44 ", pg_attribute pga" .
45 " where pgc.relname = '$table' and pgc.oid = pga.attrelid" .
46 " and pga.attname = '$keyname'");
47 die $conn->errorMessage if $result->resultStatus ne PGRES_TUPLES_OK;
48
49 my @row = $result->fetchrow;
50 die "Can't find table/key\n" if ! defined $row[0] || ! defined $row[1];
51
52 $result = $conn->exec("insert into _RSERV_SLAVE_TABLES_ (tname, cname, reloid, key)" .
53 " values ('$table', '$keyname', $row[0], $row[1])");
54 die $conn->errorMessage if $result->resultStatus ne PGRES_COMMAND_OK;
55
56 $result = $conn->exec("COMMIT");
57 die $conn->errorMessage if $result->resultStatus ne PGRES_COMMAND_OK;
58
59 exit(0);

  ViewVC Help
Powered by ViewVC 1.1.26