Hello,
I'm using DBI with DBD::DB2 connecting to a DB2 database(who'd a thought)
I'd like to be able to delete several million rows with DBI and create a
generic subroutine to do it. (my transaction log doesn't hold several
million rows) I'd rather not commit after every row, but I don't know how
to write the $dbh->do statement to only commit a certain number of rows.
I can't find the DB2 equivalent of a oracle "TRUNCATE" statement.
this is what I have so far ...
sub SQLDelete
{
$table = uc $_[0];
$dbh->{AutoCommit} = 1;
print "Deleting table $table";
$rtn_cd =
$dbh->do("DELETE FROM $table");
print "$rtn_cd rows deleted";
}
this is my best guess on what I'm looking for (it doesn't work as is)
sub SQLDelete
{
my $count = 0;
$table = uc $_[0];
$dbh->{AutoCommit} = 0;
DBI->trace(1,"dbidel.log");
print "Deleting table $table\n";
$sth = $dbh->prepare("DELETE FROM $table");
$str=$sth->errstr();
while ((rtn = $sth->execute()) == -1)
{
$count++;
if ($count % $ROWS_BEFORE_COMMIT)
{
$dbh->commit;
}
}
$dbh->commit;
print "$count rows deleted";
DBI->trace(0,"dbidel.log");
$dbh->{AutoCommit} = 1;
}
Thanks for your assistance.
-Matt Johnson