Sorry it took me awhile to get to this. It’s longish but thread is dead so I’m skipping <readmore/>. Transactions are great and trivial to use and even nest with DBIx::Class; DBIx::Class::Storage::TxnScopeGuard. You can generate a schema from an existing DB—DBIx::Class::Schema::Loader—so you don’t have to write the BEGIN style code; it’s only there for an encapsulated example.

#!/usr/bin/env perl use strictures; use 5.010; BEGIN { # Sample packages. package MyApp::Schema::Address { use parent "DBIx::Class::Core"; __PACKAGE__->table("address"); __PACKAGE__->add_columns( id => { data_type => 'integer', is_auto_increment => 1 }, address => { data_type => 'varchar', size => '100' } ); __PACKAGE__->set_primary_key("id"); }; package MyApp::Schema { use parent "DBIx::Class::Schema"; # For real -> __PACKAGE__->use_namespaces; __PACKAGE__->load_classes("Address"); # <- For this example. }; } my $use_transaction = shift; say "Doing it ", $use_transaction ? "with" : "without", " transaction. +"; my $schema = MyApp::Schema->connect("dbi:SQLite::memory:"); $schema->deploy; # Create some addresses. my $addresses = $schema->resultset("Address"); for ( 1 .. 10 ) { $addresses->create({ address => "$_ Street" }); } my $count = $addresses->count; eval { $use_transaction ? process_with_txn_guard() : process_without_txn_guard(); }; if ( $@ ) { print "We had an error! $@"; say "We have ", $addresses->count, " left in the DB"; say "Sucks to be you..." unless $count == $addresses->count; } exit 0; sub process_without_txn_guard { for my $address ( $addresses->all ) { # Do some local processing with $address. say "Deleting ", $address->address; $address->delete; die "Bad stars" if rand(1) > .8; # Intermittent failure. } # Do remote "global" processing with all addresses. } sub process_with_txn_guard { my $guard = $schema->txn_scope_guard; process_without_txn_guard(); $guard->commit; } __END__ moo@cow~>pm-1142097 Doing it without transaction. Deleting 1 Street Deleting 2 Street Deleting 3 Street We had an error! Bad stars at pm-1142097 line 57. We have 8 left in the DB Sucks to be you... moo@cow~>pm-1142097 with_txn Doing it with transaction. Deleting 1 Street Deleting 2 Street Deleting 3 Street We had an error! Bad stars at pm-1142097 line 58. We have 10 left in the DB

In reply to Re: DBI and sqlite concurrency by Your Mother
in thread DBI and sqlite concurrency by MorayJ

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.