Hey guys,
So we have this search that only seems to work with searches of 3 characters or less. I am really at quite a loss as to what the deal is. Here is the code we are running that fails:
$user->subscription('FRIOUX')->limitations;
Here are the result classes (User and Subscription) that the above is based on:
package CIS::Schema::Result::User;
use base qw/DBIx::Class/;
use strict;
use warnings;
use List::Util 'first';
__PACKAGE__->load_components(qw/PK::Auto Core/);
__PACKAGE__->table('User_Profile');
__PACKAGE__->add_columns(qw/ user_id password address1 address2 city state zip
email phone fax date_joined first_name last_name country company_name
agreement commission_from message comment ext disable_logging
disable_accountedit edituser editdate trial chemfinet_userid
chemfinet_agreement enablesearchhelper /);
__PACKAGE__->set_primary_key('user_id');
__PACKAGE__->has_many('subscriptions' => 'CIS::Schema::Result::Subscription',
{'foreign.user_id' => 'self.user_id'});
__PACKAGE__->has_many('notes' => 'CIS::Schema::Result::Note', 'user_id');
__PACKAGE__->has_many(searches => 'CIS::Schema::Result::ActiveSearch',
{'foreign.user_id' => 'self.user_id'});
sub subscription {
my ($self, $prod) = @_;
# fails for $prod = qw{DWCP STRUCT WBDU WCMD SOURCE FRIOUX}
# works for $prod = qw{DMF PF WAY WES}
return $self->subscriptions->search({ 'me.product_name' => $prod })->first;
# always works
# return first { $_->product_name eq $prod } $self->subscriptions->all;
}
package CIS::Schema::Result::Subscription;
use base qw/DBIx::Class/;
use strict;
use warnings;
__PACKAGE__->load_components(qw/PK::Auto Core/);
__PACKAGE__->table('User_Products');
__PACKAGE__->add_columns(qw/ user_id product_name user_type exp_date inst_left
disable_renewal mfg_id admin edituser editdate /,
limitations => {accessor => '_limitations'});
__PACKAGE__->set_primary_key(qw/ user_id product_name /);
__PACKAGE__->belongs_to('users' => 'CIS::Schema::Result::User', 'user_id');
__PACKAGE__->might_have('manufacturer' => 'CIS::Schema::Result::Manufacturer',
{'foreign.mfg_id' => 'self.mfg_id'} );
It turns out that DBI actually returns no results in the query. Here's the trace (long):
DBI 1.607-ithread default trace level set to 0x0/1 (pid 6124) at Company.pm line 130 via Company.pm line 234
SELECT
me.user_id, me.product_name, me.user_type, me.exp_date, me.inst_left,
me.disable_renewal, me.mfg_id, me.admin, me.edituser, me.editdate,
me.limitations FROM User_Products me WHERE ( ( me.product_name = ? AND
me.user_id = ? ) ): 'FRIOUX', 'wesm'
<- prepare_cached('SELECT me.user_id, me.product_name,
me.user_type, me.exp_date, me.inst_left, me.disable_renewal, me.mfg_id,
me.admin, me.edituser, me.editdate, me.limitations FROM User_Products
me WHERE ( ( me.product_name = ? AND me.user_id = ? ) )',
HASH(0x34f1b94), ...)= DBI::st=HASH(0x32bd12c) at DBI.pm line 1777
<- bind_param(1, 'FRIOUX', ...)= 1 at DBI.pm line 1123
<- bind_param(2, 'wesm', ...)= 1 at DBI.pm line 1123
<- execute= '0E0' at DBI.pm line 1129
<- fetchrow_array= ( ) [0 items] at Cursor.pm line 89
<- FETCH('Active')= 1 at ADO.pm line 986
<- disconnect= 1 at ADO.pm line 986
<- DESTROY(DBI::db=HASH(32896ec))= undef at Dispatch.pm line 701
<- DESTROY(DBI::st=HASH(328991c))= undef at Dispatch.pm line 701
<- DESTROY(DBI::st=HASH(34fb85c))= undef at Dispatch.pm line 701
<- DESTROY(DBI::st=HASH(34f31f4))= undef at Dispatch.pm line 701
<- DESTROY(DBI::st=HASH(34fec1c))= undef at Dispatch.pm line 701
<- DESTROY(DBI::st=HASH(34f1d14))= undef at Dispatch.pm line 701
<- DESTROY(DBI::st=HASH(34fea5c))= undef at Dispatch.pm line 701
<- DESTROY(DBI::st=HASH(2705f84))= undef at Dispatch.pm line 701
<- FETCH('Active')= 1 at ADO.pm line 986
<- disconnect= 1 at ADO.pm line 986
<- DESTROY(DBI::db=HASH(32bc0fc))= undef at Dispatch.pm line 701
[Dispatch] ERROR for request '/cis/company/list/?dir=ASC&sort=line1&term=fadgahgh&type=Match%20All%20Words':
Error executing run mode 'list': Can't call method "limitations" on an
undefined value at C:/Inetpub/gic/CIS/Controller/Company.pm line 132.
at C:/Perl/site/lib/CGI/Application/Dispatch.pm line 704
Note the highlighted (if you can) section above. You can also just search for FRIOUX in the output to find it. Zero rows returned.
The crazy thing is that it works fine with vanilla DBI:
my $sth = $self->schema->storage->dbh->prepare(q{SELECT * FROM user_products WHERE user_id = ? AND product_name = ?});
$sth->execute('wesm', 'DWCP');
while (my $row = $sth->fetchrow_hashref) {
warn "TEST ROW YEAHHHH";
warn $row->{Product_Name};
}
Also, we can't seem to reproduce this in a test script, only in a mod_perl environment...
Ideas?
--
fREW Schmidt
http://blog.afoolishmanifesto.com
_______________________________________________
List:
http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-classIRC: irc.perl.org#dbix-class
SVN:
http://dev.catalyst.perl.org/repos/bast/DBIx-Class/Searchable Archive:
http://www.grokbase.com/group/dbix-class@...