From: <mjd...@us...> - 2009-06-26 15:42:12
|
Revision: 132 http://treebase.svn.sourceforge.net/treebase/?rev=132&view=rev Author: mjdominus Date: 2009-06-26 15:41:18 +0000 (Fri, 26 Jun 2009) Log Message: ----------- add -w (where-clause) option Modified Paths: -------------- trunk/treebase-core/src/main/perl/dump/td Modified: trunk/treebase-core/src/main/perl/dump/td =================================================================== --- trunk/treebase-core/src/main/perl/dump/td 2009-06-26 03:57:57 UTC (rev 131) +++ trunk/treebase-core/src/main/perl/dump/td 2009-06-26 15:41:18 UTC (rev 132) @@ -4,7 +4,8 @@ use Getopt::Std; my %opt; -getopts('1', \%opt) or usage(); +getopts('1w:', \%opt) or usage(); +if ($opt{1} && $opt{w}) { usage(); } my $table = shift || usage(); @@ -12,6 +13,7 @@ or die "Couldn't connect to database: " . DBI->errstr; my $q = "SELECT * FROM $table"; $q .= " where 1 = 0" if $opt{1}; +$q .= " where $opt{w}" if $opt{w}; my $sth = $dbh->prepare($q) or die "Couldn't prepare statement: " . $dbh->errstr; my $rc = $sth->execute() @@ -27,13 +29,15 @@ exit; } -if (@rows || $opt{1}) { +if (@rows) { print_aoh(\@rows, "--"); } else { - print "Empty table.\n"; + print $opt{w} ? "No rows selected.\n" : "Empty table.\n"; } sub usage { - print "$0 table-name\n"; + print "$0 [-1] [-w where-clause] table-name\n"; + print "\t-1: only print column names, in order\n"; + print "\t-w: dump rows satisfying specified condition\n"; exit 1; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |