[Catalyst] Transactions with mysql - can't locate db_Main

Jess Robinson castaway at desert-island.demon.co.uk
Wed Jan 18 13:25:48 CET 2006


Which version of CDBI are you using? db_Main got renamed in later ones (to 
"connection", I think)

Jess

On Wed, 18 Jan 2006, Ross Crawford wrote:

> Hi all,
> 
> I'm a relative newbie to Catalyst. My application is using MySQL 4 with
> Model::CDBI, with AutoCommit=>1, and requires the use of transactions. I found
> this page http://wiki.class-dbi.com/wiki/Using_transactions which describes
> how to do it with Class::DBI, so I tried that basically unchanged, but when I
> execute do_transaction, I get the error:
> 
> Can't locate object method "db_Main" via package "jbrick::Model::jbrick" on
> the line:
> 
>        my $dbh = $class->db_Main;
> 
> jbrick::Model::jbrick is my CDBI class, where I have the do_transaction
> function.
> 
> If I comment out that line, and the line:
> 
>        local $dbh->{AutoCommit};
> 
> it works fine, but of course commits each SQL seperately. Here is the complete
> function, in case:
> 
> sub do_transaction {
>        my($class,$code, at args) = @_;
> 
>        $class->_invalid_object_method('do_transaction()') if ref($class);
> 
>        my @return_values = ();
>        my $dbh = $class->db_Main;
> 
>        # Localize AutoCommit database handle attribute
>        # and turn off for this block.
>        local $dbh->{AutoCommit};
> 
>        eval {
>        @return_values = $code->(@args);
>        $class->dbi_commit;
>        };
>        if ($@) {
>        my $error = $@;
>        eval { $class->dbi_rollback; };
>        if ($@) {
>        my $rollback_error = $@;
>        $class->_croak("Transaction aborted: $error; Rollback failed:
> $rollback_error\n");
>        } else {
>        $class->_croak("Transaction aborted (rollback successful): $error\n");
>        }
>        $class->clear_object_index;
>        return;
>        }
>        return(@return_values);
> }
> 
> _______________________________________________
> Catalyst mailing list
> Catalyst at lists.rawmode.org
> http://lists.rawmode.org/mailman/listinfo/catalyst
> 
> 



More information about the Catalyst mailing list