[Dbix-class] trouble using search

jagdish eashwar jagdish.eashwar at gmail.com
Thu Nov 8 12:44:03 GMT 2007


Hi,
I am sufficiently familiar with SQL, but am new to DBIC. In DBIC, I am
able to use 'find', but not 'search'. To find out where exactly I am
going wrong, I created a table called 'family' with one column called
'name' in a mysql database called 'dbic'. I then inserted the names of
the members of my family (jagdish,sushama,manasi,ninad) in it . Then I
created two files called 'Main.pm' and 'Family.pm' in a directory
called 'Testdb' as shown below:

package Testdb::Main;
use base qw/DBIx::Class::Schema/;
__PACKAGE__->load_classes(qw/Family/);

1;

package Testdb::Main::Family;
use base qw/DBIx::Class/;
__PACKAGE__->load_components(qw/PK::Auto Core/);
__PACKAGE__->table('family');
__PACKAGE__->add_columns(qw/name/);
__PACKAGE__->set_primary_key('name');

1;

Then I ran the following 'find' and 'search' scripts:

#!/usr/bin/perl
#FIND SCRIPT

use Testdb::Main;
use warnings;
use strict;

my $schema = Testdb::Main->connect('dbi:mysql:dbic','jag','passwd');
my $names = $schema->resultset('Family')->find({name => 'sushama'});
my $name = $names->name;
print "$name\n";

It printed 'sushama' as expected.


#!/usr/bin/perl
#SEARCH SCRIPT

use Testdb::Main;
use warnings;
use strict;

my $schema = Testdb::Main->connect('dbi:mysql:dbic','jag','passwd');
my $names = $schema->resultset('Family')->search({name => 'sushama'});
my $name = $names->first;
print "$name->name\n";
	
This printed 'Testdb::Main::Family=HASH(0x84275e8)->name' instead of
the expected 'sushama'.

I am unable to spot where my mistake is? Can anyone help please?

jagdish eashwar



More information about the DBIx-Class mailing list