[Dbix-class] undef vs. {}

Matt S Trout dbix-class at trout.me.uk
Thu Nov 16 17:40:10 GMT 2006


On 13 Nov 2006, at 19:40, Christopher H. Laco wrote:

> Christopher H. Laco wrote:
>> I have a resultset question. Is this by design, or by accident?
>>
>>
>> This fails
>>
>>   $schema->resultset('Carts')->search(undef, undef);
>>
>> with:
>>
>>> Use of uninitialized value in anonymous hash ({}) at C:/ 
>>> strawberry-perl/perl/site/lib/DBIx/Class/ResultSet.pm line 190.
>>> DBIx::Class::ResultSet::search(): DBD::SQLite::db prepare_cached  
>>> failed: near "IS": syntax error(1) at dbdimp.c line 269
>>>  at C:/strawberry-perl/perl/site/lib/DBIx/Class/Storage/DBI.pm  
>>> line 978.
>>
>> This succeeds:
>>
>>   $schema->resultset('Carts')->search(undef, {});
>>
>> They're both equally futile when written manually. But in things like
>> Handel, where I'm simply passing @_ down the line to DBIC search
>>
>>   sub search {
>>     my $self = shift;
>>     magic...
>>
>>     $schema->resultset('Carts')->search(@_);
>>   }
>>
>>   $handel->search($filter, $options);
>>
>>
>> It's pita to check  @_ for undefs, and strip them out, rather than
>> having DBIC just ignore them...
>>
>> Of course, I could be off my rocker...
>>
>> -=Chris
>
> And of course, more perplexing is that this fails:
>
>   $schema->resultset('Carts')->search(undef, []);
>
> with the same error message.

That's because it's interpreted as ->search({ undef => [] });

-- 
Matt S Trout, Technical Director, Shadowcat Systems Ltd.
Offering custom development, consultancy and support contracts for  
Catalyst,
DBIx::Class and BAST. Contact mst (at) shadowcatsystems.co.uk for  
details.
+ Help us build a better perl ORM: http://dbix- 
class.shadowcatsystems.co.uk/ +


-- 
Matt S Trout, Technical Director, Shadowcat Systems Ltd.
Offering custom development, consultancy and support contracts for  
Catalyst,
DBIx::Class and BAST. Contact mst (at) shadowcatsystems.co.uk for  
details.
+ Help us build a better perl ORM: http://dbix- 
class.shadowcatsystems.co.uk/ +





More information about the Dbix-class mailing list