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

Annotation of /bin/MasterDelTable

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (hide annotations)
Tue Aug 5 21:10:28 2003 UTC (20 years, 8 months ago) by dpavlin
Branch: MAIN
CVS Tags: before_onlytables, before_multmaster, r_0_3
Changes since 1.1: +22 -13 lines
command line options cleanup and cosistency fix, modification to work
under "use strict;"

1 dpavlin 1.2 #!/usr/bin/perl -w
2 dpavlin 1.1 # MasterAddTable
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 dpavlin 1.2 use strict;
12 dpavlin 1.1
13     $| = 1;
14    
15 dpavlin 1.2 my ($debug,$verbose) = (0,0);
16     my ($help,$masterhost,$masterport,$masteruser,$masterpassword);
17 dpavlin 1.1
18 dpavlin 1.2 my $result = GetOptions(
19     "debug!" => \$debug, "verbose!" => \$verbose, "help" => \$help,
20     "masterhost=s" => \$masterhost, "masterport=i" => \$masterport,
21     "masteruser=s" => \$masteruser, "masterpassword=s" => \$masterpassword,
22     );
23    
24     if (defined($help) || (scalar(@ARGV) < 2)) {
25     print "Usage: $0 [options] masterdb table
26     Options:
27     --masterhost=hostname --masterport=port
28     --masteruser=username --masterpassword=string
29     ";
30     exit ((scalar(@ARGV) < 2)? 1:0);
31 dpavlin 1.1 }
32    
33     my $dbname = $ARGV[0];
34     my $table = $ARGV[1];
35     #my $keyname = $ARGV[2];
36    
37     my $minfo = "dbname=$dbname";
38 dpavlin 1.2 $minfo = "$minfo host=$masterhost" if (defined($masterhost));
39     $minfo = "$minfo port=$masterport" if (defined($masterport));
40     $minfo = "$minfo user=$masteruser" if (defined($masteruser));
41     $minfo = "$minfo password=$masterpassword" if (defined($masterpassword));
42 dpavlin 1.1
43     my $conn = Pg::connectdb($minfo);
44     if ($conn->status != PGRES_CONNECTION_OK) {
45     print STDERR "Failed opening $minfo\n";
46     exit 1;
47     }
48    
49 dpavlin 1.2 $result = $conn->exec("BEGIN");
50 dpavlin 1.1 die $conn->errorMessage if $result->resultStatus ne PGRES_COMMAND_OK;
51    
52     $result = $conn->exec("DROP TRIGGER _RSERV_TRIGGER_T_ ON \"$table\"");
53     die $conn->errorMessage if $result->resultStatus ne PGRES_COMMAND_OK;
54    
55     $result = $conn->exec("DELETE FROM _RSERV_TABLES_ WHERE tname='$table'");
56     die $conn->errorMessage if $result->resultStatus ne PGRES_COMMAND_OK;
57    
58     $result = $conn->exec("COMMIT");
59     die $conn->errorMessage if $result->resultStatus ne PGRES_COMMAND_OK;
60    
61     exit(0);

  ViewVC Help
Powered by ViewVC 1.1.26