--- bin/MasterAddTable 2003/08/05 09:52:36 1.2 +++ bin/MasterAddTable 2003/08/05 21:10:28 1.3 @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/bin/perl -w # MasterAddTable # Vadim Mikheev, (c) 2000, PostgreSQL Inc. @@ -6,20 +6,28 @@ & eval 'exec perl -S $0 $argv:q' if 0; +use strict; use Pg; use Getopt::Long; $| = 1; -$result = GetOptions("debug!", "verbose!", "help", - "host=s", "user=s", "password=s"); +my ($debug,$verbose) = (0,0); +my ($help,$masterhost,$masterport,$masteruser,$masterpassword); -my $debug = $opt_debug || 0; -my $verbose = $opt_verbose || 0; - -if (defined($opt_help) || (scalar(@ARGV) < 3)) { - print "Usage: $0 --host=name --user=name --password=string masterdb table column\n"; - exit ((scalar(@ARGV) < 3)? 1: 0); +my $result = GetOptions( + "debug!" => \$debug, "verbose!" => \$verbose, "help" => \$help, + "masterhost=s" => \$masterhost, "masterport=i" => \$masterport, + "masteruser=s" => \$masteruser, "masterpassword=s" => \$masterpassword, + ); + +if (defined($help) || (scalar(@ARGV) < 3)) { + print "Usage: $0 [options] masterdb table column +Options: + --masterhost=hostname --masterport=port + --masteruser=username --masterpassword=string +"; + exit ((scalar(@ARGV) < 3)? 1:0); } my $dbname = $ARGV[0]; @@ -27,9 +35,10 @@ my $keyname = $ARGV[2]; my $minfo = "dbname=$dbname"; -$minfo = "$minfo host=$opt_host" if (defined($opt_host)); -$minfo = "$minfo user=$opt_user" if (defined($opt_user)); -$minfo = "$minfo password=$opt_password" if (defined($opt_password)); +$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)); my $conn = Pg::connectdb($minfo); if ($conn->status != PGRES_CONNECTION_OK) { @@ -37,7 +46,7 @@ exit 1; } -my $result = $conn->exec("BEGIN"); +$result = $conn->exec("BEGIN"); die $conn->errorMessage if $result->resultStatus ne PGRES_COMMAND_OK; $result = $conn->exec("select pgc.oid, pga.attnum from pg_class pgc" .