From: <rv...@us...> - 2009-06-11 07:54:15
|
Revision: 40 http://treebase.svn.sourceforge.net/treebase/?rev=40&view=rev Author: rvos Date: 2009-06-11 07:54:14 +0000 (Thu, 11 Jun 2009) Log Message: ----------- Factored out insert statement printing to separate subroutine 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-11 07:41:26 UTC (rev 39) +++ trunk/treebase-core/src/main/perl/dump/sqldump 2009-06-11 07:54:14 UTC (rev 40) @@ -81,40 +81,15 @@ } $dumper->set_output($outhandle); + # write create table statements if ( $with_creates ) { - print $outhandle "CREATE TABLE $table;\n"; + my $uc_table = uc $table; + print $outhandle "CREATE TABLE $uc_table;\n"; } + # write insert statements if ( $with_inserts ) { - # get all rows from $table - my $q = qq{select * from $table}; - my $sth = $dbh->prepare($q); - $sth->execute(); - - my $row; - - # if --progress is provided, print out progress counter - if ( $with_progress_meter ) { - my $count = 0; - while ( $row = $sth->fetchrow_arrayref ) { - ++$count; - $dumper->rec(@$row); - print STDERR "\r$count" if $count % 1000 == 0; - } - } - - # if --noprogress or default, just dump the records - else { - while ( $row = $sth->fetchrow_arrayref ) { - $dumper->rec(@$row); - } - } - - # finish the statement handler - $sth->finish(); - - # add line break if we're printing a progress counter - print STDERR "\n" if $with_progress_meter; + print_insert_statements ($dumper, $dbh, $table); } } @@ -141,3 +116,37 @@ $dbh->{'RaiseError'} = 1; return $dbh; } + +sub print_insert_statements { + my ( $dumper, $dbh, $table ) = @_; + + # get all rows from $table + my $q = qq{select * from $table}; + my $sth = $dbh->prepare($q); + $sth->execute(); + + my $row; + + # if --progress is provided, print out progress counter + if ($with_progress_meter) { + my $count = 0; + while ( $row = $sth->fetchrow_arrayref ) { + ++$count; + $dumper->rec(@$row); + print STDERR "\r$count" if $count % 1000 == 0; + } + } + + # if --noprogress or default, just dump the records + else { + while ( $row = $sth->fetchrow_arrayref ) { + $dumper->rec(@$row); + } + } + + # finish the statement handler + $sth->finish(); + + # add line break if we\'re printing a progress counter + print STDERR "\n" if $with_progress_meter; +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |