Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Class::DBI specifying field is NULL

by inblosam (Monk)
on Jul 15, 2004 at 11:45 UTC ( [id://374616]=perlquestion: print w/replies, xml ) Need Help??

inblosam has asked for the wisdom of the Perl Monks concerning the following question:

What I am trying to do seems it should be quite simple. I am using Class::DBI and am trying to do a search to find entries that have a particular field as NULL.
my @listings = Table::Listings->search(somefield=>'NULL');
This doesn't work, and neither does everything else I have tried to think of. I tried retrieve_from_sql but for some reason that is giving me problems, and I figure there is a way to get this to work...if I just knew how!! I looked around here, google, Class::DBI pod...but nothing. -Michael

Replies are listed 'Best First'.
Re: Class::DBI specifying field is NULL
by trantor (Chaplain) on Jul 15, 2004 at 13:34 UTC
    This should do the trick:

    my @listings = Table::Listings->search(somefield => undef);

      BINGO! Thanks!

      -Michael
Re: Class::DBI specifying field is NULL
by Fletch (Bishop) on Jul 15, 2004 at 13:26 UTC

    Since it sits on top of Ima::DBI you could always define a custom search routine.

    MyClass->set_sql( null_somefield => <<'EOT' ); SELECT __ESSENTIAL__ FROM __TABLE__ WHERE somefield IS NULL EOT my $iter = MyClass->search_null_somefield( );

    Update: Ooh, looks like passing undef as is suguested below works fine (it gets translated into field IS NULL correctly). Strange they don't explicitly mention that in the docs or on the Class::DBI wiki.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://374616]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (3)
As of 2025-06-22 11:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.