[Dbix-class] Problem with populate() and commits?

Peter Rabbitson rabbit+dbic at rabbit.us
Mon May 18 09:18:51 GMT 2009


Chris Cole wrote:
> Peter Rabbitson wrote:
>> Chris Cole wrote:
>>> Hi,
>>>
>>> Given this schema:
> 
> [snip]
>>> and this code:
>>> my $schema = DB::Schema->connect(stuff);
>>>
>>> my $species = $schema->resultset("Species");
>>>
>>> $species->populate([
>>>    { short_name => $shortName,
>>>      full_name => $longName,
>>>      common_name => $commonName }
>>> ]);
>>>
>>> Why does it work fine when I have Autocommit 'on', but get the following
>>> error with Autocommit 'off':
>>> DBIx::Class::ResultSet::update(): Values for update must be a hash at
>>> ./add_species.pl line 46
>>> Issuing rollback() for database handle being DESTROY'd without explicit
>>> disconnect().
>>>
>>> where line 46 is:
>>> $species->update();
>>>
>>> I don't get it??
>>>
>> This is still strange - you shouldn't be getting internal code exception
>> without autocommit - it is immaterial at that point. You are saying that
>> line 46 is an update() but there is no update in the code above. Which one
>> is it?
> 
> Well, I removed the update() from the working code where I don't get the
> error, as it's clearly superfluous.
> 
> To clarify. With autocommit 'off', this code:
> my $species = $schema->resultset("Species");
> 
> $species->populate([
>    { short_name => $shortName,
>      full_name => $longName,
>      common_name => $commonName }
> ]);
> 
> $species->update();
> 
> generates this error:
> DBIx::Class::ResultSet::update(): Values for update must be a hash at
> ./add_species.pl line 46
> Issuing rollback() for database handle being DESTROY'd without explicit
> disconnect().

Yes, because $species is a resultset, so you are calling resultset update[1],
which not surprisingly expects a set of column values to update.

> It seems that the only way to achieve anything with DBIx is to set
> autocommit to 'on'. This contradicts the implied transaction handling in
> the 'Intro' POD which talks about committing changes to the DB. At the
> very least a note needs adding to the docs regarding DBIx's non-use of
> transactions.
> 

I am not sure which part is it that you find contradicting. Please point
out actual snippets, or even better - provide documentation patches :)

[1] http://search.cpan.org/~ribasushi/DBIx-Class-0.08102/lib/DBIx/Class/ResultSet.pm#update



More information about the DBIx-Class mailing list