Hello,

DBD::SQLite::VERSION 1.12
DBIx::Class::VERSION 0.07001

I'm running a script to patch an error in my database. It loops over
each bad row and fixes it, and works fine, except that it requires me to
have
$data->storage->disconnect();
at the end of it, otherwise I get this message:
Issuing rollback() for database handle being DESTROY'd without explicit
disconnect().

Is there a DBIx close() or disconnect() type of method I should be
calling? It seems a bit wrong to be calling methods directly on the
storage? I haven't seen it needed in any examples ...

Steven

== script that I am running: PatchPtid.pl ===

my $db_filename = shift;

use HousePrices::Schema;
my $data =
  HousePrices::Schema->connect(
    "dbi:SQLite:$db_filename" , undef , undef ,
    {
      AutoCommit => 0, # ... so use txn_begin to start transactions
      RaiseError => 1  # raise exceptions on error
    }
  );

my $delisted =
$data->resultset('Availability')->find({Status=>'HP_DELISTED'});
my @mpd_rows = $delisted->search_related('marketedPropertyDetails');
# ... pull all rows in to an array instead of using an iterator
# because SQLite will not let us update the DB inside an iterator loop.

$data->txn_begin();
foreach my $mpd (@mpd_rows)
{
  my $previous_observation =
   $data->resultset('MarketedPropertyDetails')->search_literal(
    "mpid = ? and (avid != ? or avid is NULL) order by SeenOnDate desc
limit 1",
    $mpd->mpid(), $delisted->avid() )->single();
  
  die "No previous observation for ".$mpd->mpid() if(
!$previous_observation );
  
  if( $previous_observation->ptid() )
  {
    $mpd->ptid( $previous_observation->ptid );
    print "--updated mpid: ".$mpd->mpid." ptid: ".$mpd->ptid."\n";
    $mpd->update();
  }
}
$data->txn_commit();

my $mpd_still_null = $delisted->search_related('marketedPropertyDetails',
                                         {ptid => undef})->count;
print "$mpd_still_null MarketedPropertyDetails rows were not updated.\n"; 

#$data->storage->disconnect();
#Issuing rollback() for database handle being DESTROY'd without explicit
# disconnect().



_______________________________________________
List: http://lists.rawmode.org/cgi-bin/mailman/listinfo/dbix-class
Wiki: http://dbix-class.shadowcatsystems.co.uk/
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/trunk/DBIx-Class/
Searchable Archive: http://www.mail-archive.com/[email protected]/

Reply via email to