Skip Menu |

This queue is for tickets about the Class-DBI CPAN distribution.

Report information
The Basics
Id: 5522
Status: resolved
Priority: 0/
Queue: Class-DBI

People
Owner: Nobody in particular
Requestors: rlucas [...] tercent.com
Cc:
AdminCc:

Bug Information
Severity: Unimportant
Broken in: 0.95
Fixed in: 0.94



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.
Date: Tue, 2 Mar 2004 11:52:12 +0000
From: Tony Bowden <tony [...] kasei.com>
To: Guest via RT <bug-Class-DBI [...] rt.cpan.org>
Subject: Re: [cpan #5522] select_val broken if db set with db_Main
RT-Send-Cc:
On Mon, Mar 01, 2004 at 06:42:38PM -0500, Guest via RT wrote: Show quoted text
> 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)
You need to call Ima::DBI->connect rather than DBI->connect in your overriden db_Main. Tony
From: rlucas [...] tercent.com
--- DBI.pm 2004-01-09 10:41:30.000000000 -0500 +++ /DBI.pm 2004-03-02 16:05:33.000000000 -0500 @@ -1538,8 +1538,10 @@ schema to not have to duplicate an entire class hierarchy. The preferred method for doing this is to supply your own db_Main() -method rather than calling L<\set_db>(). This method should return a valid -database handle, and should set the standard attributes described above. +method rather than calling L<\set_db>(). This method must return a valid +L<Ima::DBI> database handle, and should set the standard attributes +described above. Note that supplying a DBI connection is insufficient; +the object returned must be of the class Ima::DBI. Note however that this is class data, and that changing it may have unexpected behaviour for instances of the class already in existence.
Date: Wed, 3 Mar 2004 15:28:20 +0000
From: Tony Bowden <tony [...] kasei.com>
To: Guest via RT <bug-Class-DBI [...] rt.cpan.org>
Subject: Re: [cpan #5522] select_val broken if db set with db_Main
RT-Send-Cc:
On Tue, Mar 02, 2004 at 04:08:41PM -0500, Guest via RT wrote: Show quoted text
> The preferred method for doing this is to supply your own db_Main() > -method rather than calling L<\set_db>(). This method should return a valid > -database handle, and should set the standard attributes described above. > +method rather than calling L<\set_db>(). This method must return a valid > +L<Ima::DBI> database handle, and should set the standard attributes > +described above. Note that supplying a DBI connection is insufficient; > +the object returned must be of the class Ima::DBI.
Thanks. The reason this broke in going from 0.94 to 0.95, btw, is that the select_val stuff was only added to Ima::DBI recently, so Class::DBI .94 didn't use these, but instead rolled its own long winded versions. 0.95 uses the new methods in Ima::DBI and is a lot better off for it! :) Tony