foreach (@session) { $db->{_dbh}->{PrintError}=$main::opt_verbose; #supress errors unless verbose $db->prepare($select) or die("Unable to prepare SELECT"); $db->execute($_) or die("Unable to execute SELECT"); my $session = $kit->session(id=>$_, status=>'locked'); $log->say("Processing $_"); my $sth = $db->{_sth}; my @records = @{$sth->fetchall_arrayref}; SCRUB: my $inserted; my (@to_update, @skipped, @upd_error, @ins_error); $session->update($db); $log->say("Inserting rows..."); $log->indent; $db->prepare($insert) or die("Unable to prepare INSERT"); while (@records) { my @row = @{shift @records}; if ($db->execute(@row)) { print STDERR "."; #if ($main::opt_verbose); $inserted++; } else { print STDERR "o"; #if ($main::opt_verbose); push @to_update, \@row; push @ins_error, $db->errstr; chomp $ins_error[$#ins_error]; } }#-while : done inserting #Process to_update rows print STDERR "\n"; $log->unindent; $log->say("Inserted $inserted rows, now updating $#to_update rows."); $log->indent; $db->prepare($update); if (@{$map{options}{key}}) { foreach (@to_update) { #my $row = $_{row}; #never mind the errstr, for now. my @upd_params = @{$_}[0 .. $#{$map{options}{key}}]; if ($db->execute(@{$_}, @upd_params)) { print STDERR "."; # if ($main::opt_verbose); } else { print STDERR "o"; # if ($main::opt_verbose); push @skipped, $_; push @upd_error, $db->errstr; chomp $upd_error[$#upd_error]; } }#-for } else { @skipped = @to_update; for (@ins_error) { push @upd_error, ""; } #define @upd_error, to avoid later issues. }#-if $log->unindent; #Clean up if (@skipped) { open SKIPF, '>>', "session.skip" or $log->warn("Unable to record skipped lines to file"); print SKIPF "\n===> $_\n"; while (@skipped) { print SKIPF join(chr(9), shift @ins_error, shift @upd_error, @{shift @skipped})."\n"; } close SKIPF; $log->warn("$#skipped records thrown to skip file"); } else { push @skipped, 'none'; #allows $#skipped to be 0 } $log->say("Finished with $_, $inserted new rows, ".$#to_update-$#skipped." updated."); #-SCRUB