Subject: | select_val broken if db set with db_Main |
In Class::DBI 0.95, setting up the DB connection by overriding db_Main breaks Ima::DBI->select_val and the methods that rely on it (like sequence and count_all), causing this error:
Can't locate object method "select_val" via package "DBI::st" (perhaps you forgot to load "DBI::st"?) at /usr/lib/perl5/site_perl/5.6.1/Class/DBI.pm line 1109.
This does not occur in 0.94.
The attached test takes an optional command line argument to cause it to use the db_Main method instead of the set_db method for DB setup; this causes it to fail with 0.95 but not with 0.94.
I have replicated this under Red Hat with 5.6.1 and Mac OS X 10.2 with 5.6.0.
Randall
#!/usr/bin/perl -w
$::failme = scalar @::ARGV;
#######################
package Container;
use base 'Class::DBI';
use strict;
use DBI;
unlink ("broken95") if -e "broken95";
@Container::DSN = ("dbi:SQLite:dbname=broken95", '', '', { AutoCommit => 1 } );
$Container::dbh = DBI->connect(@Container::DSN)
or die "could not connect: $!";
## set_db works:
__PACKAGE__->set_db(Main => @Container::DSN)
unless $::failme;
## db_Main does not work:
eval {
sub Container::db_Main {
return DBI->connect(@Container::DSN);
}
} if $::failme;
__PACKAGE__->table('sp_container');
__PACKAGE__->columns( All => qw/ id sandbox_id / );
__PACKAGE__->columns( Essential => qw/ id sandbox_id / );
1;
#######################
package main;
use strict;
Container->db_Main()->do( " create table sp_container ( id int, sandbox_id int ) " );
my $c = Container->create( { sandbox_id => 12345 } );
warn "got count all (should be 1) = " . Container->count_all;
__END__
=head1 USAGE
perl break95.pl
(should be OK)
perl break95.pl fail
Can't locate object method "select_val" via package "DBI::st" (perhaps you forgot to load "DBI::st"?) at /usr/lib/perl5/site_perl/5.6.1/Class/DBI.pm line
1109.
(any arguments; causes select_val error to appear)
=head1 SYNOPSIS
Discrepancy between Class::DBI 0.94 and 0.95.
select_val (which underlies count_all and the sequence functionality) does not work if the DBH is set
with db_Main(), but does work if it is set with set_db. This happens only under 0.95 and not 0.94.