Commit info for scoop/lib/Scoop:

Modified Files:
      Tag: CURRENT
	DB.pm 
Log Message:
Adding basic transaction support to Scoop. Only supports version of MySQL >= 4,
of course. --j



Index: DB.pm
===================================================================
RCS file: /cvs/scoop/scoop/lib/Scoop/DB.pm,v
retrieving revision 1.21
retrieving revision 1.21.2.1
diff -r1.21 -r1.21.2.1
303a304,390
> # Add functions for transactions. Can only be used with versions of mysql
> # that use transactions, of course.
> 
> sub db_start_transaction {
>         my $S = shift;
>         my $args = shift;
> 
> 	unless ($S->{CONFIG}->{mysql_version} =~ /^4/) {
> 		return "Transactions not supported in this version of MySQL.\n";
> 		}
>         $Scoop::DB_QUERY_COUNT++ if ($Scoop::COUNT_DEBUG);
>                                                                                 
>         my $query = "START TRANSACTION";
>                                                                                 
>         if ($args->{DEBUG} || $DEBUG) {warn "in db_start_transaction: Query is $query\n"};
>                                                                                 
>         my $dbh;
>         if ($args->{ARCHIVE}) {
>                 $dbh = $S->{DBHARCHIVE};
>         } else {
>                 $dbh = $S->{DBH};
>         }
>         return('0E0',undef) unless ($dbh);
>                                                                                 
>         my $sth = $dbh->prepare($query);
>         my $rv = $sth->execute();
>                                                                                 
>         warn "<<ERROR>> in db_start_transaction: $DBI::errstr (Query is $query)\n" unless $rv;
>         return ($rv, $sth);
> }
> 
> sub db_commit {
>         my $S = shift;
>         my $args = shift;
>                                                                                 
> 	unless ($S->{CONFIG}->{mysql_version} =~ /^4/) {
>                 return "Transactions not supported in this version of MySQL.\n";
>                 }
>         $Scoop::DB_QUERY_COUNT++ if ($Scoop::COUNT_DEBUG);
>                                                                                 
>         my $query = "COMMIT";
>                                                                                 
>         if ($args->{DEBUG} || $DEBUG) {warn "in db_commit: Query is $query\n"};
>                                                                                 
>         my $dbh;
>         if ($args->{ARCHIVE}) {
>                 $dbh = $S->{DBHARCHIVE};
>         } else {
>                 $dbh = $S->{DBH};
>         }
>         return('0E0',undef) unless ($dbh);
>                                                                                 
>         my $sth = $dbh->prepare($query);
>         my $rv = $sth->execute();
>                                                                                 
>         warn "<<ERROR>> in db_commit: $DBI::errstr (Query is $query)\n" unless $rv;
>         return ($rv, $sth);
> }
> 
> sub db_rollback {
>         my $S = shift;
>         my $args = shift;
>                                                                                 
> 	unless ($S->{CONFIG}->{mysql_version} =~ /^4/) {
>                 return "Transactions not supported in this version of MySQL.\n";
>                 }
>         $Scoop::DB_QUERY_COUNT++ if ($Scoop::COUNT_DEBUG);
>                                                                                 
>         my $query = "ROLLBACK";
>                                                                                 
>         if ($args->{DEBUG} || $DEBUG) {warn "in db_rollback: Query is $query\n"};
>                                                                                 
>         my $dbh;
>         if ($args->{ARCHIVE}) {
>                 $dbh = $S->{DBHARCHIVE};
>         } else {
>                 $dbh = $S->{DBH};
>         }
>         return('0E0',undef) unless ($dbh);
>                                                                                 
>         my $sth = $dbh->prepare($query);
>         my $rv = $sth->execute();
>                                                                                 
>         warn "<<ERROR>> in db_rollback: $DBI::errstr (Query is $query)\n" unless $rv;
>         return ($rv, $sth);
> }
>