<URL: https://rt.cpan.org/Ticket/Display.html?id=82814 >

A little more information about this long-standing bug (RT ticket 
#82814).

First, the change in behavior in SQL::Translator probably happened about 
2008 and involved wrapping transaction commit statements around the 
return value.  The problem was that if SQL::Translator's SQLite output 
module didn't find any actionable statements, it would still return 
begin transaction/commit statements, so your groovy fall-back code that 
would just use the INSERT didn't get a chance to work - it made it 
appear that SQL::Translator had translated them.

I didn't like the idea of cluttering your code with an explicit INSERT 
detector, so I've submitted a patch to the SQLite output module (with 
the agreement of the SQL::Translator maintainers) and hopefully that 
will be cleared up next time they post a new version to CPAN.

Once that was working, though, it revealed another problem with the 
tests - your scheme of letting the error for reinvocation of the setup 
fall through to the caller doesn't work any more.  I added a flag 
(already_called) and an explicit check for the flag, which also allows 
us to return a better error message.  Once the SQL::Translator patch is 
in the CPAN distro, this patch will allow Class::DBI::DATA::Schema to 
install cleanly again.

I've attached a patch to this bug report; alternatively, I've also set 
up a version update to 1.01 on Github at 
https://github.com/Vivtek/Class-DBI-DATA-Schema if you don't want to 
mess with it (in other words, I'm offering to take over co-maintainer 
status, which shouldn't make much difference, since honestly very little 
should ever need much maintenance in this module.)
*** Class-DBI-DATA-Schema-1.00/lib/Class/DBI/DATA/Schema.pm     2005-09-03 
22:19:23.000000000 +0200
--- Class-DBI-DATA-Schema/lib/Class/DBI/DATA/Schema.pm  2013-03-16 
20:39:41.744198600 +0100
***************
*** 120,134 ****
--- 120,139 ----
                chomp(my $sql = <$h>);
                return grep /\S/, split /;/, $translating ? $transform->($sql) 
: $sql;
        };
  
        my %cache;
+       
+       my $already_run = 0;
  
        no strict 'refs';
        *{"$caller\::run_data_sql"} = sub {
                my $class = shift;
+               die "Data SQL already run" if $already_run;
                no strict 'refs';
                $cache{$class} ||= [ $get_statements->(*{"$class\::DATA"}{IO}) 
];
                $class->db_Main->do($_) foreach @{ $cache{$class} };
+               $already_run = 1;
                return 1;
                }
  

Reply via email to