[Catalyst] Transactions with mysql - can't locate db_Main
Ross Crawford
ross.crawford at gmail.com
Wed Jan 18 23:02:09 CET 2006
I'm using Class::DBI 3.0.13, it still calls:
$class->SUPER::set_db('Main', $data_source, $user, $password, $attr);
which *seems* to look like it should setup db_Main in IMA::DBI, but with
my limited knowledge of how these all fit together, I'm not really sure.
ROSCO
Jess Robinson wrote:
> 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
>>
>>
>
>
> _______________________________________________
> Catalyst mailing list
> Catalyst at lists.rawmode.org
> http://lists.rawmode.org/mailman/listinfo/catalyst
>
More information about the Catalyst
mailing list