Subject: | database not included when using resultset |
Date: | Mon, 24 Sep 2012 14:20:10 -0400 |
To: | <bug-DBIx [...] rt.cpan.org> |
From: | "Lumsden Warren" <Warren.Lumsden [...] arbitron.com> |
Distribution: DBIx-Class-0.08200
Perl: 5.10.0
Platform: Darwin Kernel version 10.8.0; xnu-1504.15.3~1/RELEASE_I386 i386
Problem:
I have (many) a class that is defined to contain the database in the table name:
e.g.
package db::Schema::Result::Process;
use base qw/DBIx::Class::Core/;
__PACKAGE__->table( 'cluster.process' );
When using something like this that performs a command on the resultset:
$schema->resultset( 'Process' )->search( { host => 'test', name => 'test' }->delete();
...the table name does not appear in the query.
error: DBIx::Class::ResultSet::delete(): DBI Exception: DBD::mysql::st execute failed: No database selected [for Statement "DELETE FROM process WHERE ( ( host = ? AND name = ? ) )" with ParamValues: 0='test', 1='test'] at ....
I can do the following, and it does work fine, and apparently includes the dbname with the table, i.e., 'cluster.process';
my @procs = $schema->resultset( 'Process' )->search( { host => 'test', name => 'test' } );
for my $proc ( @procs )
{
$proc->delete();
}
I would prefer the first way, since it is cleaner code using it as a conversation, and should actually work according to documentation.
So in essence, there is a workaround. and this probably only effects those that don't connect to a specific dbname. We connect to 3 seperate dbname's within a db, which allows for more flexibility for replication. I'm pretty sure, that we are not alone in this practice.