[CDBI] Re: Search by "or".

Edward J. Sabol sabol at alderaan.gsfc.nasa.gov
Tue Nov 28 15:13:08 GMT 2006


> For a given column Is it possible to search for more than one value?
> for instance how would I search for an employee with the first name
> of either "William" or "Bill"?
>
> # Search for "William".
> @employees = Comp::Employee->search( first_name => 'William' );
>
> is "retrieve_from_sql" the only way to do this?

Well, you could combine the results fo two searches:

@employees = Comp::Employee->search( first_name => 'William' );
push @employees, Comp::Employee->search( first_name => 'Bill' );

In my experience, that could actually be faster with some databases!

Or you could use CDBI::AbstractSearch:

http://search.cpan.org/~miyagawa/Class-DBI-AbstractSearch/lib/Class/DBI/AbstractSearch.pm

Hope this helps,
Ed



More information about the ClassDBI mailing list