From: <mjd...@us...> - 2009-06-23 19:47:15
|
Revision: 86 http://treebase.svn.sourceforge.net/treebase/?rev=86&view=rev Author: mjdominus Date: 2009-06-23 19:46:27 +0000 (Tue, 23 Jun 2009) Log Message: ----------- add --where and --nrecs options Modified Paths: -------------- trunk/treebase-core/src/main/perl/dump/sqldump Modified: trunk/treebase-core/src/main/perl/dump/sqldump =================================================================== --- trunk/treebase-core/src/main/perl/dump/sqldump 2009-06-23 11:14:09 UTC (rev 85) +++ trunk/treebase-core/src/main/perl/dump/sqldump 2009-06-23 19:46:27 UTC (rev 86) @@ -15,7 +15,8 @@ my $schema = 'TBASE2'; # name of schema to analyze my $zip = 0; # zip output my $test = 0; # test run: delete produced files - +my $nrecs; # max number of recs per table +my $where = ""; # WHERE clause to select dumped records # get command line options, see Getopt::Long GetOptions( 'name-after-table' => \$name_file_after_table, @@ -28,6 +29,8 @@ 'table=s' => \@tables, 'zip' => \$zip, 'test' => \$test, + 'nrecs=i' => \$nrecs, + 'where=s' => \$where, 'all' => sub { @tables = get_all_tables() }, 'help|?' => sub { pod2usage( '-verbose' => 0 ) }, # see Pod::Usage 'man' => sub { pod2usage( '-verbose' => 1 ) }, # see Pod::Usage @@ -58,6 +61,10 @@ '-msg' => 'Need at least one operation to write out (--inserts and/or --creates), aborting' ) unless $with_creates or $with_inserts; +# prepend $where clause with WHERE unless it has that already, +# or there was none. +$where = "WHERE $where" unless $where =~ /^\s*$/ || $where =~ /^\s*where\b/i; + { # create database handle my $dbh = get_handle(); @@ -149,6 +156,7 @@ # get all rows from $table my $q = qq{select * from $table}; + $q .= " " . $where if $where; my $sth = $dbh->prepare($q); $sth->execute(); @@ -168,6 +176,7 @@ else { while ( $row = $sth->fetchrow_arrayref ) { $dumper->rec(@$row); + last if defined($nrecs) && (--$nrecs == 0); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mjd...@us...> - 2009-06-23 19:55:02
|
Revision: 87 http://treebase.svn.sourceforge.net/treebase/?rev=87&view=rev Author: mjdominus Date: 2009-06-23 19:54:51 +0000 (Tue, 23 Jun 2009) Log Message: ----------- add --maxlen option and increase size of dumpable records to default to 5MB Modified Paths: -------------- trunk/treebase-core/src/main/perl/dump/sqldump Modified: trunk/treebase-core/src/main/perl/dump/sqldump =================================================================== --- trunk/treebase-core/src/main/perl/dump/sqldump 2009-06-23 19:46:27 UTC (rev 86) +++ trunk/treebase-core/src/main/perl/dump/sqldump 2009-06-23 19:54:51 UTC (rev 87) @@ -17,6 +17,8 @@ my $test = 0; # test run: delete produced files my $nrecs; # max number of recs per table my $where = ""; # WHERE clause to select dumped records +my $maxlen = 5 * 1024 * 1024; # Maximum field length: 5 MB by default + # get command line options, see Getopt::Long GetOptions( 'name-after-table' => \$name_file_after_table, @@ -28,6 +30,7 @@ 'dsn=s' => \$ENV{'TREEBASE_DB_DSN'}, 'table=s' => \@tables, 'zip' => \$zip, + 'maxlen=i' => \$maxlen, 'test' => \$test, 'nrecs=i' => \$nrecs, 'where=s' => \$where, @@ -68,6 +71,7 @@ { # create database handle my $dbh = get_handle(); + $dbh->{LongReadLen} = $maxlen; # Handle LOBs up to $maxlen bytes for my $table ( @tables ) { # only using these two functions once, so for clarity as to where they This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mjd...@us...> - 2009-06-23 20:08:11
|
Revision: 88 http://treebase.svn.sourceforge.net/treebase/?rev=88&view=rev Author: mjdominus Date: 2009-06-23 20:07:19 +0000 (Tue, 23 Jun 2009) Log Message: ----------- improved progress meter reports percentage done Modified Paths: -------------- trunk/treebase-core/src/main/perl/dump/sqldump Modified: trunk/treebase-core/src/main/perl/dump/sqldump =================================================================== --- trunk/treebase-core/src/main/perl/dump/sqldump 2009-06-23 19:54:51 UTC (rev 87) +++ trunk/treebase-core/src/main/perl/dump/sqldump 2009-06-23 20:07:19 UTC (rev 88) @@ -74,11 +74,10 @@ $dbh->{LongReadLen} = $maxlen; # Handle LOBs up to $maxlen bytes for my $table ( @tables ) { - # only using these two functions once, so for clarity as to where they - # originate let's use the fully qualified names. + my @names = CIPRES::TreeBase::DBIUtil::get_colnames($dbh, $table); my @types = CIPRES::TreeBase::DBIUtil::get_coltypes($dbh, $table); - + # instantiate a RecDumper object, which will format a row-as-array # into an insert statement my $dumper = CIPRES::TreeBase::RecDumper->new( @@ -168,11 +167,17 @@ # if --progress is provided, print out progress counter if ($with_progress_meter) { + my ($total_records) = @{$dbh->selectcol_arrayref(qq{select count(*) from $table})}; + $total_records = $nrecs if defined($nrecs) && $nrecs < $total_records; my $count = 0; + my $old_percent = ""; while ( $row = $sth->fetchrow_arrayref ) { ++$count; $dumper->rec(@$row); - print STDERR "\r$count" if $count % 1000 == 0; + my $percent = int(0.5 + $count / $total_records * 100); + print STDERR "\r$percent%" if $percent ne $old_percent; + $old_percent = $percent; + last if defined($nrecs) && (--$nrecs == 0); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mjd...@us...> - 2009-07-01 21:01:14
|
Revision: 155 http://treebase.svn.sourceforge.net/treebase/?rev=155&view=rev Author: mjdominus Date: 2009-07-01 21:00:18 +0000 (Wed, 01 Jul 2009) Log Message: ----------- bug fix Modified Paths: -------------- trunk/treebase-core/src/main/perl/dump/sqldump Modified: trunk/treebase-core/src/main/perl/dump/sqldump =================================================================== --- trunk/treebase-core/src/main/perl/dump/sqldump 2009-07-01 20:56:13 UTC (rev 154) +++ trunk/treebase-core/src/main/perl/dump/sqldump 2009-07-01 21:00:18 UTC (rev 155) @@ -178,7 +178,8 @@ my $percent = int(0.5 + $count / $total_records * 100); print STDERR "\r$percent%" if $percent ne $old_percent; $old_percent = $percent; - last if defined($nrecs) && ++$rows_printed >= $nrecs; + ++$rows_printed; + last if defined($nrecs) && $rows_printed >= $nrecs; } } @@ -186,7 +187,8 @@ else { while ( $row = $sth->fetchrow_arrayref ) { $dumper->rec(@$row); - last if defined($nrecs) && ++$rows_printed >= $nrecs; + ++$rows_printed; + last if defined($nrecs) && $rows_printed >= $nrecs; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |