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

Chris Cole chris at compbio.dundee.ac.uk
Mon May 18 08:29:51 GMT 2009


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().

And this code:
my $species = $schema->resultset("Species");

$species->populate([
   { short_name => $shortName,
     full_name => $longName,
     common_name => $commonName }
]);

#$species->update();

generates this error:
Issuing rollback() for database handle being DESTROY'd without explicit
disconnect().

Neither code actually updates the DB. So, regardless of the errors and
whether it is 'The Right THing To do' or not how on Earth am I supposed
to add data to the DB with autocommit set to 'off'?

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.





More information about the DBIx-Class mailing list